How to code a “real life stop”

Forums ProRealTime English forum ProOrder support How to code a “real life stop”

Viewing 13 posts - 1 through 13 (of 13 total)
  • #30627

    does anyone know how to code a stop loss as you would use it when you trade manually. For example, the system is placing a trade and the stop is set to be 5 points above or below latest high/low depending of long/short position. To simplify we could say that we want the stop below/above N periods max or min price.

    #30678

    Hi!

    Like this?

    Slong = Highest [20](high)

    Sshort = Lowest [20](low)

    If longonmarket then

    Set stop loss Slong

    Endif

    I did not test it since I am mobile. It’s justa Donchian Channel that saves the recent highs and lows.

    #30707

    Yes! thanks! But I think Highest and Lowest needs to change place? If I’m long I want the stop to be att lowest and if I’m short I want the stop to be at highest?

    #30708

    As the stop is tied to highs / lows then the stop level would auto-recalculate at the end of every bar?

    When we get multi-timeframe I hope we will be able to have stops recalc on, for example, a 1 Min bar where the System may be running on a 1H bar?

    GraHal

    #30882

    @Victor: Yep, the high and low in the stop loss should be reversed. Did it actually work or is Grahal’s asdumption correct? In this case you need to put the stop loss command inside your buy/sell if statement.

    If it is already working you need to check what would happen if the market crashes in the very first bar you are in the market. Maybe my snippet above will leave you without a stop because “if longonmarket” is not true when they entry is triggered.

    #30944

    Thanks Derek and Grahal, but the code should be syntaxed like this instead:

    “Set stop loss” do not use price level, but points amount, so we need to calculate the distance between the order open price and the price level where we want the stoploss to be set.

     

    2 users thanked author for this post.
    #147364

    Hallo, Weiß jemand, ob die SL hier mitziehen? Das sollten sie nicht tun. Aber wenn ich damit mein System berechne, ändern sich die Ergebnisse immer im Backtest. Ich berechne lange, kurze Änderungen. Wenn ich kurz berechne, ändern sich die Ergebnisse für lang wieder. obwohl mein System ein umgekehrtes System ist. was ist das? Wie kann ich das ändern?
    Hello,
    does anyone know whether the SL will pull along? They shouldn’t do that. But when I use it to calculate my system, the results always change in the back test. I calculate long, short changes. If I calculate briefly, the results change again for a long time. although my system is an inverse system. What is it? How can I change this?

    #147383

    @phoentzs

    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thank you 🙂

    #147384

    It’s not clear what you want.

    Post your code to help further.

    #147387

    Excuse me please.

    here is my simple code. If I change SL and TP in the long order, the results also change in the short in the backtest. and vice versa.

     

    Why? what do i have to change?

    #147413

    Replace line 38 with:

    and line 46 with:

    otherwise when C1 or C2 are true the block IF…ENDIF will be executed and values changed accordingly, despite no further trades would be opened, having accumulation been disabled at line 4.

     

    1 user thanked author for this post.
    #147434

    Unfortunately, the values ​​are still changing. When I calculate long, the short values ​​change in the backtest and vice versa. Something is wrongly coded somewhere. Can someone help me?

     

    #147438

    The addition of And Not  OnMarket is useless, it doesn’t change anything.

    Slong never changes while LongOnMarket and Sshort never changes while ShortOnMarket.

    There is an error in your code, in lines 40 and 48 you are using TRADEPRICE, but it’s not known yet, it’s the previous entry (or exit) price, since the current price will only be known when the candle closes. It must be replaced with CLOSE.

    Lines 55-61 are actually not needed, since you code, as is, is doing Stop & Reverse. Anyway, if you want to use them, move them to line 34.

    I added several GRAPH instruction at the end, so that you can check those values candle by candle in the variable window of the backtest.

    This is the modified code:

     

     

    1 user thanked author for this post.
Viewing 13 posts - 1 through 13 (of 13 total)

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