Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaTrader7 ingnoring some sent EnterLong commands - seems like a BUG

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

    NinjaTrader7 ingnoring some sent EnterLong commands - seems like a BUG

    Hello

    I would really need to ask you something, I have one issue with NinjaScript and I am not sure if its caused because of any bug of NT7 or because of any rule of broker. Let me explain...

    I have one strategy what I wrote and this strategy is working with two instruments. EURUSD and GBPUSD.
    It works like this. I run (backtest) this strategy on 60Min GBPUSD.
    The strategy is trading on this GBPUSD instrument.
    But the strategy will also load 60Min EURUSD data.
    Add("$EURUSD", PeriodType.Minute, 60);



    Example:
    Code:
    Initialize() {
      Add("$EURUSD", PeriodType.Minute, 60);
    }
    
    OnBarUpdate() {
      ... 
      some calculations and indicators working with EURUSD and GBPUSD
      ...
      
      if (Closes[1][0]>myIndicatorValue) { // if current EURUSD close
                                                          // is higher than myIndicatorValue
        EnterLong(0, 1, ("myId"+(id++)));  // buy GBPUSD
        SetStopLoss...
        SetProfitTarget...
      }
    
    }
    So now you see that strategy is working with TWO instruments.
    And both of them has the same period (60Minute).
    So when new bar is created on GBPUSD the OnBarUpdate method is called, and after that the OnBarUpdate method is called AGAIN because there is also new bar created on EURUSD in the same moment. (Because they have same timeframe so the bars are created in same time on the instruments).

    I was debuging the code (I was watching via Print(...) what is happening inside the code when is executing) and really [bold]EVERYTIME[/bold] is the EnterLong command called [bold]twice[/bold]. And this is I guess correct. This is what I expected.


    But when you will take a look at the attachment you will see that sometimes is filled just one Enter command. The secondone is not even appear in the table. WHY?? I dont understand...
    I was looking in the code and as I told you the strategy REALLY EVERYTIME call the EnterLong TWICE. But as you can see in attachment - sometimes it has behaviour like the strategy call the EnterLong just one - but WHY? There is profit/loss just for one contract.
    BUT EVERYTIME THERE SHOULD BE PROFIT/LOSS FOR TWO CONTRACTS BECAUSE THE STRATEGY CALL THE ENTERLONG TWICE EVERYTIME.


    Is this bug of NinjaTrader or is this any special behaviour of broker that sometimes from SOME reason dont accept my one of my two ENterLongs?

    Thank you for your response, I really need to know this because I am going to trade this strategy via NinjaTrader as soon as possible but I need to know why is this sometimes happening..?
    Why sometimes there is just one trade EVEN my strategy called the EnterLong method twice..?

    Thank you again.. if you will need I can provide you whole the source code of strategy and indicators.

    But I think it is really weird - my strategy is EVERYTIME call the method EnterLong TWICE! I checked via Print(..any log..) So why is in most of time really trading with twice EnterLongs how it should, and sometimes just with one EnterLong..?-thats incorrect!

    I know that I could use
    Code:
    if (BarsInProgress==1){
      enterLong conditions
    }
    but when I did that I saw, that the strategy is not so profitable.

    I realize that in most of time, when NinjaTrader/or broker is ignoring my EnterLong command it the loosig trade! And thats perfect!
    So now I dont know if its bug of NinjaTrader or any rule behaviour of broker. Because everytime the missing trades are still the same. Everytime I backtest the strategy I see still the same missing trades. So I dont know if its just coincidence.? And most of the time the missing trades are the loosing.? coincidence?

    Thank you



    /// EDIT

    Hello I found out new thing..
    Attachment log.xls is tab TRADES from strategy analyzer. In second attachment log2-orders is tab orders. I am sending it to you because I found out there is some order (for example 9.april.2007 at 20:00) whichone is trade just one (and should be twice as I explained on the top) but there is any CANCELLED order in tab orders..
    But I dont understand why is it cancelled and what it means..?
    I think this could be the reason why some of the sent EnterLong commands are ignored .. ?

    Thank you very much for your help !!
    Attached Files
    Last edited by zooinek; 06-14-2010, 07:37 AM. Reason: I found out another thing

    #2
    Hi zooinek,

    Begin by simplifying your code, perhaps submit this to just one series, ensure orders are being submitted as expected.

    You will need to use either

    if (BarsInProgress==1)
    {
    conditions
    }

    or if (BarsInProgress !=0) return;

    ...for example.

    To ensure you are accessing the correct series.

    The proper way of doing this is illustrated at - http://www.ninjatrader-support.com/H...ameInstruments
    Last edited by NinjaTrader_Tim; 06-14-2010, 11:52 AM.
    TimNinjaTrader Customer Service

    Comment


      #3
      Are you kidding me?
      Did you even read my questions???

      I didnt ask "how to fix code".
      I know the reason WHY is the algorithm doing every EnterLong twice.
      And I wrote that I want to do it in this way. I just dont underrstatnt why is Ninja cancelling ssome orders sometimes...?

      Please read the post very carefuly to understatnd what I am asking for.
      thank you

      Comment


        #4
        Hi zooinek,

        Sorry for the confusion, let me see if we can clarify the issue here...

        1. Keep in mind that SetProfitTarget and SetStopLoss are always OCO, so once one is filled, the other will show as cancelled. To clarify, are these the orders you are referring to?

        2. Are you expecting more entries each time? What are you EntriesPerDirection setting?

        3. Have you used TraceOrders to see why order are being cancelled?
        More info at - http://www.ninjatrader.com/support/f...ead.php?t=3627
        TimNinjaTrader Customer Service

        Comment


          #5
          Detailed explanantion

          Ok so I am back and now I will try to explain my problem more detailed.
          Please download the attachmnts.zip file it contains picturres and excel files from backtest.

          So I have my strategy. The source code looks like this: (it's always running on $GBPUSD)

          Code:
          ...
          
          protected override void Initialize() {
              CalculateOnBarClose = false;
              ExitOnClose = true;
              Add("$EURUSD", PeriodType.Minute, 60);
              EntriesPerDirection = 1;
              TraceOrders = true;
          }
          
          ...
          
          protected override void OnBarUpdate() {		
          		
              ... some calculations and indicators...
              ... the indicators are using also the $GBPUSD and also the $EURUSD data...
          
              if (Closes[1][0]>myValue) {  // if eurusd current close price is higher than myValue
                  i++;
                  myId = id+i;
                  EnterLong(0, 1, myId);  // the myId is important, take a look at
                                                    // the pictures on the continuous
                  SetProfitTarget(myId, CalculationMode.Ticks, pt);
              }    
              if (Closes[1][0]<myValue) {  //  if eurusd current close price is lower than myValue
                  i++;
                  myId = id+i;
                  EnterShort(0, 1, myId);
                  SetProfitTarget(myId, CalculationMode.Ticks, pt);
              }    
          
          }
          So now we know, that strategy is working with two instruments.
          60Minute GBPUSD (strategy is running on this) and also 60Min EURUSD.
          So when new bar is created on GBPUSD it starts OnBarUpdate method with BarsInProgress=0 and when new bar is created on EURUSD it starts OnBarUpdate method with BarsInProgress=1.

          As you can see I am not working with BarsInProgress in my code !!!
          And because both of the instruments has 60Minute timeframe, I expect that my code will be run TWICE on end of every hour.
          One- because theres new bar on GBPUSD
          Two- because theres new bar on EURUSD


          I was checking this (kind of debugging via Print() method and checking the own logs) and really my expectation was true - everytime when new bar was created on one instrument (GBPUSD) right after then new bar was created on second instrument (EURUSD) so the OnBarUpdate method was executed twice with the same indicator values!

          So it means this: Imagine there's new GBPUSD bar, the OnBarUpdate is executing and the condition [bold]if (Closes[1][0]>myValue)[/bold] is true. So the EnterLong command is executed. Great.
          And right after this happend, the OnBarUpdate is executing AGAIN (because the new EURUSD bar created in the same time) and the condition is again true, so the EnterLong is executed again!

          So I expect, that EVERYTIME when GBPUSD starts the OnBarUpdate and the condition [bold]if (Closes[1][0]>myValue)[/bold] is true, RIGHT AFTER THEN the OnBarUpdate is executed AGAIN (because of new EURUSD) and the condition [bold]if (Closes[1][0]>myValue)[/bold] is true again so the EnterLong is executed again.

          So I expect EVERYTIME there has to be TWO SAME ENTRIES in chart.
          Twice EnterLong (once because of GBPUSD and second time because of EURUSD).

          And now please take a look at pictures firstTest_pic1.jpg and firstTest_pic2.jpg
          You can see really there are TWO ENTRIES. But sometimes you can see there is just ONE entry! But WHY??? There should be always TWO? Or not ??
          (note every entry command has unique myId - check in the pictures that there are some "IDs missing in the continuity" so that means, that strategy was really executing that small part of code just Ninja didnt create the entry in chart - this is my question - why?)

          Files
          firstTest_pic1.jpg
          firstTest_pic2.jpg
          firstTest_pic3.jpg
          firstTest_Executions.xls
          firstTest_Orders.xls
          firstTest_Trades.xls
          firstTest_TracedOrders.txt

          are related to this test.


          Thank you for your answers, I am really lost.
          Attached Files

          Comment


            #6
            Hello zooinek,

            You have EntriesPerDirection set to 1.

            Do you have EntryHandling set to AllEntries or UniqueEntries?

            I'm seeing this in your TraceOrders output:

            Ignored PlaceOrder() method at 7.1.2010 13:00:00: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='id=4' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I have AllEntries... what it means??


              I forgot to say..
              I am satisfied how it is working now.
              I know that there is way how to fix the code. I supposed to add "if (BarsInProgress!=1) { return; }" (1 because I am waiting for EURUSD crossing the myValue) but with this "fix" it has much worse results.
              It is not so profitable.

              But in the version without the "if (BarsInProgress!=1) { return; }" there are great profits, because I saw there is lot of profit trades TWICE as it should be, but lots of loosing trades just ONCE

              And that's the reason why I am writing to you. I dont want to "fix" the code. I just want to know why some of the trades are twice as I expected and some of them just once. Because I would like to trade this live with real money and I am not sure if it is possible to do same profits and results as in the backtest I sent you... it is possible? Will it be working like this also in real trading???

              As I told - "to fix the code" means for me do every trade just once. The profit and also the loosing trade do everytime just once.
              But with the "bug" where every trade SHOULD be twice, but some of them are (for some unknown reason wich I would like to know) just once, the strategy is more profitable.
              Because most of the ONCE trades are the loosing trades (I also I dont understat why..???)


              So it is possible to trade my strategy as I wrote you? With the "bug"?

              Comment


                #8
                zooinek, I'm not sure which bug you refer to, here's how it works - with AllEntries what ever signal triggers first will be used (EntriesPerDirection 1) -



                Based on this you will occasionally run into ignored orders as seen in the trace - to make this more transparent -

                a) use unqiue entry handling and provide a distinctive naming for each

                b) use the way as it is but with a higher EntriesPerDirection

                The behavior would be the same going live, so we unfortunately can't comment on the performance you can expect.

                Comment


                  #9
                  Hello Bertrand, thank you for your response.
                  Yes I know how I could make the strategy work to trade everytime just with one trade.
                  But don't want to do so. Because this way how it is (it's trading sometimes two trades and sometimes just one trade because the secondone is ignored) is better for me.
                  I just need to know why is this happening. But I am not going to "solve" it.

                  I am sorry but from your previous text I didnt understand why it is sometimes ingoring my trades..?
                  Could you explain it to me please? I am not native english speaker so please use easy words to make it understandable.

                  I want my strategy as it is, the only think I am trying to get to know in this thread is, why it is ignoring some of my trades, and if this will happen in real live trading also..?

                  Here is another example of ignoring trade signal. I have to know, what is the difference between the two situations in the rings. What happend there? Why Ninja executed just first signal and ignored the secondone in the most left sample?

                  Please please answer this questions
                  Please answer also the questions inside the pic.jpg in the comments. Please I need to know that. I like that how it works, but I need to know WHY it is working like that, because I need to consider if I am going to trade this strategy and I have to consider to myself if this will be good for the expected strategy profit-performance.

                  Thank you for your time

                  thank you
                  Attached Files
                  Last edited by zooinek; 06-16-2010, 07:40 AM. Reason: I forgot to add the image

                  Comment


                    #10
                    Hi zooinek,

                    Here is what I believe is happening...

                    1. On BIP = 0, you get an entry and the profit target is hit within the same bar. On the SAME bar, but on BIP=1 you get another entry AFTER the previous one, where the profit target is hit as well, within the same bar. This may be giving you the illusion that two entries are being executed, however, only one at a time is being entered.

                    2. The TraceOrders are accurately reporting this behavior, showing you the ignored orders, and the reasons for them.

                    3. Please review and understand the EntriesPerDirection and EntryHandling settings, as they indeed do explain why these orders are being cancelled.
                    More info at - http://www.ninjatrader-support.com/H...xEntryHandling

                    I understand you do not want to solve it, but the same time of behavior may not be apparent in live trading since the profit may not be taken immediately, allowing another entry immediately after.
                    TimNinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      it seems you were right

                      1. On BIP = 0, you get an entry and the profit target is hit within the same bar. On the SAME bar, but on BIP=1 you get another entry AFTER the previous one, where the profit target is hit as well, within the same bar. This may be giving you the illusion that two entries are being executed, however, only one at a time is being entered.
                      I added to my code this:

                      Code:
                      if (Closes[1][0]>myValue) {
                          EnterLong(0, 1, myDynamicId);
                          Print("EnterLong. ID="+myDynamicId+". BIP="+BarsInProgress); // i added this
                      }
                      if (Closes[1][0]<myValue) {
                          EnterShort(0, 1, myDynamicId);
                          Print("EnterShort. ID="+myDynamicId+". BIP="+BarsInProgress); // i added this
                      }
                      
                      ...
                      
                      /* I added all this OnPositionUpdate */
                      		protected override void OnPositionUpdate(IPosition position) {
                      			if (Position.MarketPosition==MarketPosition.Flat) {
                      				Print("FLAT");
                      			}
                      			if (Position.MarketPosition==MarketPosition.Long) {
                      				Print("LONG");
                      			}
                      			if (Position.MarketPosition==MarketPosition.Short) {
                      				Print("SHORT");
                      			}
                      		}
                      and look at the picture.
                      It really did this.
                      First signal: BIP=0 and conditions are true so there is new EnterShort. The trade exited on profittarget. Because there is FLAT written in output window. AFTER THAT in the SAME bar is then BIP=1 conditions=true so ANOTHER EnterShort and ANOTHER profittarget. So the trades didnt run in same time. The only think I dont understand now is, why it seems in the chart that both of them entered on same price and exited on same price?
                      Does it mean that the first EnterShort entered on 1.5922 then the price fall down so position is exited on profittarget, then the price went up (back to 1.5922) and when was back the BIP=1 was created at the time so thats why the second enter is on the same price??

                      Because your theory was right. The trades are not running in the same time. At first is first trade (id=1) and AFTER this trade exited on profittarget then is second trade (id=2) ON THE SAME BAR, but not IN THE SAME TIME as first trade. So why these two trades on this one common bar has SAME ENTER PRICE AND EXIT PRICE? They are not running together in same time. They were just on same bar..
                      Attached Files
                      Last edited by zooinek; 06-16-2010, 03:00 PM. Reason: add image

                      Comment


                        #12
                        Hello Zooinek,

                        Profit Targets and Stop Loss orders are submitted upon entry execution. When backtesting this can result in an exit on the same bar.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello, I don't understand
                          Can you explain please?

                          Comment


                            #14
                            Hi zooinek,

                            In backtesting, once an entry is executed, the Profit Target and Stop Loss (if applicable) are entered at the same time, as it would in real-time. That is why you can see the profit target and the entry on the same bar in some cases.
                            TimNinjaTrader Customer Service

                            Comment


                              #15
                              Oh you mean this.. this I know
                              I thought something else..

                              Look at the picture. You will see there are two trades on one bar. At first was executed first entry and after it cached the profittarget then was executed the second entry which also cached the profittarget.
                              The trades was executed one by one !! The second entry was executed after the first entry cached the profittarget.

                              My question is: why are these two entries (executed in different time) entered on THE SAME PRICE LEVEL ??

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              640 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              366 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              572 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X