Move stop loss level to opening level
Forums › ProRealTime English forum › ProOrder support › Move stop loss level to opening level
- This topic has 11 replies, 3 voices, and was last updated 5 years ago by foxfutures.
-
-
08/15/2018 at 11:19 AM #78262
Hi there,
I was wondering if somebody could help me out. I would like to have my stoploss moved to the level of entry as soon as price hits 70% of my target. This has to be implemented in my code. My code so far works really well. The code is shown below. It’s fairly simple: when the conditions are met, 1 contract will be bought. Stop loss lies 5 pips below the candle previous from entry, and target profit lies at the exact same distance.
1234567DISTANCELONG=(abs(close - low) / pipsize) +5IF STRATEGYLONG AND Not OnMarket THENBUY 1 CONTRACT AT MARKETSET STOP PLOSS (abs(close - low) / pipsize) + 5 //DISTANCELONGSET TARGET PPROFIT PositionPrice + DISTANCELONGENDIFNow I just would like to have added that if the price moves in the favourable direction and reaches 70% of the target level (positionprice + (0.7*distancelong??), the stop loss will be moved from the original level to the level of entry (positionprice). Of course maintaing the same target profit level.
Ik hope someone can help me out. Thanks in advance!
Daniel (foxfutures)
08/15/2018 at 11:42 AM #78268To write code, please use the <> “insert PRT code” button, to make code easier to read and understand. Thank you.
08/15/2018 at 11:47 AM #78269There you go (not tested, though, let me know of any issue):
123456789101112131415IF Not OnMarket THENStopLoss = 0ENDIFDISTANCELONG=(abs(close - low) / pipsize) +5IF STRATEGYLONG AND Not OnMarket THENBUY 1 CONTRACT AT MARKETSET STOP PLOSS (abs(close - low) / pipsize) + 5 //DISTANCELONGSET TARGET PPROFIT PositionPrice + DISTANCELONGENDIFIF LongOnMarket AND (close - TradePrice) >= (70 * pipsize) THENStopLoss = TradePriceENDIFIF LongOnMarket AND StopLoss THENSELL AT StopLoss STOPENDIFBeware that line 8 will only be executed next bar, since ProOrder takes a bar to know it’s On Market. Also, PPROFIT doesn’t want a price, but the number of PIPS!
08/15/2018 at 11:49 AM #782701234567DISTANCELONG=(abs(close - low) / pipsize) +5IF STRATEGYLONG AND Not OnMarket THENBUY 1 CONTRACT AT MARKETSET STOP PLOSS (abs(close - low) / pipsize) + 5 //DISTANCELONGSET TARGET PPROFIT PositionPrice + DISTANCELONGENDIFThank you Robertogozzi, I was not aware of that. I hope this works better.
1 user thanked author for this post.
08/15/2018 at 11:58 AM #782711IF LongOnMarket AND (close - TradePrice) >= (70 * pipsize) THENThe above line of your code is not correct Robert. Foxfutures wanted it at 70% of the target distance and not 70 pips.
Also this line is wrong as it sets a price rather than a distance:
1SET TARGET PPROFIT PositionPrice + DISTANCELONGI think this is what you meant to write:
1234567891011121314151617IF Not OnMarket THENStopLoss = 0ENDIFDISTANCELONG=(abs(close - low) / pipsize) +5IF STRATEGYLONG AND Not OnMarket THENBUY 1 CONTRACT AT MARKETSET STOP PLOSS DISTANCELONGSET TARGET PPROFIT DISTANCELONGENDIFIF LongOnMarket AND (close - TradePrice) >= (0.70 * DISTANCELONG) THENStopLoss = TradePriceENDIFIF LongOnMarket AND StopLoss THENSELL AT StopLoss STOPENDIF08/15/2018 at 12:01 PM #78272Beware that line 8 will only be executed next bar, since ProOrder takes a bar to know it’s On Market.
I’m not sure that is correct either. All the three orders will be sent to market, the buy, the target and the stop loss as at that time you are not ONMARKET which is one of the conditions.
08/15/2018 at 12:32 PM #78278Thank you for spotting my error about 70%, I misread it.
As for TRADEPRICE, ProOrder will know it next candle, so I guess it evakuates it to ZERO, thus leaving DISTANCELONG as SL. I see you amended it.
08/15/2018 at 12:50 PM #78279I’m not sure that I fully follow you. At the time when the orders are placed on the market this bit of code will be ignored as you are not long on the market so the value of TRADEPRICE is irrelevant:
123IF LongOnMarket AND (close - TradePrice) >= (0.70 * DISTANCELONG) THENStopLoss = TradePriceENDIFAt the close of the first bar you are now LONGONMARKET so it checks to see if it is above the TRADEPRICE which is now a known value.
08/15/2018 at 12:54 PM #78281Foxfutures – you may want to consider using MTF for this sort of break even idea. I don’t know what time frame you are testing it on but if for example it is an hourly chart then price could go above your 70% threshold several times in that hour but then actually close below it so your move to break even would not be triggered. A faster time frame would allow you to trigger it as soon as the 70% threshold was hit – although at the cost of less data to back test on of course.
08/15/2018 at 12:56 PM #78282Line 6 of the original code was
1SET TARGET PPROFIT PositionPrice + DISTANCELONGProOrder will send it to the broker as
1SET TARGET PPROFIT 0 + DISTANCELONGwhich, in this particular case, may be working because he was adding a price to pips using PPROFIT.
08/15/2018 at 1:00 PM #7828308/15/2018 at 3:28 PM #78288Hi guys,
Thank you both for your solutions and feedback. However, I am not a specialist and have trouble following you both completely, but you’ve helped me a lot.
Thanks!
-
AuthorPosts
Find exclusive trading pro-tools on