Hello,
If I use: pprofit = averagetruerange[14](close)
… can someone tell me how PRT calculates the profit level?
If the profit target is not met on the first bar (after buy cond is met), does it re-calculate the level using the new bar? Does it continue to do this with each new bar?
Many thanks.
PS/ notify of follow ups via email sometimes doesn’t work.
If you are using SET to set the level then any time SET is read in the code then an order is sent to market and if the value is different to the previous level then it will be set at the new level. If your SET instruction is within an IF THEN ENDIF and the conditions are not met then it may not be updated.
Thanks Vonasi,
The backtest works better if I use SET, so I will go with that. Now I’m trying to get my indicator to match the backtest.
If the backtest says: set target pprofit = averagetruerange[14](close)
…could you tell me how to draw this as a dynamic line as an indicator please? Is it possible?
The value you will be using is the value at the close of the last candle so this will tell you what that was as an indicator:
a = averagetruerange[14](close)
return a[1]
I think I’ve got it now, thank you.
buycond =*buy conditions*
if buycond then
closepricewhenbuy = close
endif
atr = closepricewhenbuy + averagetruerange[14](close)
return atr[1]
The problem with that is that is that the indicator is constantly updating on the current forming candle and so you will need to see if your conditions were met on the last candle and then set the closepricewhenbuy to the open value of the current candle and the ATR value to the previous candle to get a true picture of the trade.
buycond = (buy conditions)
if buycond[1] then
closepricewhenbuy = open
endif
atr = closepricewhenbuy + averagetruerange[14](close[1])
return atr
Not tested.
That looks good thanks, but for some reason doesn’t appear to work. Some signals are correctly placed; others not.
buycond = (buy conditions)
if buycond[1] then
closepricewhenbuy = open
endif
atr = closepricewhenbuy + averagetruerange[1](close)
return atr
With this:
averagetruerange[1](close)
you are just getting the currently forming ATR for a period of 1 so just this currently forming bar. That is not information that you can use in a strategy. My last version works exactly as it should be.
In this image the bottom indicator is showing AVERAGETRUERANGE[14](close[1]) which is the value a strategy would get at the close of a bar when it makes its decision. The OPEN of the current bar is the price you would open your trade at. Added together we get your take profit price which is shown in the top indicator which is my code.
OPEN + AVERAGETRUERANGE[14](close) = ?
63863.9 + 1379.14356 = 65243.04536
[attachment file=77011]
Thanks again. I made a typo (1 instead of 14), but I undersatand your explanation.