Stop orders rejected because too close to current price

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #152932 quote
    mr blue
    Participant
    Senior

    Yes, in backtesting everything works fine and looks great. But when it comes to live trading some parameters change.

    So my strategy enters a trade using STOP orders. And I am struggling at the moment with the situation, that somethings the algo calculates the levels of the STOPs to close to the current price, so that IG rejects the STOP orders and the strategy stops.

    Any idea how to prevent this? How can I identify what the minimal distance of points to the current price must be on financial instrument level?

    Thanks

    #152934 quote
    robertogozzi
    Moderator
    Master

    There’s no way to know what that distance is at runtime and it changes when there’s high volatility or news.

    You should check what it is with IG, then use this code to make sure your SL is not below:

    Once Distance = 10
     .
     .
    MyStopLoss = max(MyStopLoss, Distance)

    this will not guarantee your strategy will never be stopped again when exceptions occur, but most of the times it will.

    mr blue thanked this post
    #152939 quote
    mr blue
    Participant
    Senior

    Thats a helpful snipped of code – Grazie

    #152955 quote
    BC
    Participant
    Master

    Thanks Robertogozzi

    Some of my algo which use pending stop order also affect by IG conditions (too close to market price).

     

    Any command can read the current price so that I use your syntax?

    #152970 quote
    robertogozzi
    Moderator
    Master

    You need to apply that code whenever you place an order, be it a SET STOP LOSS or a PENDING LIMIT/STOP order (not AT MARKET).

    Before you place the order make a difference between the current price (CLOSE) and your desired entry price, then check that it’s not less than the required distance:

    ONCE Distance = 10 * pipsize
     .
     .
    IF MyLongConditions AND close > close[1] THEN  //your long conditions on a raising market
       EntryPrice = min(Close - Distance,low[1])   //enter al the lowest price between LOW[1] and CLOSE-Distance to make sure your order is not rejected
       BUY 1 CONTRACT AT EntryPrice LIMIT
    ENDIF

    in this case say you want to enter LIMIT at LOW[1] on a raising market, so you want to make sure that the entry price is at least within DISTANCE pips from the current price (CLOSE) at the very moment you place the order.

    Obviously you will have to check with IG what is the correct value for DISTANCE (if any).

    #152975 quote
    BC
    Participant
    Master

    Thanks for your suggestion, Robertogozzi.

     

    But actual syntax is as below:-

     

    ONCE Distance = 10 * pipsize
    
    InitialTargetPrice = DClose(1) + AverageTrueRange[20](Close)
    
    If  LongCondition then
    
    FinalTargetPrice = Max(InitialTargetPrice, CurrentPrice + Distance)
    
    Buy 1 Contract at FinalTargetPrice Stop
    
    EndIf

    So I wondering what command can replace the CurrentPrice?

    #152980 quote
    robertogozzi
    Moderator
    Master

    CLOSE is the current price.

    In strategies it’s the last price of the most recently closed candle since currently forming candles cannot be accessed, while in indicators and screeners it’s the last price of the candle being formed.

    #153041 quote
    BC
    Participant
    Master

    Yes, I should use Close to detect current price.

    Million thanks Robertogozzi.🙏🙏

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Stop orders rejected because too close to current price


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
mr blue @marco_sala Participant
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by BC
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/08/2020
Status: Active
Attachments: No files
Logo Logo
Loading...