Hi there,
I’m having trouble visualizing how to code a longstop using the following line of code:
Longstop = average[barindex - tradeindex](close)
In this example, the system will stop immediately because the indicator has received a parameter that isn’t a number (that’s what PRT says even though I’m not sure to understand this.)
Be that as it may, to thwart this, I simply modified the previous line of code like this:
Longstop = average[barindex + 1 - tradeindex](close)
Now the question that I’m asking myself is whether I need to update the close into Close[1] so as to include the close at the moment I’m in the market in my longstop?
Because BarIndex has been artificially advanced, does that mean that I have to go back further in time in order for the longstop to take into consideration the close at the moment I’m in the market?
I would assume so but I’d like a second opinion! Thanks for getting back to me, would be much appreciated!
In your first example at extremes barindex – tradeindex can be 0 (which returns an error) or a huge number (such as 1450 or 21716,…).
In your second example, say barindex= 280 and tradeindex=275, the difference is 6, that is CLOSE[0] (which is barindex 280) through CLOSE[5] (which is barindex 275), so you do NOT need to use [1] next to CLOSE.
I forgot to mention that the longstop also needs to kick in at the very next bar I’m in the market – like a normal stop behavior sort to speak! Does that change anything?
No, it doesn’t, since BARINDEX will increase and the result of the expression will, as well. Nothing changes!
Okay, thanks a lot! I guess i got confused because of the addition of that +1 constant 🙂