Stop moved to entry when in profit
Forums › ProRealTime English forum › ProOrder support › Stop moved to entry when in profit
- This topic has 25 replies, 4 voices, and was last updated 6 years ago by Vonasi.
-
-
07/11/2018 at 12:38 PM #75795
Needing help to code so that the stop moves to entry (0) when the trade is in profit by a number of points?
12345678910111213141516171819202122232425262728293031// indicators and parametersdefparam cumulateorders = falsedefparam flatbefore = 083000defparam flatafter =170000possize = 10IF TIME = 090000 THEN //include the 0910 candleTop = highest[6](high) // go back 8 candlesBottom = lowest[6](low) // go back 8 candlesLongsForDay = 0MaxPos = 1ENDIFIF TradeIndex = BarIndex THENLongsForDay = LongsForDay +1ENDIFIF TIME >=090000 AND LongsForDay < MaxPos THENBUY possize CONTRACTS AT Top +11 STOPSELLSHORT possize CONTRACTS AT Bottom -11 stopENDIFset target profit 50set stop loss 170IF CLOSE-TradePrice>25 THENset stop loss 0ENDIF07/11/2018 at 1:35 PM #75797I suggest to replace
1IF CLOSE-TradePrice>25 THENwith
1IF CLOSE-TradePrice>25*pipsize THENto make sure it works with alla instruments.
Your code seems fine, the only correction to make is line 30, since I don’t think setting a SL to 0 works, you’d better replace thet line with
1SELLSHORT possize CONTRACTS AT Tradeprice stop07/11/2018 at 2:15 PM #75800You have long and short in the code so your stoploss change will not work anyway for both. Also Roberts suggestion of changing just the one line won’t work as if the price drops under the 25 pip gap the order will no longer be sent to market. You need something like this I think:
123456789101112if not onmarket thenbreakevenflag = 0endifIF onmarket and ABS(CLOSE-TradePrice) > 25 THENbreakevenflag = 1endifif breakevenflag = 1 thensell at positionprice stopexitshort at positionprice stopENDIF1 user thanked author for this post.
07/11/2018 at 2:37 PM #75807Thanks, Ive made the changes however I get a syntax error, please help?
123456789101112131415161718192021222324252627282930313233343536373839// indicators and parametersdefparam cumulateorders = falsedefparam flatbefore = 083000defparam flatafter =170000possize = 10IF TIME = 090000 THEN //include the 0910 candleTop = highest[6](high) // go back 8 candlesBottom = lowest[6](low) // go back 8 candlesLongsForDay = 0MaxPos = 1ENDIFIF TradeIndex = BarIndex THENLongsForDay = LongsForDay +1ENDIFIF TIME >=090000 AND LongsForDay < MaxPos THENBUY possize CONTRACTS AT Top +11 STOPSELLSHORT possize CONTRACTS AT Bottom -11 stopENDIFset target profit 50set stop loss 170IF not onmarket thenbreakevenflag = 0ENDIFIF onmarket and ABS(CLOSE-TradePrice) > 25 THENbreakevenflag = 1ENDIFIF breakevenflag = 1 THENsellshort possize contracts at positionPrice stopsell possize contracts at positionprice stopendif07/11/2018 at 2:39 PM #75808Sorry I see it didnt copy it all
12345678910111213141516171819202122232425262728293031323334353637383940414243// indicators and parametersdefparam cumulateorders = falsedefparam flatbefore = 083000defparam flatafter =170000possize = 10IF TIME = 090000 THEN //include the 0910 candleTop = highest[6](high) // go back 8 candlesBottom = lowest[6](low) // go back 8 candlesLongsForDay = 0MaxPos = 1ENDIFIF TradeIndex = BarIndex THENLongsForDay = LongsForDay +1ENDIFIF TIME >=090000 AND LongsForDay < MaxPos THENBUY possize CONTRACTS AT Top +11 STOPSELLSHORT possize CONTRACTS AT Bottom -11 stopENDIFset target profit 50set stop loss 170IF not onmarket thenbreakevenflag = 0ENDIFIF onmarket and ABS(CLOSE-TradePrice) > 25 THENbreakevenflag = 1ENDIFIF breakevenflag = 1 THENsellshort possize contracts at positionprice stopsell possize contracts at positionprice stopendif//IF CLOSE-TradePrice>25 THEN//set stop loss 0ENDIF07/11/2018 at 2:43 PM #75809OK so clearly you can see I’m not a coder!
07/11/2018 at 3:22 PM #75810Please use the ‘Insert PRT Code’ button when posting code. I have tidied up your posts as best as I can but there was a lot of lines that were not PRT code so I had to guess a little.
I think your syntax error is because you have an ENDIF at the end of the code that you do not need.
07/11/2018 at 3:34 PM #75811Thank you so much, lets see how it behaves live tomorrow!
07/12/2018 at 8:10 AM #75841Ok, so it doesn’t work live
07/12/2018 at 8:20 AM #75842Line 32 does set BREAKEVENFLAG whenever you reach 25 pips, no matter whether you are in profit or loss, since it doesn’t tell between LONG and SHORT trades, I suggest replacing lines 32-34 with
12345IF longonmarket and (CLOSE-TradePrice) > 25 THENbreakevenflag = 1ELSIF shortonmarket and (TradePrice-close) > 25 THENbreakevenflag = 1ENDIFyou could actually combine the two IFs in just one line, but that would make the code much less clear.
07/12/2018 at 8:30 AM #7584307/12/2018 at 9:00 AM #758441234567891011121314151617181920212223242526272829303132333435363738394041// indicators and parametersdefparam cumulateorders = falsedefparam flatbefore = 083000defparam flatafter =170000possize = 2IF TIME = 090000 THEN //include the 0910 candleTop = highest[6](high) // go back 8 candlesBottom = lowest[6](low) // go back 8 candlesLongsForDay = 0MaxPos = 1ENDIFIF TradeIndex = BarIndex THENLongsForDay = LongsForDay +1ENDIFIF TIME >=090000 AND LongsForDay < MaxPos THENBUY possize CONTRACTS AT Top +11 STOPSELLSHORT possize CONTRACTS AT Bottom -11 stopENDIFset target profit 50set stop loss 170IF not onmarket thenbreakevenflag = 0ENDIFIF longonmarket and (CLOSE-TradePrice) > 25 THENbreakevenflag = 1ELSIF shortonmarket and (CLOSE-TradePrice-CLOSE) > 25 THENbreakevenflag = 1ENDIF//IF breakevenflag = 1 THEN//sellshort possize contracts at positionprice stop//sell possize contracts at positionprice stop//ENDIF07/12/2018 at 9:02 AM #75845Is the above correct?
When I try activate it for automatic trading I get:
– Code is invalid. Please correct it.
07/12/2018 at 10:17 AM #75849To write code, please use the <> “insert PRT code” button to make code easier to read and understand. Thank you.
07/12/2018 at 10:20 AM #75853Is the above correct?
When I try activate it for automatic trading I get:
– Code is invalid. Please correct it.
The only warning I get is that the variable BREAKEVENFLAG is not used. Why keeping it if you don’t use it?
-
AuthorPosts
Find exclusive trading pro-tools on