Need help to code a new stop loss
Forums › ProRealTime English forum › ProOrder support › Need help to code a new stop loss
- This topic has 10 replies, 3 voices, and was last updated 4 years ago by GraHal.
-
-
06/10/2019 at 7:07 PM #100346
Backstory: While making mean reversion its pretty usual to exit when close crosses under/over the mean. Sometimes close crosses over/under and the trade is pretty much perfect, other times price just keeps on running and you miss out on alot of profit.
I would love a kind of trailing stop loss that moves the stop to the price of the Moving average when the crossover happens. As you see in the picture:
1. I enter short trade when price is high, hoping price will revert back to its mean.
2. When in the short trade, and price crosses under the MA, the stop loss will move to that spesific price of the moving average, when that crossover happens. So if the moving average = 12 123, then thats my new stop loss.
06/10/2019 at 7:46 PM #100351It’s just abs(TRADEPRICE – CLOSE) of the candle when the crossing occurs.
Divide it by PIPSIZE if you need pips instead of a price difference.
If you need the price of the average, you decide which one and replace CLOSE with it.
06/10/2019 at 8:08 PM #10035506/10/2019 at 11:40 PM #100374You just need to save the value of your SL and, once set, never change it again. You’ll then place a pending STOP order each candlestick while On Market.
When Not OnMarket clear your SL value resetting it to zero.
06/11/2019 at 7:44 AM #10038206/11/2019 at 9:50 AM #100407Try this:
12345678910IF Not OnMarket THENMyStop = 0ENDIFSma20 = average[20,0[(close)IF close CROSSES UNDER Sma20 AND MyStop = 0 THENMyStop = Sma20ENDIFIF MyStop AND ShortOnMarket THENEXITSHORT AT MyStop STOPENDIF06/11/2019 at 10:18 AM #100411I have not tested it yet Roberto, but this was my intial thought as well. The problem (and please correct me if im wrong) is that i dont want “a MA 20” to be my new stop level. i want “the MA 20” level where price crossed under the MA 20.
I dont think the code u posted does this? it just has “if price crosses over MA20 then sell” basicly?
06/11/2019 at 10:32 AM #10041406/11/2019 at 10:36 AM #100416Line 6 does the job. The level where CLOSE crosses SMA20 is… SMA20!
1 user thanked author for this post.
06/11/2019 at 11:18 AM #100419In case you need the moment when close FIRST crosses under SMA20, then you’ll have to resort to MTF so that you can tell exactly that very moment, but it’s not granted that by the closure of the bar the price won’t retrace so, indeed, no crossing could have occurred at all, despite your strategy may have assumed it!
06/11/2019 at 11:24 AM #100420 -
AuthorPosts
Find exclusive trading pro-tools on