Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with IOrder

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

    Problem with IOrder

    What I am trying to accomplish is setup to stop orders one for a long and one for a short, then once one of them is hit I want to cancel the other order. When I add the code for the OnOrderUpdate method I never get a buy in and with some simple debugging I think the code for the OnOrderUpdate is killing the process somehow....any idea's....


    Code:
     
    protected override void OnOrderUpdate(IOrder order)
    {
    if ((lOrder != null && lOrder.Token == order.Token) || (sOrder != null && sOrder.Token == order.Token))
    {
    Print("IN HERE");
    if(lOrder.OrderState == OrderState.Filled || lOrder.OrderState == OrderState.PartFilled)
    {
    Print("Cancel 1");
    CancelOrder(sOrder);
    }else if (sOrder.OrderState == OrderState.Filled || sOrder.OrderState == OrderState.PartFilled)
    {
    Print("Cancel 2");
    CancelOrder(lOrder);
    }
    }
    }
     
    protected override void OnBarUpdate()
    {
    ...do some stuff...
    lOrder = EnterLongStop(0,true,BuySize, (High[0] + (BuyOffset*TickSize)),"Long");
     
    sOrder = EnterShortStop(0,true,BuySize, (Low[0] - (BuyOffset*TickSize)),"Short");
    ...do some stuff...
    }

    #2
    You are likely violating our internal order handling rules. Please see the following link and scroll near bottom.

    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      You are likely violating our internal order handling rules. Please see the following link and scroll near bottom.

      http://www.ninjatrader-support.com/H...verview36.html

      Gotcha, thanks! I didn't realize the log on the control panel posted errors, I was wondering where to find any errors occurred! So after reading the rules it looks like I need to code market orders to accomplish what I am trying to do? The only problem with this is I won't be able to backtest correctly as in doing this I think I will have to use the methods GetCurrentAsk() and GetCurrentBid() which state they use the current (or last) bars close price. Any idea's on how to submit two orders in opposite directions as an OCO that will work for back testing? Thanks for the help!

      Comment


        #4
        Only as separate strategies unfortunately.
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          Only as separate strategies unfortunately.
          Ok, thanks!

          Comment


            #6
            Actually with that being the case can you use any type of global or public variable for a flag for two or more strategies to share / check?

            Comment


              #7
              For instance can I make a variable Public in the #region Variables section and access it from another strategy via Strategy1.Variable etc. similar to Java of course probably with public getters/setters instead.

              Comment


                #8
                You certainly could code/use global variables, since this is a concept supported by C#. However, this is beyond the scope what we provide support for, since you easily could run into problems by e.g. not freeing resources etc.

                Comment


                  #9
                  fxRichard, I'm interested, did you ever get this working?

                  Gotcha, thanks! I didn't realize the log on the control panel posted errors, I was wondering where to find any errors occurred! So after reading the rules it looks like I need to code market orders to accomplish what I am trying to do? The only problem with this is I won't be able to backtest correctly as in doing this I think I will have to use the methods GetCurrentAsk() and GetCurrentBid() which state they use the current (or last) bars close price. Any idea's on how to submit two orders in opposite directions as an OCO that will work for back testing? Thanks for the help!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,265 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X