Library "eStrategy" Library contains methods which can help build custom strategy for continuous investment plans and also compare it with systematic buy and hold.
sip(startYear, initialDeposit, depositFrequency, recurringDeposit, buyPrice) Depicts systematic buy and hold over period of time Parameters: startYear: Year on which SIP is started initialDeposit: Initial one time investment at the start depositFrequency: Frequency of recurring deposit - can be monthly or weekly recurringDeposit: Recurring deposit amount buyPrice: Indicatinve buy price. Use high to be conservative. low, close, open, hl2, hlc3, ohlc4, hlcc4 are other options. Returns: totalInvestment - initial + recurring deposits totalQty - Quantity of units held for given instrument totalEquity - Present equity
customStrategy(startYear, initialDeposit, depositFrequency, recurringDeposit, buyPrice, sellPrice, initialInvestmentPercent, recurringInvestmentPercent, signal, tradePercent) Allows users to define custom strategy and enhance systematic buy and hold by adding take profit and reloads Parameters: startYear: Year on which SIP is started initialDeposit: Initial one time investment at the start depositFrequency: Frequency of recurring deposit - can be monthly or weekly recurringDeposit: Recurring deposit amount buyPrice: Indicatinve buy price. Use high to be conservative. low, close, open, hl2, hlc3, ohlc4, hlcc4 are other options. sellPrice: Indicatinve sell price. Use low to be conservative. high, close, open, hl2, hlc3, ohlc4, hlcc4 are other options. initialInvestmentPercent: percent of amount to invest from the initial depost. Keep rest of them as cash recurringInvestmentPercent: percent of amount to invest from recurring deposit. Keep rest of them as cash signal: can be 1, -1 or 0. 1 means buy/reload. -1 means take profit and 0 means neither. tradePercent: percent of amount to trade when signal is not 0. If taking profit, it will sell the percent from existing position. If reloading, it will buy with percent from cash reserve Returns: totalInvestment - initial + recurring deposits totalQty - Quantity of units held for given instrument totalCash = Amount of cash held totalEquity - Overall equity = totalQty*close + totalCash
Release Notes
⋅
v2
Added: getEquityAthAndDrawdown(equity) Calculates max equity, current drawdown from equity ATH and max drawdown Parameters: equity: Present equity value Returns: equityAth - Equity all time high drawdown - Present drawdown percentage from equity ATH maxDrawdown - Max drawdown percentage
Release Notes
⋅
v3
Added: getAverageCashPercent(cash, equity) Calculates average cash holding percent for strategy Parameters: cash: Present cash holding equity: Present equity value Returns: currentCashPercent - Cash Percent of Equity avgCashPercent - Average cash percent of equity
Currently reverse-engineering the code, can I track the performance of an indicator with this? I am trying to code an Optimizer which backtests several profitable strategies and plots the most profitable strategy on the chart.
Trendoscope
⋅
@hgmahan, You can. You just need to call customStrategy method on all your trade actions. There may be limitations. But, will try to improve over the period of time.
Also, this framework is more suitable for daily timeframes.
UnknownUnicorn11728497
⋅
@HeWhoMustNotBeNamed, Thanks for this, will send the template once it's finished.
Trendoscope
⋅
@hgmahan, Sure. all the best :)
slowcoconut
⋅
@hgmahan, sounds like a super useful implementation... would love to see it -- to be clear, @hgmahan do you mean to build a way for a user to automatically cycle through strategy settings for the optimal/most profitable combination for a particular asset/market at any given time? this is something I discussed in the PineCoders telegram group, we were looking at tools outside of trading view that could provide this functionality but it would be incredible if it could be accomplished in-house...
UnknownUnicorn11728497
⋅
@slowcoconut, Yes, as of now I finished it with longs only, and I am trying to reverse engineer the portfolio backtester engine from @pAulseperformance to include shorts as well. Once both are done I might intend to post it, there are so many more great ideas you find once you get into a flow!