hi guys!
i read in some articles that an stoploss has an duration of 1 candle.
so if i have the following code for automatic trading – the stoploss is only for 1 minute, 10 minutes, (depends on the timeframe)?
//trailing stop function
trailingstart = 20 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
//reset the stoploss value
if not onmarket then
newSL=0
endif
//manage long positions
if longonmarket then
//first move (breakeven)
if newSL=0 and close-tradeprice(1)>=trailingstart*pipsize then
newSL = tradeprice(1)+trailingstep*pipsize
endif
//next moves
if newSL>0 and close-newSL>=trailingstep*pipsize then
newSL = newSL+trailingstep*pipsize
endif
endif
//manage short positions
if shortonmarket then
//first move (breakeven)
if newSL=0 and tradeprice(1)-close>=trailingstart*pipsize then
newSL = tradeprice(1)-trailingstep*pipsize
endif
//next moves
if newSL>0 and newSL-close>=trailingstep*pipsize then
newSL = newSL-trailingstep*pipsize
endif
endif
//stop order to exit the positions
if newSL>0 then
sell at newSL stop
exitshort at newSL stop
endif
@ this point: thx to nicolas for this system
STOP LOSS does not expire if you set it with ProOrder instructions (SET STOP LOSS,…..).
PENDING ORDERS expire each bar (be it 1 second or 1 week) and need to be placed again if needed. Thus if you set your SL with a pending order (like Nicolas did in his code) it must be placed again if you still need it after each bar. Nicolas’code does this with lines 31-34.
Correct. LIMIT and STOP orders last for one bar only. So on a ten minute time frame it is for ten minutes. If you want the order kept on the market then reissue it at each candle close or use a SET instruction to place a stop or limit on the market at a set distance from the position price. A SET instrution only has to be issued once and keeps the order on the market until the position is closed. The SET distance can be changed at any bar close by placing a new SET instruction if you want to change the value.
how to write such SET instruction?
thx! all of u out there are amazing and i love this forum because u all are here!