Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error Oco id

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Error Oco id

    Hi i'm having some trouble with oco order, in the attachment there is the problem .
    this is the script that i suppose create the problem: ( i'd like to point out that it gives me an error only on the nd 03-22, iif i use the fdax or other es 03-22 it doesn't give me an error)


    if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Ticks) > m_tikTrailing && firstTrail)
    {
    if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Ticks) > m_tikTrailing && firstTrail)
    {
    SetStopLoss(CalculationMode.Ticks, 0);
    firstTrail = false;

    }

    }

    I'm just checking when the position is in profit of more than 6 tik ( m_tikTrailing) ( first trial it's for the trialing stop loss that i'm not currently using so it doesn't matter)
    And then it comes this error
    Last edited by AlessioCianini12; 01-11-2022, 07:17 AM.

    #2
    Hello AlessioCianini12,

    Thanks for your post.

    The error message about OCO id error is consequential to the incorrect actions performed by the strategy. The bottom message is the real error here. It is saying that the strategy submitted an order that was rejected. The order was rejected because it was a buy-stop market order that was placed above the current price. The order was to be placed at 16386.5.

    I would suggest adding print statements to your code and print out the values being determined/used in your conditional statement along with the current price to see where the error is occurring. 6 ticks may or may not be an appropriate distance, as it depends on the volatility in the market.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Yeah ok but it normally works, so i'm wondering is it possible to put a setstoploss that when touched just send a market order?

      Comment


        #4
        Hello AlessioCianini12,

        Thanks for your reply.

        The SetStopLoss uses a buystopmarket type order that when price touches will change to a market order to be immediately filled. However, if you submit it above the current market price it is rejected. The stop loss must be below the current price when submitted.

        You can replace the SetStopLoss() if you wish by using a ExitLong() (or ExitShort() when going short) as these are market orders regardless of the price. Note: Do not use both SetStopLoss and the exit methods at the same time as it is possible you will have duplicate orders resulting in an unexpected position. You would need your logic to monitor price and when price hits your stop level you would submit the appropriate Exit order which again would be a market order.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Graci117, Yesterday, 11:40 PM
        0 responses
        5 views
        0 likes
        Last Post Graci117  
        Started by BIOK.NT, Yesterday, 01:56 PM
        2 responses
        11 views
        0 likes
        Last Post BIOK.NT
        by BIOK.NT
         
        Started by i2ogu3, Yesterday, 11:31 PM
        0 responses
        4 views
        0 likes
        Last Post i2ogu3
        by i2ogu3
         
        Started by RDTrader16, Yesterday, 10:19 PM
        0 responses
        10 views
        0 likes
        Last Post RDTrader16  
        Started by gemify, 03-08-2023, 08:02 AM
        9 responses
        150 views
        0 likes
        Last Post culpepper  
        Working...
        X