stoploss on a moving average

Forums ProRealTime English forum ProOrder support stoploss on a moving average

Viewing 9 posts - 1 through 9 (of 9 total)
  • #209529

    Hello, I know that this rejection exists, but unfortunately I can’t find it anymore. I’m looking for the code how to put a stoploss directly on a moving average. For example, I enter the trade long and set the stop loss below an SMA. How exactly do you code this?

    #209533

    There you go:

    1 user thanked author for this post.
    #213784

    In order to achieve the minimum distance of the SL I use the following for long only:

    Set Stop Price MA  4*PipSize

    For short only this:

    Set Stop Price MA + 4*PipSize

    But if I want to pack both long and short in one system. How do I write the SL so it doesn’t get mixed up? Do I need to use a for loop somehow?
    I have to say I use it outside of the buy/sell block. As a kind of trailing stop.

     

     

    #213788

    How about …

    You mean all these Trailing Stop Codes and above is all we need – 3 lines of code!? 😉

    I’ll give it a go myself!

    1 user thanked author for this post.
    #213794

    No of course not. But there is a way to tighten the sling without a coded trailing stop. 😉

    #213805

    This way (not tested):

     

    3 users thanked author for this post.
    #213954

    @phoentzs
    I prefer to use two different codes for Long and Short, Don’t forget that the SellShort function can make you get out of a Long position as if you executed a normal Sell in case you mismanage the entry and exit level (or an unexpected conflict in programming), moreover the SellShort will make you get out of your Long position but it will not open a Short position, you will still have to execute the SellShort function to open a Short

    #219007

    I would like to add a maximum SL to this code. That is, if the price is very far from the SMA20 and going against me, I don’t want a huge loss to the SMA, just 0.25%. In this way you lose a maximum of 0.25% per trade. If the position turns into profit, the MA-SL secures the profits. The function can be equated with the following function, which I use in TF M1:

    Set stop %loss 0.25

    if longonmarket and close

    #219341

    This version will set a 0.25% SL when the distance between the SL and the entry price is greater than 50 pips:

     

     

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

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