STOPLOSS STUCK AFTER BEING SET
Forums › ProRealTime English forum › ProOrder support › STOPLOSS STUCK AFTER BEING SET
- This topic has 11 replies, 5 voices, and was last updated 5 years ago by robertogozzi.
Tagged: Break Even, BreakEven, trailing stop
-
-
05/22/2018 at 12:04 AM #71038
I wrote this code below.
When a certain price level is reached I want to move the stop loss to the entry price. but once it is set trying to set it again does not work.
I saw that the code is reached but has no effect.
any advise would be highly appreciated
setting stop loss more than once does not work12345678910111213141516171819202122232425262728IF ONMARKET THENIF LONGONMARKET THENLongTriggered=1IF(Close - POSITIONPRICE)>= ZeroRiskLevel THENState=13SET STOP LOSS POSITIONPRICE//0ENDIFELSIF SHORTONMARKET THENShortTriggered=1IF(POSITIONPRICE-Close)>= ZeroRiskLevel THENState=14SET STOP LOSS POSITIONPRICE//0ENDIFENDIF//FOR EACH BARELSIF NOT ONMARKET THENIF InitDailyProfit>=StrategyProfit THEN // if no profit was made today continues. else wait for next dayIF LongTriggered=0 THENBUY StakeSize CONTRACTS AT MyBuyprice stopENDIFIF ShortTriggered=0 THENSELLSHORT StakeSize CONTRACTS AT MySellprice stopENDIFSET STOP LOSS StopLossSET TARGET PROFIT StopLimitENDIFENDIF05/22/2018 at 11:53 AM #7109205/22/2018 at 12:28 PM #71094There are 2 solutions for u, search for the “breakeven” stop loss + the MFE trailing stop loss on this forum.
Breakeven stop loss is self explanatory
The MFE trailing waits for price to close over a certain amount of pips and then start trailing with XX trailing stop.
1 user thanked author for this post.
05/22/2018 at 2:06 PM #7109905/22/2018 at 4:13 PM #71117Hi here is an example
It uses % instead of points.
1BreakEvenStop = 1 // BreakEvenStop and BreakEvenStop Minimum Gain12bs = 1.00 // % BreakEvenStopbsm= 0.10 // % BreakEvenStop Minimum Gain123456789101112131415161718192021222324252627if tcShort and tcxShort thenif (s0 or s1 or s2 or s3 or s4 or s5 or s6 or s7 or s8 or s9) thensellshort positionsize contract at marketshorttradecounter=shorttradecounter + 1If BreakEvenStop thenSET STOP %LOSS bsmendifendifendifendif// BreakEvenStopIf BreakEvenStop thenif not onmarket thennewSL=0endifIf longonmarket and close-tradeprice(1)>=((tradeprice/100)*bs)*pipsize thennewSL = tradeprice(1)+((tradeprice/100)*bsm)*pipsizeendifIf shortonmarket and tradeprice(1)-close>=((tradeprice/100)*bs)*pipsize thennewSL = tradeprice(1)-((tradeprice/100)*bsm)*pipsizeendifIf newSL>0 thensell at newSL Stopexitshort at newSL Stopendifendif1 user thanked author for this post.
05/23/2018 at 1:22 AM #71132Even after this change I don’t think my code works as expected. Looking at the charts I don’t see it exit when the “break even” price is reached.
Here is the part of the code that deals with “on market” case. what do you think?
the state is reached (state 13 and 14 in this example)
12345678910111213141516IF ONMARKET THENIF LONGONMARKET THENLongTriggered=1IF(Close - POSITIONPRICE)>= ZeroRiskLevel THENState=13//SET STOP LOSS POSITIONPRICE//0SELL AT POSITIONPRICE STOPENDIFELSIF SHORTONMARKET THENShortTriggered=1IF(POSITIONPRICE-Close)>= ZeroRiskLevel THENState=14//SET STOP LOSS POSITIONPRICE//0EXITSHORT AT POSITIONPRICE STOPENDIFENDIF05/23/2018 at 7:24 AM #71137Did u try the breakeven code from forum?
Copy pastaed the example with the breakeven code in it..
1234567891011121314151617181920212223242526272829defparam cumulateorders = falsestartBreakeven = 30 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)c1 = RSI[14] crosses over 50if c1 thenBUY 1 LOT AT MARKETSET STOP PLOSS 50 //first stoplossendif//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---1 user thanked author for this post.
05/23/2018 at 9:28 AM #71145Thanks
I used a similar code as I wrote above and specifically added this:
SELL AT POSITIONPRICE STOP
following the forum code you mentioned.
it seems to have not made a change in the charts though. If I put a breakeven of 100 pts or 40 pts the gains don’t change even though they should have
So it is either a problem with my code or a problem with the detailed report in ProRealCode (I am guessing it’s my code but I don’t know what the problem is)…
05/23/2018 at 10:19 AM #711561234567891011121314151617181920startBreakeven = 30 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---Can u try to add this exact code at the bottom and check ur detailed report?
As soon as profit > 30 pips (on a closed candle, not the high of the candle), this should close your trade at the least 5 pips in profit (without calculating spread and cost ofc.)
09/17/2019 at 10:29 AM #107834how to make this code for the short market???
1234567891011121314151617181920startBreakeven = 30 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// — BUY SIDE —//test if the price have moved favourably of “startBreakeven” points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// — end of BUY SIDE —09/17/2019 at 10:36 AM #107836For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part!
Thank you!09/17/2019 at 10:41 AM #107838This is the code (you could have found it already coded, with a slightly different approach, at https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/):
12345678910111213141516171819202122232425262728293031startBreakeven = 30 //how much pips/points in gain to activate the breakeven function?PointsToKeep = 5 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// — BUY SIDE —//test if the price have moved favourably of “startBreakeven” points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 AND LongOnMarket THENSELL AT breakevenLevel STOPENDIF//// — SHORT SIDE —//test if the price have moved favourably of “startBreakeven” points alreadyIF SHORTONMARKET AND tradeprice(1)-close>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 AND ShortOnMarket THENEXITSHORT AT breakevenLevel STOPENDIF -
AuthorPosts
Find exclusive trading pro-tools on