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

Cancelled Orders BarsArray

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

    Cancelled Orders BarsArray

    Hi Guys, I was hoping for some help with Bars Array. I am implementing a multi timeframe strategy and the orders are cancelled before they are filled. It is based on EMAs rising or falling over 2 different time frames. The logic is ok as it works as an indicator but when used in a strategy orders are cancelled. I followed the example from "Multi_Time Frame & Instruments" exactly. Here is the relevant code:

    #region Variables

    private int emashort = 5;
    private int emamedium = 10;
    private int emalong = 15;

    private string renko20 = "TF 09-11";
    private int renkoperiod = 15;

    protected override void Initialize()

    AddRenko(renko20, renkoperiod, MarketDataType.Last);

    protected override void OnBarUpdate()

    if (BarsInProgress == 1) return;
    if (CurrentBars[0] <= BarsRequired||CurrentBars[1] <= BarsRequired) return;

    //1. Long entry

    if(Open[0] > Open[1]
    &&Open [0] - Low[0] >4*TickSize
    &&Rising(EMA(emashort))
    &&Rising(EMA(emamedium))
    &&Rising(EMA(emalong))

    &&Rising(EMA(BarsArray[1],emashort))&& Rising(EMA(BarsArray[1],emamedium))&& Rising(EMA(BarsArray[1],emalong))
    &&Position.MarketPosition == MarketPosition.Flat

    I notice in the output screen it says "there is already an existing order with same prices and quantity".

    Is the implementation of the above multitimeframe correct? I've tried many iterations but all have the same effect. Note complete code attached as well.

    Thanks in advance
    DJ


    9/2/2011 9:59:09 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=20 Currency=0 Simulated=False
    9/2/2011 9:59:09 AM Entered internal PlaceOrder() method at 9/2/2011 9:59:09 AM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=692.6 StopPrice=0 SignalName='' FromEntrySignal=''
    9/2/2011 9:59:09 AM Ignored PlaceOrder() method: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=692.6 StopPrice=0 SignalName=Sell short' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
    9/2/2011 9:59:09 AM Cancelled expired order: BarsInProgress=1: Order='cbc5de1c3fce4dab80c789f562a3dd6f/Sim101' Name='Sell short' State=PendingSubmit Instrument='TF 09-11' Action=SellShort Limit price=692.6 Stop price=0 Quantity=1 Strategy='Multitimeframes' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='cbc5de1c3fce4dab80c789f562a3dd6f' Gtd='12/1/2099 12:00:00 AM'
    526
    Attached Files

    #2
    Hello,

    Thanks for your patience.

    I dont see anything off with the I see.

    If you have already tried multiple configurations and tried to debug. What I can offer is to send the code into support at ninjatrader dot com. Try to simplify it as much as possible when you send it in and we will check into it for you and see what is wrong.

    I look forward to assisting you further.

    Comment


      #3
      BarsArray Issue

      Hi Brett, thanks for the offer on that. I did a little more digging in the forums on this issue and found someone else with the same issue. If you look at posts 9, 10 and 11 of the thread below it discusses the issue.



      I have the strategy running on a few instruments and works ok. The problem is on the TF instrument where the cancelled orders are happening. Now I am adding only the TF instrument in barsarray and adding the same TF on other instruments. Now Josh said in Post 11:

      "hat is expected behavior. If you are using the same instruments you need to resubmit on all bar series of that instrument, not just the one you submitted to"

      I think this is the answer to the puzzle but I'm not clear how to do this. I did try:

      if (BarsInProgress == 0|| BarsInProgress == 1) return; instead of just
      if (BarsInProgress == 1) return;

      which I have now but didn't get any orders to fill on TF. So the question is if I'm doing a multitimeframe barsarray using the same instrument what else do I need to do?

      Thanks in advance
      DJ

      Comment


        #4
        DJ,

        If you're running multiple bars of the same symbol/instrument, you should only be using Set() to the first bar within the context of the instrument and ensures the logic will work properly.

        Please review our Help Guide on Entering, Exiting and Retrieving Position Information on Multi time frames:

        MatthewNinjaTrader Product Management

        Comment


          #5
          Thanks Matthew, but I'm not sure what you mean with this Set(). I looked through the link you sent and there is no example of this Set() command that I could see. Can you be more exactly on what this is and where it goes.

          Cheers
          DJ

          Comment


            #6
            djkiwi,

            I was referring to any order methods you are using, or any SetStopLoss or SetProfitTarget methods.

            Taking a step back here, can you please tell me what methods you are using to place your orders? I do not see any reference to them in your code above.
            MatthewNinjaTrader Product Management

            Comment


              #7
              set stop

              Hi Matthew, I attached the strategy in the 1st post. The entry signals are included there. I'd be grateful if could look at that and provide some ideas on what to change.

              Thanks
              DJ

              Comment


                #8
                DJ,

                Thanks- sorry I didn't see the attachment.

                I don't see any reason why this shouldn't work. You are definitely working in the context of the primary series.

                You will need to simply some of this code where you can reproduce the issue and send it in to support[at]ninjatrader[dot]com so we can test this further. Please send using ATTN: Brett in the subject line and a reference to this thread.
                MatthewNinjaTrader Product Management

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by techgetgame, Yesterday, 11:42 PM
                0 responses
                7 views
                0 likes
                Last Post techgetgame  
                Started by sephichapdson, Yesterday, 11:36 PM
                0 responses
                1 view
                0 likes
                Last Post sephichapdson  
                Started by bortz, 11-06-2023, 08:04 AM
                47 responses
                1,613 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Yesterday, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                20 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Working...
                X