Is it possible to set a 2nd exit?
Forums › ProRealTime English forum › ProOrder support › Is it possible to set a 2nd exit?
- This topic has 6 replies, 2 voices, and was last updated 7 months ago by robertogozzi.
-
-
02/12/2024 at 11:55 AM #227983
Good day All
I am using a code provided by Nicolas to adjust my exit when the price has moved a set number of points. Breakeven code for your automated trading strategy – Learning – ProRealTime (prorealcode.com)
Breakeven Code1234567891011121314//When a trade has moved by a set number of points(60), the stop loss is moved to protect a set number of points(35):IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (60 * PipSize) THENAdjustMySL = 1ENDIFExitMyAdjustedLong = TradePrice[1] + 35IF AdjustMySL THENSELL AT ExitMyAdjustedLong STOPENDIFIF NOT LongOnMarket THENAdjustMySL = 0ENDIFCan I repeat this code with adjusted wording and values to adapt my exit should the price continue higher (long position)?
Additional Move12345678910111213141516171819202122232425262728293031//When a trade has moved by a set number of points(60), the stop loss is moved to protect a set number of points(35):IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (60 * PipSize) THENAdjustMySL = 1ENDIFExitMyAdjustedLong = TradePrice[1] + 35IF AdjustMySL THENSELL AT ExitMyAdjustedLong STOPENDIFIF NOT LongOnMarket THENAdjustMySL = 0ENDIF//Second Move//When a trade has moved by a set number of points(90), the stop loss is moved to protect a set number of points(50):IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (90 * PipSize) THENAdjustMySL2 = 1ENDIFExitMyAdjustedLong2 = TradePrice[1] + 50IF AdjustMySL2 THENSELL AT ExitMyAdjustedLong2 STOPENDIFIF NOT LongOnMarket THENAdjustMySL2 = 0ENDIFI realize a trailing SL can be used, but I would like to know if the above coding is possible and, if so, if it is coded correctly.
Thanks
Brad
02/12/2024 at 12:13 PM #227990It’s almost correct.
Replace line 2 with:
1IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (60 * PipSize) AND AdjustMySL = 0 THENand replace line 19 with:
1IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (90 * PipSize) AND AdjustMySL2 = 0 THENto prevent the first move from being executed again AFTER move two has been triggered.
replace also line 8 with:
1IF AdjustMySL AND AdjustMySL2 = 0 THENfor the same reason.
1 user thanked author for this post.
02/12/2024 at 9:20 PM #22801802/25/2024 at 3:02 PM #228717Hi Roberto
I have applied the corrections you pointed out. Thank you.
I have now applied the same logic to include a third exit. Do you mind checking if I have written this code correctly, please?
I have also applied a trailing stop as an additional exit condition. Is the code correct in saying that if the price reaches 500 points, a trailing stop of 100 points will start? So if the price moves from 1000 to 1500 and then reverses, the price will exit at 1400?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253//First Move 100/50//When a trade has moved by a set number of points(100), the stop loss is moved to protect a set number of points(50):IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (100 * PipSize) AND AdjustMySL1 = 0 THENAdjustMySL1 = 1ENDIFExitMyAdjustedLong = TradePrice[1] + 50IF (AdjustMySL1 = 1) AND (AdjustMySL2 = 0) AND (AdjustMySL3 = 0) THENSELL AT ExitMyAdjustedLong STOPENDIFIF NOT LongOnMarket THENAdjustMySL1 = 0ENDIF//Second Move 200/100//When a trade has moved by a set number of points(200), the stop loss is moved to protect a set number of points(100):IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (200 * PipSize) AND AdjustMySL2 = 0 THENAdjustMySL2 = 1ENDIFExitMyAdjustedLong2 = TradePrice[1] + 100IF (AdjustMySL2 = 1) AND (AdjustMySL1 = 0) AND (AdjustMySL3 = 0) THENSELL AT ExitMyAdjustedLong2 STOPENDIFIF NOT LongOnMarket THENAdjustMySL2 = 0ENDIF//Third Move 300/150//When a trade has moved by a set number of points(300), the stop loss is moved to protect a set number of points(150):IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (300 * PipSize) AND AdjustMySL3 = 0 THENAdjustMySL3 = 1ENDIFExitMyAdjustedLong3 = TradePrice[1] + 150IF (AdjustMySL3 = 1) THENSELL AT ExitMyAdjustedLong3 STOPENDIFIF NOT LongOnMarket THENAdjustMySL3 = 0ENDIF//Trailing Stop. If Price reaches 500 points, a trailing SL of 100 points will trigger.IF LongOnMarket AND (CLOSE - TradePrice[1]) >= (500 * PipSize) THENSET STOP PTRAILING 100ENDIF02/26/2024 at 11:19 AM #228756It’s almost correct.
TradePrice[1], despite it may work in some cases, should be replaced by:
1TradePrice(1) //or simply TradePricethen I changed the first 5 lines and one of the IF….
123456789101112131415161718192021222324252627282930313233343536IF NOT LongOnMarket THENAdjustMySL1 = 0AdjustMySL2 = 0AdjustMySL3 = 0ENDIF//First Move 100/50//When a trade has moved by a set number of points(100), the stop loss is moved to protect a set number of points(50):IF LongOnMarket AND (CLOSE - TradePrice(1)) >= (100 * PipSize) AND AdjustMySL1 = 0 THENAdjustMySL1 = 1ENDIFExitMyAdjustedLong = TradePrice(1) + 50IF (AdjustMySL1 = 1) AND (AdjustMySL2 = 0) AND (AdjustMySL3 = 0) THENSELL AT ExitMyAdjustedLong STOPENDIF//Second Move 200/100//When a trade has moved by a set number of points(200), the stop loss is moved to protect a set number of points(100):IF LongOnMarket AND (CLOSE - TradePrice(1)) >= (200 * PipSize) AND AdjustMySL2 = 0 THENAdjustMySL2 = 1ENDIFExitMyAdjustedLong2 = TradePrice(1) + 100IF (AdjustMySL2 = 1) AND (AdjustMySL3 = 0) THENSELL AT ExitMyAdjustedLong2 STOPENDIF//Third Move 300/150//When a trade has moved by a set number of points(300), the stop loss is moved to protect a set number of points(150):IF LongOnMarket AND (CLOSE - TradePrice(1)) >= (300 * PipSize) AND AdjustMySL3 = 0 THENAdjustMySL3 = 1ENDIFExitMyAdjustedLong3 = TradePrice(1) + 150IF (AdjustMySL3 = 1) THENSELL AT ExitMyAdjustedLong3 STOPENDIF//Trailing Stop. If Price reaches 500 points, a trailing SL of 100 points will trigger.IF LongOnMarket AND (CLOSE - TradePrice(1)) >= (500 * PipSize) THENSET STOP PTRAILING 100ENDIF1 user thanked author for this post.
02/26/2024 at 4:05 PM #228773Thanks, Roberto
I’m assuming the “()” corrections and moving “AdjustMySL1 = 0 and AdjustMySL2 = 0” to the top of the code should be applied to my initial code as well?
Updated ‘additional move’ code:
Updated initial code1234567891011121314151617181920212223242526IF NOT LongOnMarket THENAdjustMySL1 = 0AdjustMySL2 = 0ENDIF//When a trade has moved by a set number of points(60), the stop loss is moved to protect a set number of points(35):IF LongOnMarket AND (CLOSE - TradePrice(1)) >= (60 * PipSize) AND AdjustMySL1 = 0 THENAdjustMySL1 = 1ENDIFExitMyAdjustedLong = TradePrice(1) + 35IF AdjustMySL1 AND (AdjustMySL2 = 0) THENSELL AT ExitMyAdjustedLong STOPENDIF//Second Move //When a trade has moved by a set number of points(90), the stop loss is moved to protect a set number of points(50):IF LongOnMarket AND (CLOSE - TradePrice(1)) >= (90 * PipSize) AND AdjustMySL2 = 0 THENAdjustMySL2 = 1ENDIFExitMyAdjustedLong2 = TradePrice(1) + 50IF AdjustMySL2 THENSELL AT ExitMyAdjustedLong2 STOPENDIF02/27/2024 at 5:48 AM #228795 -
AuthorPosts
Find exclusive trading pro-tools on