Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate() is not running, please help

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

    OnBarUpdate() is not running, please help

    Hi, my code is below:

    Code:
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"This robot is based on 1min, 5min, 30min EMA.";
                    Name = "Robot1530EMAversion0";
                    Calculate = Calculate.OnPriceChange;
                    EntriesPerDirection = 1;
                    EntryHandling = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy = false;
                    ExitOnSessionCloseSeconds = 30;
                    IsFillLimitOnTouch = true;
                    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
                    OrderFillResolution = OrderFillResolution.Standard;
                    Slippage = 0;
                    StartBehavior = StartBehavior.WaitUntilFlat;
                    TimeInForce = TimeInForce.Gtc;
                    TraceOrders = true;
                    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade = 7000;
                    IsInstantiatedOnEachOptimizationIteration = true;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 5);
                    AddDataSeries(Data.BarsPeriodType.Minute, 30);
                }
    
    protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[0] < BarsRequiredToTrade || CurrentBars[1] < (BarsRequiredToTrade / 5f) || CurrentBars[2] < (BarsRequiredToTrade / 30f))
                    return;
    
                Print(ATR30min[0]);
    When I enable the strategy, nothing prints out, so clearly there is a problem. I guess it must be my BIP & CurrentBars which prevent Print. I'm expecting it to load 7000 historical bars to let the strategy run as soon as it's enabled. Would you please advise how to correct my code?

    Thank you very much!

    #2
    Hello HiddenPhilosopher,

    Thanks for the post.

    I suspect you are right with your guess that one of the variables here is not within the range you set.

    For this you could move the print outside of the condition to find out whats going on. I would likely suggest to try doing something like the following:

    Code:
    protected override void OnBarUpdate()
    {
        Print(BarsInProgress + " " + CurrentBars[0] + " " + CurrentBars[1] + " < " + (BarsRequiredToTrade / 5f) + " " + CurrentBars[2] + " < " + (BarsRequiredToTrade / 30f));
    Checking these variables before the conditions is fine so that should allow you to output what the values and calculations are happening before your other print. Based on the output you get back you could modify the conditions or change the script settings to match whatever is needed.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello HiddenPhilosopher,

      Thanks for the post.

      I suspect you are right with your guess that one of the variables here is not within the range you set.

      For this you could move the print outside of the condition to find out whats going on. I would likely suggest to try doing something like the following:

      Code:
      protected override void OnBarUpdate()
      {
      Print(BarsInProgress + " " + CurrentBars[0] + " " + CurrentBars[1] + " < " + (BarsRequiredToTrade / 5f) + " " + CurrentBars[2] + " < " + (BarsRequiredToTrade / 30f));
      Checking these variables before the conditions is fine so that should allow you to output what the values and calculations are happening before your other print. Based on the output you get back you could modify the conditions or change the script settings to match whatever is needed.

      I look forward to being of further assistance.
      Hi Jesse - Thank you for the advice. I tried and found the problem. Below is the printout:

      0 5173 1034 < 1400 172 < 233.3333
      1 5173 1034 < 1400 172 < 233.3333
      2 5173 1034 < 1400 172 < 233.3333

      even if I set BarsRequiredToTrade 7000 (on 1 minute data series), the system doesn't load enough historical bars to make it work. Why is this happening? How do I make system load enough bars? That's the minimum number of bars I need to have my strategy work.

      Thank you for your help!

      Comment


        #4
        Hello HiddenPhilosopher,

        The BarsRequiredToTrade is just a number which denotes how many bars need to be present before a trade is placed, that will not load data or tell the script it needs 7000 bars. Did you make sure you have that many bars in the chart or when you applied it?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello HiddenPhilosopher,

          The BarsRequiredToTrade is just a number which denotes how many bars need to be present before a trade is placed, that will not load data or tell the script it needs 7000 bars. Did you make sure you have that many bars in the chart or when you applied it?

          I look forward to being of further assistance.
          I do have enough bars on the chart (I load 365 days of data). How can I force the system to load enough bars in my code? Is there such a method in strategy that can ask system to load how many historical data when enabled?
          Last edited by HiddenPhilosopher; 06-01-2020, 09:43 AM.

          Comment


            #6
            Hello HiddenPhilosopher,

            What primary series are you using?

            The prints you show have the primary at a large number 5173 but the secondary seems to have less bars 1034.

            If this was for example a daily primary and we see 5173 bars processed but only a small amount of minute data that would hint that some of the minute data for that time period is missing. It seems like you may be using a smaller timeframe for the primary here. Have you tried loading a chart for all series used to make sure all series have the full set of data? For example load the primary you use now along with the minute series all as charts.





            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello HiddenPhilosopher,

              What primary series are you using?

              The prints you show have the primary at a large number 5173 but the secondary seems to have less bars 1034.

              If this was for example a daily primary and we see 5173 bars processed but only a small amount of minute data that would hint that some of the minute data for that time period is missing. It seems like you may be using a smaller timeframe for the primary here. Have you tried loading a chart for all series used to make sure all series have the full set of data? For example load the primary you use now along with the minute series all as charts.





              I look forward to being of further assistance.

              My strategy's primary series is 1 minute, and I added 5 minute and 30 minute addtional data series. On my chart, I loaded all 1 minute, 5 minute, 30 minute series for 365 days long period. I have also downloaded last 2 years' tick data. I don't think the problem is that I don't have enough data on my chart.

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello HiddenPhilosopher,

                What primary series are you using?

                The prints you show have the primary at a large number 5173 but the secondary seems to have less bars 1034.

                If this was for example a daily primary and we see 5173 bars processed but only a small amount of minute data that would hint that some of the minute data for that time period is missing. It seems like you may be using a smaller timeframe for the primary here. Have you tried loading a chart for all series used to make sure all series have the full set of data? For example load the primary you use now along with the minute series all as charts.





                I look forward to being of further assistance.
                Please see my above reply. Any idea how to resolve this issue? It's preventing my strategy from working.

                Comment


                  #9
                  Hello HiddenPhilosopher,

                  Thanks for clarifying that.

                  Do you have the strategy applied directly to the chart you are using where you see all the bars loaded or did you apply it to the control center strategies tab?

                  From the prints the script is at 5173 minute bars processed so that wouldn't exceed your conditions to let your other print happen.

                  Are there any gaps in the data?

                  You may want to make a more simple test using less data to see where the problem starts. Try loading 30 days of data and add the Time to the print to make sure the full range of data is being seen. You can increase the number of days until you see a discrepancy, this could help to better understand what is happening. I would also suggest printing the time for the full 365 days to see what the first and last prints are listed as for the times.

                  Print(BarsInProgress + " " + Time[0] + " " + CurrentBars[0] + " " + CurrentBars[1] + " < " + (BarsRequiredToTrade / 5f) + " " + CurrentBars[2] + " < " + (BarsRequiredToTrade / 30f));


                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Renorail, Today, 01:38 PM
                  1 response
                  8 views
                  0 likes
                  Last Post Renorail  
                  Started by BrianARice, Today, 01:16 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post BrianARice  
                  Started by Ousher, Today, 09:08 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Ousher
                  by Ousher
                   
                  Started by Unsuitable, Today, 08:41 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post Unsuitable  
                  Started by newdill, Today, 07:54 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post newdill
                  by newdill
                   
                  Working...
                  X