Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cancel order

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

    #31
    Hello,

    Yes your are on the correct track here.

    Make sure that you do a check for enough bars in the example below for your straegy to run:

    http://www.ninjatrader.com/support/helpGuides/nt7/currentbars.htm


    Also, make sure that you do your if(BarsInProgress == 0) checks to make sure that you only caclulate this for the OnBarUpdate() for the bars series you want this run on. Since with a multi series strategy OnBarUpdate() runs for all bar series added.



    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #32
      chancehero,

      There is no issue creating 300 variables as long as you spend the time and typed it all out to create them. The reason you got an error is likely because you have not created each and every single one of them as doubles individually which is what is required for you to do in this instance.

      For this purpose, many programmers decide to use arrays to do this. Unfortunately that would be outside the scope of what we can offer support for, but you should be able to find lots of resources on programming and using arrays in C# on google.
      Josh P.NinjaTrader Customer Service

      Comment


        #33
        chancehero, we're looking into matters for this message you see - are you starting it from the chart or strategies tab?

        Thanks,

        Comment


          #34
          problem solved

          neverming.

          brakets were at the wrong places.

          Comment


            #35
            if I start it from a chart it works, while if its from the strategy tab I get the error.

            Comment


              #36
              new problem.

              so got alot of kinks worked out, and am trying to printout when orders are filled I have a setup as:

              PHP Code:
              //variables
              private double lastProfit      = 0.00;
              protected override void OnBarUpdate()
                  {
                      // print profit target
                      if (Performance.RealtimeTrades.Count > 0) 
                      { 
                      // Get the last completed real-time trade (at index 0) 
                      Trade lastTrade = Performance.RealtimeTrades[0]; 
              
                      // Calculate the PnL for the last completed real-time trade 
                      double lastProfit = lastTrade.ProfitPoints; 
              
                      // Pring the PnL to the Output window 
                      Print("The last trade's profit is " + lastProfit); 
                      } 
              
              how will I make the count variable reset after it prints it out once?

              Comment


                #37
                chancehere, are you looking to clear up the output window after a certain condition?

                Comment


                  #38
                  not really, I only wanted to make the output window spit out how much profit I made . (it was on a loop). don't worry about it I imagine i can do it later.

                  now, were do I look if I my strategy is on a 1 min and 60 min bar chart - if I get a signal on a 1 min bar, how do I plot it on the 60 min chart at the same spot?

                  when I get home I will post a picture of what I mean. (if it is not clear).

                  thanks

                  also

                  1) where do I look if I want to add uncertainty into some of my calculations

                  2) if I want to add some probabilities to my strategy

                  I have the stuff written down but I don't know how to put it in code.

                  basically, I want to anticipate my signals before.

                  Comment


                    #39
                    Hello,

                    You simply plot it while your are in BarsInProgress == 1. This will plot at the current price and time that the BarsInProgress==1 ran.

                    Let me know if I can be of further assistance.
                    BrettNinjaTrader Product Management

                    Comment


                      #40
                      ok I will try this tonight.


                      I have another huge problem....


                      when the market closes from 5-5h15 and then from 6h23-7h00 (Atlantic time ) my chart does not plot any bars,

                      I NEED to find a way to generate some fake 1min bars...

                      for example, from 5h-5h15 generate the previous bar 'before close i.e at 4h59' . Is this possible?

                      Comment


                        #41
                        Hello,

                        Not sure why you would need to do this but in realtime this would not be possible as it requires ticks to build bars. If the market is truly closed during this time no bars will be formed.
                        BrettNinjaTrader Product Management

                        Comment


                          #42
                          past this bar creation

                          Alright,

                          so I trashed this bar creation stuff.
                          I have my cancel order working as I like it.


                          any ideals where to start looking?

                          when I have time ill clean up some of my code and post the cancel order I have.
                          Last edited by chancehero; 01-10-2013, 06:25 PM.

                          Comment


                            #43
                            noobs

                            this is simply to help others with CancelOrder()

                            1) to use the CancelOrder(), you need to first:
                            1.1) create a IOrder:
                            PHP Code:
                            private IOrder enter              = null; 
                            
                            in your variables.
                            1.2) this order is to track you position.
                            1.3) when even you want to change something about your order, you can refer to it with the name you gave it , in this case: enter
                            1.4) I use unmanage=true, but I am sure this can be ported to the opposite.
                            1.5) you can create IOrder for your stop_loss and profit_target:
                            PHP Code:
                            private IOrder stop_target     = null;   
                            private IOrder profit_target   = null; 
                            
                            in you strategy, lets say you are in the OnBarUpdate(): you create your strategy:
                            PHP Code:
                            if( bla bla bla){
                            enter       = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, enter_price, 0, "", "EnterLong");
                            } 
                            
                            were
                            PHP Code:
                            enter_price 
                            
                            is determined somewhere else as part of your strategy
                            now , your order is pending, and waiting to be filled.


                            to know what is going on, use the output window, and
                            PHP Code:
                            protected override void OnOrderUpdate(IOrder order) 
                            
                            , this simply gets called, when ever, one of your IOrder has changed. (look in the help file for what they can change to).
                            PHP Code:
                            if (enter != null && enter == order){
                                Print(DateTime.Now.ToLongTimeString()+ order.ToString());
                                if (order.OrderState == OrderState.Filled){
                                    // set stop loss
                                    stop_price  = your_price_1
                                    stop_target = SubmitOrder(0, OrderAction.Sell,                   OrderType.StopLimit,1,stop_price,stop_price,"","Stop target");
                                    // profit target 
                                    profit_price  = your_price_2
                                    profit_target = SubmitOrder(0, OrderAction.Sell, OrderType.Limit,1,profit_price,0,"","profit target");
                                }
                                if (order.OrderState == OrderState.PendingCancel){
                                    Print(DateTime.Now.ToLongTimeString()+ order.ToString());
                                }
                            } 
                            
                            the first line checks if : you have a pending /working order, and that enter is its name.
                            the second line is a printout of that even
                            the third, is a if command that checks if you have filled the enter position.
                            the forth and rest, are the answer to the if command, in this case, you place a profit and stop loss order, at your determined price.


                            now, what about CancelOrder()?

                            lets say you want to cancel your pending order after it has not been filled, for 2 bars,

                            PHP Code:
                             protected override void OnBarUpdate(){
                            if(enter != null && Position.MarketPosition != MarketPosition.Long   ){
                                            exiting+=1;
                                            // Print
                                            Print(DateTime.Now.ToLongTimeString() +" , "+ "order is pending, and counter is increased to : " +" , "+ exiting);
                                        }
                                        
                                        if(enter != null && Position.MarketPosition != MarketPosition.Long && exiting >2){
                                            CancelOrder(enter);
                                            enter = null;
                                            exiting=0;
                                            // Print
                                            Print(DateTime.Now.ToLongTimeString() +" , "+ "pending order is canceled");
                                        }
                            } 
                            
                            now we have checked if our order is in fact pending, but not filled, and we make a counter that increases each time the onbarupdate() is called, I am sure that they are other ways to do this, but a counter is easy.
                            the second if will check if you are still pending , and if you have passed two bars, then it will call the
                            PHP Code:
                            CancelOrder(enter) 
                            
                            and reset the enter Iorder, back to null and the counter as well.
                            the main thing here is to note that the IOrder, needs to be reset
                            PHP Code:
                            enter = null; 
                            
                            when all is done, or else its simply going to stay open, but filled, and the loop that you want to achieve with your strat will stop.

                            this goes as well, if the position was filled, and that you need to cancel the stop loss, or the profit target.

                            enjoy and good luck !
                            feel free to add to this post if I missed anything.

                            ChanceHero

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            671 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            379 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            111 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            575 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            582 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X