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

Problem with Cancelling Orders

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

    Problem with Cancelling Orders

    Hello!
    I'm developing strategy using some dynamic indicators.
    Having trouble to set "flags" for entering.
    F.e. I have 2 SMA's which showing me the trend and a variable Crossover which comes true when 2 SMA's crossing each other. And I want ONLY ONE TRADE from ONE crossover. Then - just waiting for another one.

    Code:
    if (CrossAbove(SMA(14), SMA(50), 1){
    Crossover = true;
    }
    The next thing I want is to enter long limit order on price of another indicator, which gives new value every new bar. I will call that value for example (Indie)
    So I'm printing:

    Code:
    if (SMA(14)[0] < SMA(50)[0]{
    Crossover = false;
    }
    
    if (Crossover==true){
    EnterLongLimit(Indie, "EnterLong");
    Crossover=false;
    }
    In this case I have next issue - i have only cancels of all orders on the next bar from the order was accepted.

    What I'm doing wrong?

    Thanks!


    Update:
    If I'm using just EnterLong() and EnterShort() method this "flag" of variable Crossover works good and I have only one enter from each crossover. But when I'm putting EnterLongLimit - have no entries at all - only cancelling of orders.
    Last edited by YevhenShynkarenko; 10-20-2015, 02:09 PM.

    #2
    Hello YevhenShynkarenko,

    Thank you for your inquiry.

    The reason why this is occurring is because, with the managed approach, if an order is not re-submitted, then the order is cancelled.

    The reason why your EnterLongLimit() order is cancelling is because it is not being called on the next iteration of OnBarUpdate(). You will need to ensure that EnterLongLimit() is called again on the next iteration if you do not wish for this order to be cancelled on the next OnBarUpdate() call.

    Please, take a look at this section in the NinjaTrader help guide for further information about the Managed Approach: http://ninjatrader.com/support/helpG...d_approach.htm

    One way to get around this is to use this particular overload for your EnterLongLimit() call:
    Code:
    EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)
    If you set the liveUntilCancelled parameter to true, then the order will NOT expire at the end of the bar, but instead remain live until the CancelOrder() method is called or its time in force has been reached.

    For more information about EnterLongLimit(), please take a look at the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...rlonglimit.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello YevhenShynkarenko,

      Thank you for your inquiry.

      The reason why this is occurring is because, with the managed approach, if an order is not re-submitted, then the order is cancelled.

      The reason why your EnterLongLimit() order is cancelling is because it is not being called on the next iteration of OnBarUpdate(). You will need to ensure that EnterLongLimit() is called again on the next iteration if you do not wish for this order to be cancelled on the next OnBarUpdate() call.

      Please, take a look at this section in the NinjaTrader help guide for further information about the Managed Approach: http://ninjatrader.com/support/helpG...d_approach.htm

      One way to get around this is to use this particular overload for your EnterLongLimit() call:
      Code:
      EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)
      If you set the liveUntilCancelled parameter to true, then the order will NOT expire at the end of the bar, but instead remain live until the CancelOrder() method is called or its time in force has been reached.

      For more information about EnterLongLimit(), please take a look at the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...rlonglimit.htm

      Please, let us know if we may be of further assistance.
      Big thanks - it worked, but still have troubles with testing.
      I have the next code with conditions:

      Code:
               // Checking for SMA crossover for finding trend up
                         if (CrossAbove(SMA(FastSMA), SMA(SlowSMA), 1))
                          {
                          trendchangesup = true;
                          
                          }
                          //If we have a new crossover - cancel the enter
                          if (SMA(FastSMA)[0] < SMA(SlowSMA)[0])
                          {
                              trendchangesup=false;
                          }
                                          
                      
                      //If trend is up and was no any other crossovers - enter long
                          if (trendchangesup==true)
                          {
                              EnterLongLimit(0, true, DefaultQuantity, lowerBand,"Long Limit Enter");
                              
                              Print("Enter Long" + Time[0].ToString());
                              trendchangesup=false;
      }
      But in fact I see next thing: SMA's are already in downtrend and variable "trendchangesup" must be false and have no enter to Long. But I have it!



      The variable lowerBand is
      double lowerBand = Bollinger(2, 55).Lower[0];

      What I'm doing wrong?
      Thanks!

      Comment


        #4
        Hello YevhenShynkarenko,

        I would suggest debugging your code to see if you are getting the values that you are expecting.

        Here is a helpful link on our support forum that details how you can debug your code: http://ninjatrader.com/support/forum...58&postcount=1

        I would suggest testing to see if your second if statement triggers or not. Print the SMA(FastSMA)[0] and SMA[SlowSMA)[0] values.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ZacharyG View Post
          Hello YevhenShynkarenko,

          I would suggest debugging your code to see if you are getting the values that you are expecting.

          Here is a helpful link on our support forum that details how you can debug your code: http://ninjatrader.com/support/forum...58&postcount=1

          I would suggest testing to see if your second if statement triggers or not. Print the SMA(FastSMA)[0] and SMA[SlowSMA)[0] values.
          Yes, they are printing me right values - just tried that.

          Comment


            #6
            Hello YevhenShynkarenko,

            The output provided does not paint a clear picture of what's going on.

            I would suggest printing the times for those variables as well and compare it to the time that your enter long limit was submitted.

            Was (SMA(FastSMA)[0] < SMA(SlowSMA)[0]) true at the time the limit order was submitted?
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ZacharyG View Post
              Hello YevhenShynkarenko,

              The output provided does not paint a clear picture of what's going on.

              I would suggest printing the times for those variables as well and compare it to the time that your enter long limit was submitted.

              Was (SMA(FastSMA)[0] < SMA(SlowSMA)[0]) true at the time the limit order was submitted?
              I did this.
              Here is the code

              Code:
                                  if (SMA(FastSMA)[0] < SMA(SlowSMA)[0])
                                  {
                                      Print("!!!ORDER CANCEL FROM LONG!!!" + Time[0].ToString());
                                      Print("FastSMA" + SMA(FastSMA)[0]);
                                      Print("SlowSMA" + SMA(SlowSMA)[0]);
                                      trendchangesup=false;
                                  }
              And here is the output and enter

              Comment


                #8
                Hello YevhenShynkarenko,

                In order to investigate further, please attach your script to your post. You can find your script in (My) Documents\NinjaTrader 7\bin\Custom\Strategy.

                If you would prefer your script not be publicly available, please send an email to platformsupport [AT] ninjatrader [DOT] com with a link to this forum thread, my name referenced, and the script attached.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ZacharyG View Post
                  Hello YevhenShynkarenko,

                  In order to investigate further, please attach your script to your post. You can find your script in (My) Documents\NinjaTrader 7\bin\Custom\Strategy.

                  If you would prefer your script not be publicly available, please send an email to platformsupport [AT] ninjatrader [DOT] com with a link to this forum thread, my name referenced, and the script attached.
                  I'm having trouble with exporting so I will send you cs file on e-mail

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by burtoninlondon, Today, 12:38 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by AaronKoRn, Yesterday, 09:49 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post AaronKoRn  
                  Started by carnitron, Yesterday, 08:42 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post carnitron  
                  Started by strategist007, Yesterday, 07:51 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post strategist007  
                  Started by StockTrader88, 03-06-2021, 08:58 AM
                  44 responses
                  3,983 views
                  3 likes
                  Last Post jhudas88  
                  Working...
                  X