Hi,
I am using the below code as a trailing stop on the US500 but keep getting a positive integer error. When I remove line 9 indicator i5, it seems to work but I dont understand why it doesnt when included.
I think i have accounted for negatives and also used round() to account for decimals.
Any help would be appreciated.
Thanks
Carter
i1 = close - 2491//2491 is purchase price, will use postiionprice in backtest
i2 = 250 - (i1 * 3)//250 is an optimized number
if i2 < 1 then
i2 = 2
endif
i4 = round(i2)
i5 = lowest[10](i4)// to delay fall of lowest value
if i1 > 3 then
i6 = i5
else
i6 = 700//optimized value stop when in loss
endif
i7 = lowest[i6](low)
return i7[1]
Carter – Please always use the ‘Insert PRT Code’ button when posting code to make it more readable for others. I have tidied up your post. 🙂
Hi Robert,
Thanks for that but it seems to the same.
Just something else, it does seem to back test ok but when running on live orders the system SOMETIMES stops with the same error.
Thanks
Try this:
if barindex > 10 then
i1 = close - 2491//2491 is purchase price, will use postiionprice in backtest
i2 = 250 - (i1 * 3)//250 is an optimized number
if i2 <= 1 then
i2 = 2
endif
i4 = max(1,i4)//round(i2)
i5 = lowest[10](i4)// to delay fall of lowest value
if i1 > 3 then
i6 = i5
else
i6 = 700//optimized value stop when in loss
endif
i6 = max(1,i6)
i7 = lowest[i6](low)
endif
return i7[1]
Yes it seems to work, i had to change a couple of values though.
I tried it with the barindex and with out and it didnt work with out, what is the thought process behind that. I dont understand.
Thanks for your help
if barindex > 10 then
i1 = close - 2491//2491 is purchase price, will use postiionprice in backtest
i2 = 250 - (i1 * 3)//250 is an optimized number
//if i2 <= 1 then
//i2 = 2
//endif
i4 = max(1,round(i2))//round(i2)
i5 = lowest[10](i4)// to delay fall of lowest value
if i1 > 3 then
i6 = i5
else
i6 = 700//optimized value stop when in loss
endif
i7 = max(1,i6)
i8 = lowest[i7](low)
endif
return i8[1]
It is a common fix. When you first launch the indicator it checks the first bar and then tries to look for lows on the previous 9 bars that don’t exist. The error message I think is a little incorrect as to how it describes the problem. It is always a good idea to make sure there are enough bars on your chart to actually get a meaningful result. However if the indicator is used in a strategy then it means that you have a pause at the start of every back test before trading can start.