Hi. Wondering how to encode “lowest [5] (low)” trailing stop counting from the trade time only and returns and stays with the highest value “lowest [5] (low)” after we have trade. Trailing stop value never goes down after rising, displays only the last maximum value of “lowest [5] (low)” in the trade. Thanks
If I understand correctly, you want your stoploss to move on the last “lowest[5](low)” each time this value is higher than the previous one?
Yes. After the purchase, the walk up just not down. In order to be stopped in decline.
OK, here we go, this is a code snippet that should work (not tested, please do your own test in ProBacktest with GRAPH instruction):
//launch a buy order if the buy condition is met
if buycondition then
buy 1 contract at market
ll = lowest[5](low)
stoploss = close-ll
set stop loss stoploss
endif
//make a pseudo trailing stop at each new highest lowest[5](low)
if not onmarket then
ll=0
endif
if lowest[5](low)>ll and ll>0 then
ll=lowest[5](low)
endif
if longonmarket then
SELL AT ll STOP
endif
Hi, trying to get this code to work but it wont, any advice ?
IF c1 and c2 and c3 and NOT ONMARKET THEN
buy positionsize CONTRACTS at high+2 stop
ll = lowest[5](low)
stoploss = close-ll
set stop loss stoploss
endif
//make a pseudo trailing stop at each new highest lowest[5](low)
if not onmarket then
ll=0
endif
if lowest[5](low)>ll and ll>0 then
ll=lowest[5](low)
endif
if longonmarket then
SELL AT ll STOP
endif
SET TARGET PPROFIT 40
Did you graph “ll” to see if it’s moving?
GRAPH ll as "my lowest low trailing stop level !"
Add this line into your code and launch a backtest please.
Got it working but not as i thought
Wanted the stop to be behind the entry price bar on the lowest low within x bars away, took away the trailing but dint work, code as follow
IF c1 AND c2 and c3 AND NOT ONMARKET THEN
buy positionsize CONTRACTS at high+2 stop
ENDIF
ll = lowest[x](low)
stoploss = close-ll
set stop loss stoploss
if longonmarket then
SELL AT ll STOP
endif
GRAPH ll as "my lowest low trailing stop level !"
SET TARGET PPROFIT 55
You should look at this blog article on how to make a stoploss with an indicator value.
The lowest low of X periods is the lower band of a Donchian Channel of X periods.
@Nicolas referring to the recent post at https://www.prorealcode.com/topic/trailing-stop-loss/ can you possibly assist us in coding a manual Trailing Stop that will work the same as the Set Stop pTrailing function. I have attempted to code it but it is unfortunately not working as I imagined it to work.