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/12/2018 at 10:21 AM #7585407/12/2018 at 12:50 PM #75868
Please understand I have zero coding knowledge. Someone helped me put the algo together. They can’t help me get the stop to entry once in 25 points profit and adviced that I use this forum.
I don’t know what breakevenflag means or how it works.
07/12/2018 at 2:23 PM #75876breakevenflag is just a variable used in this case as a switch . It is either on (=1) or off (=0). If you have reached your 25 pips then it is switched on and so the code knows now that we have achieved that goal. If we later sell then we switch it off so that the code can once again start looking to see when we have a new trade whether it has hit our desired 25 pips.
07/12/2018 at 2:25 PM #75877Thanks for the explanation. How does it set the stop to entry or zero points?
07/12/2018 at 2:36 PM #75878There was a typo in your last code and you had // an important part of the code. I tested this code and it does what you ask for.
123456789101112131415161718192021222324252627282930313233343536373839// 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 or shortonmarket and (TradePrice - close) > 25 THENbreakevenflag = 1ENDIFIF breakevenflag = 1 THENsellshort possize contracts at positionprice stopsell possize contracts at positionprice stopENDIF07/12/2018 at 2:44 PM #75879Some explanation:
12345678910111213141516//If you are not in a trade we make sure the flag is switched offIF not onmarket thenbreakevenflag = 0ENDIF//Then we check to see if any long or short positions have reached 25 pips or more and we switch the flag on if they haveIF longonmarket and (CLOSE-TradePrice) > 25 or shortonmarket and (TradePrice - close) > 25 THENbreakevenflag = 1ENDIF//if the flag is now switched on telling us that we have previously hit 25 pips then we send stop orders to the market at each candle opening to//close any long or short positions at the price the trade was opened atIF breakevenflag = 1 THENsellshort possize contracts at positionprice stopsell possize contracts at positionprice stopENDIF07/12/2018 at 7:46 PM #7588707/12/2018 at 8:30 PM #75889Yes, you’re right, and if the price retraces to a price lower than your treshold before closing, it eon’t Even trigger breakeven even if in profit.
It can be modified so that it compares HIGH instead of CLOSE to your treshold.
07/12/2018 at 11:19 PM #75890Correct me if I am wrong, but the breakeven rule is triggered with every candle closing. So if within a candle we have a spike in the desired direction nothing happens until candle close time is here, please confirm.
Yes but we can only make decisions at the candle close. If it goes 25 pips in profit and then falls back to 5 pips in loss then we have no chance to catch that get out at break even mid candle. Setting a stop loss at break even after a candle has closed just because at sometime during the candle it went above a 25 pip gain would most probably lock in more losses than break evens. We can only do what we can do at candle close and I think the OP was working on short time frames and on markets where 25 pips in a short amount of time is likely.
07/13/2018 at 7:44 AM #75892Thanks for all the help, I went to prepare the algo for automatic trading and got the following:
The following changes must be applied before sending the code to ProOrder:
Trading systems with orders that partially close a position cannot be sent to ProOrder (ex: sell 3 shares at market). Make sure that no quantity is specified in instructions to close positions (in this case the instruction closes the entire position). Ex: sell at market. Exitshort at 1.5 limit
Please help?
07/13/2018 at 8:56 AM #75898Change the last four lines of code to this:
1234IF breakevenflag = 1 THENsellshort at positionprice stopsell at positionprice stopENDIFPartial position closure is not allowed in ProOrder trading yet. Rumours are that it should be soon.
-
AuthorPosts
Find exclusive trading pro-tools on