Breakeven and Points to Keep
Forums › ProRealTime English forum › ProOrder support › Breakeven and Points to Keep
- This topic has 5 replies, 3 voices, and was last updated 6 years ago by
adeelq79.
-
-
10/04/2019 at 10:40 PM #109319
Hi, I have the code below but when the trade was in profit this week, the code did not protect the number of points I stated. Any idea on what maybe wrong with the code below?
I would also like to add a trailing stop ie if the trade is in profit 1 point greater than when the breakeven point starts, i’d like the stop loss (points to keep) to increase by 1 point too; and to continue to do so until target is met. Any thoughts on how to introduce this code would be appreciated.
Thanks
FTSE - Points to Keep123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedOnce LastTradeDate = 0// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 160000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//how much pips/points in gain to activate the breakeven function?startBreakeven = 20//how much pips/points to keep in profit above or below our entry price when the breakeven is activated (beware of spread)PointsToKeep = 15// Conditions to enter long positionsindicator1 = RSI[7](close)c1 = (indicator1 >= 83)ignored, ignored, ignored, ignored, indicator2, ignored, ignored = CALL "WA Explosion COMBO"[150, 30, 15, 15]c2 = (indicator2 >= 260)indicator3 = ExponentialAverage[5](close)indicator4 = ExponentialAverage[17](close)c3 = (indicator3 > indicator4)indicator5 = ExponentialAverage[62](close)indicator6 = ExponentialAverage[5](close)c4 = (indicator5 < indicator6)IF (c1 AND c2 AND c3 AND c4) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AND LastTradeDate<>OpenDate THENBUY 1 CONTRACT AT MARKETLastTradeDate = OpenDateENDIF// Conditions to enter short positionsindicator7 = RSI[7](close)c5 = (indicator7 <= 22)ignored, ignored, ignored, ignored, ignored, indicator8, ignored = CALL "WA Explosion COMBO"[150, 30, 15, 15]c6 = (indicator8 >= 260)indicator9 = ExponentialAverage[5](close)indicator10 = ExponentialAverage[17](close)c7 = (indicator9 < indicator10)indicator11 = ExponentialAverage[62](close)indicator12 = ExponentialAverage[5](close)c8 = (indicator11 > indicator12)IF (c5 AND c6 AND c7 AND c8) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AND LastTradeDate<>OpenDate THENSELLSHORT 1 CONTRACT AT MARKETLastTradeDate = OpenDateENDIF// Stops and targetsSET STOP pLOSS 14SET TARGET pPROFIT 25//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 ---// --- SELL SIDE ---IF SHORTONMARKET AND close-tradeprice(1)-close>startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF// --- end of SELL SIDE ---10/05/2019 at 11:50 AM #109334Is the WA Explosion COMBO the Indicator below please?
https://www.prorealcode.com/prorealtime-indicators/waddah-attar-explosion/
I’m going to run it on my Platform and try to see what is going on.
I’ve never had much success with Trailing Stops, but maybe it’s because they didn’t work and I’ve never bothered to investigate so I though your code would be a good one to collaborate on! 🙂
But please anybody else contribute also as I often get my understanding by experimenting (using GRAPH etc) whereas you coding wizards may spot the issue from just looking at the above code … so please feel free to dive in! 🙂
10/05/2019 at 11:59 AM #109336Thanks for the reply,
Thats not the code I have for the explosion combo, I have the one attached.
I found this trailing stop with incremental steps below, I do not know if it works but when I backtested it on FTSE, 1 trade showed up as b/e. I thought it should have shown up +10 as the trade went up +20 before falling back to b/e.
Thanks
Trailing Stop with Step123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedOnce LastTradeDate = 0// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 160000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions to enter long positionsindicator1 = RSI[7](close)c1 = (indicator1 >= 83)ignored, ignored, ignored, ignored, indicator2, ignored, ignored = CALL "WA Explosion COMBO"[150, 30, 15, 15]c2 = (indicator2 >= 260)indicator3 = ExponentialAverage[5](close)indicator4 = ExponentialAverage[17](close)c3 = (indicator3 > indicator4)indicator5 = ExponentialAverage[62](close)indicator6 = ExponentialAverage[5](close)c4 = (indicator5 < indicator6)IF (c1 AND c2 AND c3 AND c4) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AND LastTradeDate<>OpenDate THENBUY 1 CONTRACT AT MARKETLastTradeDate = OpenDateENDIF// Conditions to enter short positionsindicator7 = RSI[7](close)c5 = (indicator7 <= 22)ignored, ignored, ignored, ignored, ignored, indicator8, ignored = CALL "WA Explosion COMBO"[150, 30, 15, 15]c6 = (indicator8 >= 260)indicator9 = ExponentialAverage[5](close)indicator10 = ExponentialAverage[17](close)c7 = (indicator9 < indicator10)indicator11 = ExponentialAverage[62](close)indicator12 = ExponentialAverage[5](close)c8 = (indicator11 > indicator12)IF (c5 AND c6 AND c7 AND c8) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AND LastTradeDate<>OpenDate THENSELLSHORT 1 CONTRACT AT MARKETLastTradeDate = OpenDateENDIF// Stops and targetsSET STOP pLOSS 14SET TARGET pPROFIT 25//************************************************************************// trailing stop function (fixed after breakeven)//reset the stoploss valueIF NOT ONMARKET THENtrailingstart = 10 //10 trailing will start @trailinstart points profittrailingstep = 5 //5 trailing step to move the "stoploss"initialSL = 14 //14 initial SL when a trade is enterednewSL = 0ENDIF//manage long positionsIF LONGONMARKET THENCurrentProfit = close - tradeprice(1)//first moveIF newSL = 0 AND CurrentProfit >= (trailingstart * pipsize) THENnewSL = tradeprice(1) + (trailingstep * pipsize) - (initialSL * pipsize)InitialSL = initialSL - (trailingstep * pipsize)ENDIF//next movesIF newSL > 0 AND (close - newSL) >= (trailingstep * pipsize) AND initialSL > 0 THENnewSL = newSL + min(trailingstep * pipsize,initialSL * pipsize)initialSL = max(0,initialSL - (trailingstep * pipsize))ENDIFENDIF//manage short positionsIF SHORTONMARKET THENCurrentProfit = tradeprice(1) - close//first moveIF newSL = 0 AND CurrentProfit >= (trailingstart * pipsize) THENnewSL = tradeprice(1) - (trailingstep * pipsize) + (initialSL * pipsize)InitialSL = initialSL - (trailingstep * pipsize)ENDIF//next movesIF newSL > 0 AND (newSL - close) >= (trailingstep * pipsize) AND initialSL > 0 THENnewSL = newSL - min(trailingstep * pipsize,initialSL * pipsize)initialSL = max(0,initialSL - (trailingstep * pipsize))ENDIFENDIF//stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF10/05/2019 at 12:18 PM #109339You are now making it more difficult / confusing as you now have two different codes for Trailing Stop issues … in the same Topic.
You would have been better opening a new Topic for the second Trailing Stop code issue so then it keeps it simple and the reading quicker etc for folks wanting to help .
Thanks for WA Explosion Combo, I will run it later, but I have now run out time now after I had to put both your codes above into the diff checker below to check out the differences! 🙂
10/05/2019 at 12:24 PM #109340Line 82 in the code in your first post makes no sense.
1IF SHORTONMARKET AND close-tradeprice(1)-close>startBreakeven*pipsize THENshould be changed to this:
1IF SHORTONMARKET AND tradeprice(1)-close >= startBreakeven*pipsize THEN1 user thanked author for this post.
10/05/2019 at 12:40 PM #109343 -
AuthorPosts
Find exclusive trading pro-tools on