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

Strategy code not executed

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

    Strategy code not executed

    Hello

    I'm coding a strategy and it worked fine last week, but now the Long entries work normal, while the Short entries won't trigger.

    As it can be seen from the attachment, it only prints the step "1", but nothing after that, meaning that, for some reason, it can't see the condition " if (currentBid < open) " and I don't understand why since I can see the last price below the Open and I'm kindda stuck here, as it should work, except it doesn't.

    Like I said, that happened without me making any changes from last week until yesterday, when I first noticed it.

    Thank you

    PS: I've had to shorten the Long entries code, due to the 10k characters limit

    Code:
    // Entries.            
                // Enter long 
                if (CONDITION TRUE[0])
                {                
                    runOnceCondFalseLong = false;                
                    if (currentAsk > open)
                    {                                            
                        longCondPrice = GetCurrentAsk(0);
                        if (longAtmId.Length == 0)                                
                        {
                            Print("++++++++++");
                            Print("Long condition at: " + Convert.ToString(longCondPrice) + " @ " + Time[0]);
                        }
                        if(!runOnceCondTrueLong)
                        {
                            Print ("S = " + Convert.ToString(CONDITION TRUE VALUE[0]) + " - " + "Current Ask: " + Convert.ToString(currentAsk) + " - " + Time[0]);
                            runOnceCondTrueLong = true;  
                        }    
                        // If there is a short ATM Strategy running close it.
                        if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)                    
                        {
                            AtmStrategyClose(shortAtmId);
                            isShortAtmStrategyCreated = false;
                        }                        
                        // Ensure no other long ATM Strategy is running.
                        if(longOrderId.Length == 0 && longAtmId.Length == 0)
                        {
                            if (longCondPrice > open && !isLongAtmStrategyCreated)
                            {
                                longOrderId = GetAtmStrategyUniqueId();
                                longAtmId = GetAtmStrategyUniqueId();
                                AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, currentAsk + offsetLimitStop * TickSize, currentAsk + offsetLimitStop * TickSize, 
                                TimeInForce.Day, longOrderId, "3C", longAtmId, (atmCallbackErrorCode, atmCallBackId) => 
                                { 
                                    //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                                    if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == longAtmId) 
                                        isLongAtmStrategyCreated = true;
                                    barNumberOfLongOrder = CurrentBar;
                                    triggerPriceLong = GetCurrentAsk(0);                                    
                                    Print("Long ATM triggered at: " + Convert.ToString(triggerPriceLong) + " - " + Time[0]);
                                    Print("##########");
    
                                });
                            }
                        }                    
    
                    }
                }            
                else if ((longAtmId.Length != 0 && isLongAtmStrategyCreated && CONDITION FALSE[0]&& currentAsk < triggerPriceLong - cancelLongShort * TickSize)  //Cancel if condition becomes false and price pulls back by CancelOffsetTicks * TickSize            
                    || (longAtmId.Length != 0 && isLongAtmStrategyCreated && CONDITION FALSE[0] && currentAsk > longCondFalsePrice + (int) Math.Ceiling((2 + 1) / 2.0) * TickSize) // Cancel if price rises 2 ticks after the condition became false 
                    || (longAtmId.Length != 0 && isLongAtmStrategyCreated && CurrentBar != barNumberOfLongOrder && IsFirstTickOfBar && CONDITION FALSE[1])  // Cancel on start of next bar if condition became false
                    || (longAtmId.Length != 0 && isLongAtmStrategyCreated && CurrentBar != barNumberOfLongOrder && !IsFirstTickOfBar && CONDITION TRUE[1] && currentAsk < triggerPriceLong - (int) Math.Ceiling((2 + 1) / 2.0) * TickSize)) // Cancel on next bar if condition still true but price pulls back 2 Ticks below the trigger price 
                {
                    AtmStrategyClose(longAtmId);
                    isLongAtmStrategyCreated = false;
                    runOnceCondTrueLong = false;
                    cancelPriceLong = GetCurrentAsk(0);
                    Print("Long ATM cancel price: " + Convert.ToString(cancelPriceLong) + " - " + Time[0]);                
                }            
    
                // Enter short 
                if (CONDITION TRUE[0])
                {
                    Print("1");    //Only prints THIS line
                    runOnceCondFalseShort = false;            
                    if (currentBid < open)
                    {                    
                        Print("2");  //...but not from THIS line down
                        shortCondPrice = GetCurrentBid(0);
                        if (shortAtmId.Length == 0)                                
                        {
                            Print("----------");
                            Print("Short condition at: " + Convert.ToString(shortCondPrice) + " @ " + Time[0]);
                        }
                        if(!runOnceCondTrueShort)
                        {
                            Print ("R = " + Convert.ToString(CONDITION TRUE VALUE) + " - " + "Current Bid: " + Convert.ToString(currentBid) + " - " + Time[0]);
                            runOnceCondTrueShort = true;  
                        }                                                
                        if(longAtmId.Length != 0 && isLongAtmStrategyCreated)                    
                        {
                            AtmStrategyClose(longAtmId);
                            isLongAtmStrategyCreated = false;
                        }                            
                        Print("3");
                        if(shortOrderId.Length == 0 && shortAtmId.Length == 0)
                        {
                            if (shortCondPrice < open && !isShortAtmStrategyCreated)
                            {
                                shortOrderId = GetAtmStrategyUniqueId();
                                shortAtmId = GetAtmStrategyUniqueId();
                                AtmStrategyCreate(OrderAction.Sell, OrderType.StopLimit, currentBid - offsetLimitStop * TickSize, currentBid - offsetLimitStop * TickSize, 
                                TimeInForce.Day, shortOrderId, "3C", shortAtmId, (atmCallbackErrorCode, atmCallBackId) => 
                                {                                 
                                    if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == shortAtmId) 
                                        isShortAtmStrategyCreated = true;
                                    barNumberOfShortOrder = CurrentBar;
                                    triggerPriceShort = GetCurrentBid(0);                                    
                                    Print("Short ATM triggered at: " + Convert.ToString(triggerPriceShort) + " - " + Time[0]);
                                    Print("##########");                            
                                });
                            }
                        }                    
                        else if(CONDITION FALSE[0])                
                        {
                            Print("About to run once short");
                            if (!runOnceCondFalseShort)                    
                            {
                                shortCondFalsePrice = GetCurrentBid(0);
                                Print ("XX>>--Short condition false at: " + Convert.ToString(shortCondFalsePrice) + " - " + "Trigger Short Price: " + Convert.ToString(triggerPriceShort) + " - " + Time[0]);                    
                                runOnceCondFalseShort = true; 
                            }
                        }
                    }
                }            
                else if ((shortAtmId.Length != 0 && isShortAtmStrategyCreated && CONDITION FALSE[0] && currentBid > triggerPriceShort + cancelLongShort * TickSize)  //Cancel if condition becomes false and price pulls back by CancelOffsetTicks * TickSize                
                    || (shortAtmId.Length != 0 && isShortAtmStrategyCreated && CONDITION FALSE[0] && currentBid < shortCondFalsePrice - (int) Math.Ceiling((2 + 1) / 2.0) * TickSize) // Cancel if price drops 2 ticks after the condition became false 
                    || (shortAtmId.Length != 0 && isShortAtmStrategyCreated && CurrentBar != barNumberOfShortOrder && IsFirstTickOfBar && CONDITION FALSE[1]) // Cancel on start of next bar if condition became false
                    || (shortAtmId.Length != 0 && isShortAtmStrategyCreated && CurrentBar != barNumberOfShortOrder && !IsFirstTickOfBar && CONDITION TRUE[1] && currentBid > triggerPriceShort + (int) Math.Ceiling((2 + 1) / 2.0) * TickSize)) // Cancel on next bar if condition still true but price pulls back 2 Ticks above trigger price 
                {
                    AtmStrategyClose(shortAtmId);
                    isShortAtmStrategyCreated = false;
                    runOnceCondTrueShort = false;
                    cancelPriceShort = GetCurrentBid(0);
                    Print("Short ATM cancel price: " + Convert.ToString(cancelPriceShort) + " - " + Time[0]);                
                }
                // End entries.
    Attached Files

    #2
    Hello itrader46,

    Thanks for your post.

    You mention that Print 2 is not reached. The if statement that controls the logic to reach that line is
    if (currentBid < open) Since this line of code is not becoming true and allowing the logic to go further, I suggest printing out the values of these conditions next to Print 1 so you can see how this condition gets evaluated to see why the logic is not going any further. For example:

    Print("currentBid: " + currentBid + " open: " + open);

    This will make it clear why the logic is not becoming true and allowing the logic to reach Print 2. It is also helpful to study the logic by printing out what exactly the strategy is doing rather than relying on visual cues.

    Please let us know if you have any questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Got it: as you can see from the attachment, it takes the open of the first bar on the chart, instead of the current bar.

      The Long entries work just coz it so happens the CurrentAsk is above the open of the chart.

      What do I do?
      Attached Files

      Comment


        #4
        This is my open declaration

        Code:
        protected override void OnBarUpdate()
                {            
                    if (BarsInProgress != 1) // return for the primary series to execute logic on the tick series
                        return;
        
                    if (CurrentBar < BarsRequiredToTrade)
                        return;
        
                    // Make sure this strategy does not execute against historical data
                    if(State == State.Historical)
                        return;            
        
                    else if(State == State.Realtime)
        
                    currentBid = GetCurrentBid(0);
                    currentAsk = GetCurrentAsk(0);        
                    open       = Bars.GetOpen(0);

        Comment


          #5
          Hello itrader46,

          currentBid is greater than open. if (currentBid < open) will evaluate to false and the logic will not enter this condition's code block.

          You are also providing Bars.GetOpen with literal indexes. I.E. You are always referencing Bar 0 on the chart, not BarsAgo 0 (the last/updating bar.)

          Please see GetCurrentAsk/GetCurrentBid documentation as well as the documentation on Bars.GetOpen to see how this indexes are used. I have also linked to our Working with Price Series documentation which outlines where BarsAgo references are used with Series objects.

          GetCurrentAsk - https://ninjatrader.com/support/help...currentask.htm

          Bars.GetOpen - https://ninjatrader.com/support/help...t8/getopen.htm

          Working with Price Series - https://ninjatrader.com/support/help...ice_series.htm

          I also suggest opening a Data Box window and enabling Bar Indexes and BarsAgo indexes. This will help to clarify which bars you are referencing when you use objects with BarsAgo references or use methods that take a literal Bar Index.

          Please let me know if you have any questions.
          Last edited by NinjaTrader_Jim; 10-29-2019, 02:17 PM.
          JimNinjaTrader Customer Service

          Comment


            #6
            I have used the syntax from GetOpen and it's not much difference, as you can see from the attachment. The current bar open is 56.17, but the code sees it as 53.85

            Code:
            protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                    {
                      base.OnRender(chartControl, chartScale);
                      // loop through only the rendered bars on the chart
                      for(barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
                      {
                        // get the open price at the selected bar index value
                        open = Bars.GetOpen(barIndex);
            //            Print("Bar #" + barIndex + " open price is " + open);
                      }
                    }
            
                    protected override void OnBarUpdate()
                    {            
                        if (BarsInProgress != 1) // return for the primary series to execute logic on the tick series
                            return;
            Attached Files

            Comment


              #7
              Hello itrader46,

              Bars.GetOpen takes a literal index. If you reference Bars.GetOpen(0) you will be referencing the first bar on the chart. This can be observed by enabling BarIndexes in the Data Box and checking the bar index for the first bar on the chart.

              If you want to reference the most recent bar using BarsAgo indexes, you will want to use Open[0] instead of Bars.GetOpen(0).
              JimNinjaTrader Customer Service

              Comment


                #8
                I'm afraid it doesn't work: when I use the code below, the open is still taken from the first bar

                Code:
                protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                        {
                          base.OnRender(chartControl, chartScale);
                          // loop through only the rendered bars on the chart    
                            for(barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
                          {
                            // get the open price at the selected bar index value
                            open = Open[0];            
                          }
                        }
                Output Prints:

                1 Short - currentBid: 56.09 - open: 53.83 - BarsInProgress: 1
                1 Short - currentBid: 56.09 - open: 53.83 - BarsInProgress: 1
                1 Short - currentBid: 56.09 - open: 53.83 - BarsInProgress: 1
                1 Short - currentBid: 56.09 - open: 53.83 - BarsInProgress: 1
                1 Short - currentBid: 56.09 - open: 53.83 - BarsInProgress: 1



                ...And when I use this code, it sort of works, but just because the Open is equal with the Bid, which is not right

                Code:
                protected override void OnBarUpdate()
                        {            
                            if (BarsInProgress != 1) // return for the primary series to execute logic on the tick series
                                return;
                
                            if (CurrentBars[1] < BarsRequiredToTrade)
                                return;
                
                            // Make sure this strategy does not execute against historical data
                            if(State == State.Historical)
                                return;            
                
                            else if(State == State.Realtime)
                
                            currentBid = GetCurrentBid(1);
                            currentAsk = GetCurrentAsk(1);        
                            open       = Open[0];
                Output prints (actual bar Open = 56.13):

                Short condition at: 56.09 @ 25/10/2019 13:37:43
                R = 1 - Current Bid: 56.09 - 25/10/2019 13:37:43
                Bar #0 open price is 56.1
                3
                Short ATM triggered at: 56.09 - 25/10/2019 13:37:43
                ##########
                1 Short - currentBid: 56.09 - open: 56.09 - BarsInProgress: 1
                1 Short - currentBid: 56.09 - open: 56.1 - BarsInProgress: 1
                2
                3
                1 Short - currentBid: 56.08 - open: 56.1 - BarsInProgress: 1
                2
                3
                1 Short - currentBid: 56.08 - open: 56.09 - BarsInProgress: 1

                Comment


                  #9
                  Hello itrader46,

                  Please see the demonstration video below showing the difference between BarsAgo indexes with Open[BarsAgo] and Bars.GetOpen(BarIndex). Please allow some time for the video to be transcoded into a streamable format.

                  https://drive.google.com/file/d/1OvA...w?usp=drivesdk
                  Last edited by NinjaTrader_Jim; 10-29-2019, 02:16 PM.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    The video doesn't do nothing to clear it up, I'm afraid: it uses OnBarClose, while I use OnEachTick, so it's not the same calculation, but I can't use OnBarClose.

                    Do you not find it strange that the Open becomes equal with the Bid when I use Open[0] or Bars.GetOpen(CurrentBar)?

                    Can you please refer this issue to somebody that knows how to solve it? It seems to me you are under the impression it is me, but according to the video and the help guide, it should work, but it doesn't.

                    Thank you

                    Comment


                      #11
                      Hello itrader46,

                      The strategy logic is not proceeding because the condition is not evaluating as true. To flush it out, we will have to understand what values you are using and what those represent.

                      You are using GetCurrentBid() as follows: currentBid = GetCurrentBid(1); You are telling NinjaTrader: "Get me the current Bid for the secondary data series (BarsInProgress 1) and assign it to currentBid."

                      You are assigning open with Open[0]. This will reflect the opening price of the developing bar when using Calculate.OnEachTick or Calculate.OnPriceChange. With Calculate.OnBarClose, Open[0] will reflect the open of the bar that has just closed instead of the developing bar.

                      So we have the open of the developing bar and the current bid price of the added data series. It would not necessarily be strange that the current Bid of that data series becomes equal to the Open of that bar.

                      Demo - https://drive.google.com/file/d/1Y8c...w?usp=drivesdk

                      Code:
                      if (BarsInProgress == 0)
                          Print(String.Format("CurrentBar: {0} Bars.GetOpen(CurrentBar): {1} Open[0]: {2} GetCurrentBid(): {3} State: {4}", CurrentBar, Bars.GetOpen(CurrentBar), Open[0], GetCurrentBid(), State));
                      As I understand this issue, there is a logical reason why the strategy is not processing further. Understanding why that logic is evaluating as it is requires a deeper look into what that condition is actually checking.

                      If this is not making sense or if I am sounding confusing, I could have a colleague follow up.

                      Let me know if matters are still unclear.
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        I'm sorry but, despite having put a bit of time in replying, it still doesn't make sense and I think if you would have put an equal amount of time into reading my posts carefully (especially #8), you would have understood what the issue really was:

                        - when the logic was not progressing, it was because of the assignment " open = Bars.GetOpen(0) " which was taking the Open of the first bar on chart - I got that

                        - when I assign open = Open[0] or open = Bars.GetOpen(CurrentBar), the issue is not that the Open "sometimes" becomes equal with the Bid (or I actually think it's the Ask), but that the Open actually follows the Ask during the course of a bar, instead of just reflecting the actual opening price.

                        For instance, I would have a bar with open of 56.13 and when the price gets to 56.08, the Open is printed as 56.09, just like I said in my post #8

                        On top of that, when I print the current bar this is what I get:


                        Output window prints:

                        Long ATM cancel cond 2 price: 56.19 - Bar #6383 open price is 56.19 - Current Bar: 1289690 - 25/10/2019 13:31:42
                        >>> Long Order ID Reset Price: 56.19 - Bar #6383 open price is 56.19 - Current Bar: 1289691 - 25/10/2019 13:31:42
                        >>## Long ATM ID Reset Price: 56.19 - Bar #6383 open price is 56.19 - Current Bar: 1289692 - 25/10/2019 13:31:42
                        ----------
                        Short condition at: 56.15 - Bar #6383 open price is 56.16 - Current Bar: 1289746 @ 25/10/2019 13:31:48
                        R = 1 - Current Bid: 56.15 - Bar #6383 open price is 56.16 - Current Bar: 1289746 - 25/10/2019 13:31:48
                        Short ATM triggered at: 56.15 - Bar #6383 open price is 56.16 - Current Bar: 1289746 - 25/10/2019 13:31:48
                        ##########
                        ++++++++++
                        Long condition at: 56.15Bar #6384 open price is 56.14 - Current Bar: 1289940 @ 25/10/2019 13:32:02
                        S = 1 - Current Ask: 56.15 - Bar #6384 open price is 56.14 - Current Bar: 1289940 - 25/10/2019 13:32:02
                        Long ATM triggered at: 56.15 - Bar #6384 open price is 56.14 - Current Bar: 1289940 - 25/10/2019 13:32:02

                        What bar is 1289690 when the data box shows for instance bar 6382 and the index prints 6383 (which is another thing I don't get, but it's only a difference of 1)?!?

                        This is the code:

                        Code:
                        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                                {
                                  base.OnRender(chartControl, chartScale);
                                  // loop through only the rendered bars on the chart    
                                    for(barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
                                  {
                                        ;
                        //             get the open price at the selected bar index value
                                    open = Open[0];
                        //            Print("Bar #" + barIndex + " open price is " + open);
                                  }
                                }
                        ...
                        
                        if (CONDITION TRUE)
                                    {                
                        //                Print("1 Long "+ " - currentBid: " + currentBid + " - open: " + open + " - BarsInProgress: " + BarsInProgress);    
                                        runOnceCondFalseLong = false;                
                                        if (currentAsk > open)
                                        {                                            
                                            longCondPrice = GetCurrentAsk(0);
                                            if (longAtmId.Length == 0)                                
                                            {
                                                Print("++++++++++");
                                                Print("Long condition at: " + Convert.ToString(longCondPrice) + "Bar #" + barIndex + " open price is " + open + " - Current Bar: " + CurrentBar +  " @ " + Time[0]);
                                            }
                                            if(!runOnceCondTrueLong)
                                            {
                                                Print ("S = " + Convert.ToString(CONDITION VALUE) + " - " + "Current Ask: " + Convert.ToString(currentAsk) + 
                                                " - Bar #" + barIndex + " open price is " + open + " - Current Bar: " + CurrentBar +  " - " + Time[0]);                    
                                                runOnceCondTrueLong = true;  
                                            }    
                                            // If there is a short ATM Strategy running close it.
                                            if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)                    
                                            {
                                                AtmStrategyClose(shortAtmId);
                                                isShortAtmStrategyCreated = false;
                                            }                        
                                            // Ensure no other long ATM Strategy is running.
                                            if(longOrderId.Length == 0 && longAtmId.Length == 0)
                                            {
                                                if (longCondPrice > open && !isLongAtmStrategyCreated)
                                                {
                                                    longOrderId = GetAtmStrategyUniqueId();
                                                    longAtmId = GetAtmStrategyUniqueId();
                                                    AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, currentAsk + offsetLimitStop * TickSize, currentAsk + offsetLimitStop * TickSize, 
                                                    TimeInForce.Day, longOrderId, "3C", longAtmId, (atmCallbackErrorCode, atmCallBackId) => 
                                                    { 
                                                        //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
                                                        if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == longAtmId) 
                                                            isLongAtmStrategyCreated = true;
                                                        barNumberOfLongOrder = CurrentBar;
                                                        triggerPriceLong = GetCurrentAsk(0);                                    
                                                        Print("Long ATM triggered at: " + Convert.ToString(triggerPriceLong) + " - Bar #" + barIndex + " open price is " + open + 
                                                        " - Current Bar: " + CurrentBar +  " - " + Time[0]);
                                                        Print("##########");                                
                                                    });
                                                }
                                            }                    
                                            else if(CONDITION FALSE)                
                                            {
                                                Print("About to run once long");
                                                if (!runOnceCondFalseLong)                    
                                                {
                                                    longCondFalsePrice = GetCurrentAsk(0);
                                                    Print ("XX>>--Long condition false at: " + Convert.ToString(longCondFalsePrice) + " - " + "Trigger Long Price: " + Convert.ToString(triggerPriceLong) + 
                                                    " - Current Bar: " + CurrentBar +  " - " + Time[0]);                    
                                                    runOnceCondFalseLong = true; 
                                                }
                                            }
                                        }
                                    }
                        Quite surprisingly, this code doesn't make things better either:

                        Code:
                        protected override void OnBarUpdate()
                                {            
                                    if (BarsInProgress != 1) // return for the primary series to execute logic on the tick series
                                        return;
                        
                                    if (CurrentBars[1] < BarsRequiredToTrade)
                                        return;
                        
                                    // Make sure this strategy does not execute against historical data
                                    if(State == State.Historical)
                                        return;            
                        
                                    else if(State == State.Realtime)
                        
                                    currentBid = GetCurrentBid();
                                    currentAsk = GetCurrentAsk();        
                        [B][COLOR=#FF0000]if (IsFirstTickOfBar)
                                    {
                                        open = Open[0];
                                    }    [/COLOR][/B]
                        Now, I mean no disrespect, but if you still have no solution, rather than send me some irrelevant videos, could you please refer this matter to somebody else? This is the 12th post already

                        All this looks to me like an issue with the way NT8 script processes OnEachTick calculation more than anything - It's the only thing it makes sense

                        Thank you

                        Comment


                          #13
                          Hello itrader42,

                          We will need assess what each value is in order to understand the output we are receiving.

                          - when I assign open = Open[0] or open = Bars.GetOpen(CurrentBar), the issue is not that the Open "sometimes" becomes equal with the Bid (or I actually think it's the Ask), but that the Open actually follows the Ask during the course of a bar, instead of just reflecting the actual opening price.
                          Did you see the same results when testing a snippet similar to what I have provided in a new script? This would establish an issue with the platform, or an issue with variable assignment.

                          Rephrasing the question, we want to know why your variable "open" is always equal to GetCurrentAsk(), GetCurrentAsk(1), or that "open" is equal to your variable "currentAsk?" This is relevant because we will want to know what exactly your variables represent. This depends on what they are assigned to and where they are assigned that value.

                          Focusing on the "open" variable and why this is matching GetCurrentAsk and not the open of the bar, where are you assigning open, and to what? I see that you assign it in OnBarUpdate only when BarsInProgress 1 is processing and on the first tick of a new bar.

                          The snippet below literally means "If the processing BarsInProgress is not the first added data series with AddDataSeries(), do not process this method further." Your logic is only processing OnBarUpdate for the single tick data series.

                          Code:
                          if (BarsInProgress != 1) // return for the primary series to execute logic on the tick series  
                               return;
                          You are also assigning "open" to Open[0] in OnRender. I would not recommend this. We do not know what the current BarsInProgress is in OnRender, and you are simply accessing Open[0] instead of Open[0][0]. You are likely assigning "open" to the single tick data series Open[0] value, which would be that tick's price since a Open[0] == High[0] == Low[0] == Close[0] for a single tick data series.

                          I also would not recommend using BarsAgo references in OnRender and would recommend using literal indexes instead. I.E. Opens[0].GetValueAt(BarIndex). Finally, I would not advise using OnRender for data operations, and I would only recommend using it for custom rendering with SharpDX.

                          What bar is 1289690 when the data box shows for instance bar 6382 and the index prints 6383 (which is another thing I don't get, but it's only a difference of 1)?!?
                          This question was presented in your other thread here. 1289690 is reflecting the CurrentBar value of the single tick data series, because the single tick data series is what is currently processing in OnBarUpdate. CurrentBar reflects the Data Series that is processing in OnBarUpdate, not necessarily the primary data series. bar 6382 would reflect whatever is assigned to barIndex in your code.

                          If you reference CurrentBars[0], this will always show the primary data series bar count. Calculate.OnBarClose will show what you see in the Data Box - 1 from the last bar on the chart because the last bar has not yet closed. Calculate.OnEachTick/OnPriceChange will have a CurrentBars[0] value that matches the index of the last/developing bar on the chart.

                          Ultimately when you are debugging your scripts, I recommend the following process

                          1. Identify the problem
                          2. Isolate the problem by commenting code, and setting up test scripts that look into the issue alone.

                          This will set the stage so you can see if you are hitting an issue with your logic and how you are assigning variables, etc. or could break the issue down to a specific behavior of the platform. In this case, the issue involves how your script is assigning variables.

                          Please let me know if you have any questions.
                          JimNinjaTrader Customer Service

                          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,266 views
                          0 likes
                          Last Post sidlercom80  
                          Started by Barry Milan, Yesterday, 10:35 PM
                          3 responses
                          13 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Working...
                          X