Need help to code a new stop loss

Forums ProRealTime English forum ProOrder support Need help to code a new stop loss

Viewing 11 posts - 1 through 11 (of 11 total)
  • #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.

     

    #100351

    It’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.

    #100355

    not sure i understand what u mean Roberto, sorry.

    Im not sure how i can keep the stop loss at the same level regardless of how long the trade continues?

    #100374

    You 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.

    #100382

    Im stupid, cant get this to work, sorry.

     

    Im someone wanna help me write the code id be grateful.

    #100407

    Try this:

     

    #100411

    I 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?

    #100414

    My head is buzzing trying to work out if the code is doing what I think it is supposed to! 🙂

    More coffee then look at it again, but attached is what I am looking at.

    The last orange bar was where it exit the Short trade.

    #100416

    Line 6 does the job. The level where CLOSE crosses SMA20 is… SMA20!

    1 user thanked author for this post.
    #100419

    In 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!

    #100420

    Surely the exit was on the next bar / bar not shown (at the stop level exit) and you can see that the exit price was the same price as MyStop shown on the previous bar?

     

Viewing 11 posts - 1 through 11 (of 11 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login