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

Error handling issue in NT8 for Bar period

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

    Error handling issue in NT8 for Bar period

    Hi,

    I am using below code, so that unless user uses 15 min or daily or weekly or monthly time frame; it is going to show error message to prompt to correct the time period :

    else if (State == State.Historical)
    {

    if ((BarsPeriod.Value != 15 && BarsPeriod.BarsPeriodType == BarsPeriodType.Minute)||
    (BarsPeriod.BarsPeriodType != BarsPeriodType.Day)||(BarsPeriod.BarsPeriodType != BarsPeriodType.Week)||
    (BarsPeriod.BarsPeriodType != BarsPeriodType.Month))
    {
    Draw.TextFixed(this, "Error", "change to 15 Min/Daily/ Weekly/ Monthly/", TextPosition.Center);
    Log("change to 15 Min/ Daily/ Weekly/ Monthly", LogLevel.Error);
    }
    }

    But for some strange reason, it is not working as expected. so far I could find in ref guide and in forum examples, that is the way. Anyone can suggest what might be missing or wrong there?

    #2
    Hi asmmbillah, thanks for your note.

    This is happening because your conditions are linked together. If you had a 15 minute chart, that would be fine, but thats still not a 1 Month or Weekly chart so you still get the error message. You should check for each legal bar type individually.

    Best regards.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply. I have separated them like below:

      else if (State == State.Historical)
      {

      if (BarsPeriod.Value != 15 && BarsPeriod.BarsPeriodType == BarsPeriodType.Minute)
      {
      Draw.TextFixed(this, "Error", "Please change the Bar Type", TextPosition.Center);
      Log("Please change the Bar Type", LogLevel.Error);
      }

      if (BarsPeriod.BarsPeriodType != BarsPeriodType.Day)
      {
      Draw.TextFixed(this, "Error", "Please change the Bar Type", TextPosition.Center);
      Log("Please change the Bar Type", LogLevel.Error);
      }
      if (BarsPeriod.BarsPeriodType != BarsPeriodType.Week)
      {
      Draw.TextFixed(this, "Error", "Please change the Bar Type", TextPosition.Center);
      Log("Please change the Bar Type", LogLevel.Error);
      }
      if (BarsPeriod.BarsPeriodType != BarsPeriodType.Month)
      {
      Draw.TextFixed(this, "Error", "Please change the Bar Type", TextPosition.Center);
      Log("Please change the Bar Type", LogLevel.Error);
      }
      #endregion
      }

      But still same. When I keep and comment out rest, first one works, but when I start using 2nd one and rest, then same issue. Any advice?

      Comment


        #4
        Hi asmmbillah, thanks for your reply.

        You should check this from OnBarUpdate and return from the method if one of your conditions becomes true. e.g.:

        if (BarsPeriod.Value != 15 && BarsPeriod.BarsPeriodType == BarsPeriodType.Minute)
        {
        Draw.TextFixed(this, "Error", "Please change the Bar Type", TextPosition.Center);
        Log("Please change the Bar Type", LogLevel.Error);
        return;
        }
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your response. But still same. No change. I have checked them from OnBarUpdate and return from the method individually as per your example, but no luck. Anything else?

          Comment


            #6
            Hi asmmbillah, thanks for your reply.

            I was able to get it to work from State.Historical. It proved to be a little more challenging since we need to accept more than one type of bar:

            Code:
            else if (State == State.Historical)
                        {
                            if((BarsPeriod.BarsPeriodType == BarsPeriodType.Minute) && BarsPeriod.Value != 15)
                            {
                                Draw.TextFixed(this, "Error", "change minute chart to 15 Min chart", TextPosition.Center);
                                return;
                            }
                            else if((BarsPeriod.BarsPeriodType == BarsPeriodType.Day) && BarsPeriod.Value != 1)
                            {
                                Draw.TextFixed(this, "Error", "change minute chart to 15 Min chart", TextPosition.Center);
                                return;
                            }
                            else if((BarsPeriod.BarsPeriodType == BarsPeriodType.Week) && BarsPeriod.Value != 1)
                            {
                                Draw.TextFixed(this, "Error", "change minute chart to 15 Min chart", TextPosition.Center);
                                return;
                            }
                            else if((BarsPeriod.BarsPeriodType == BarsPeriodType.Month) && BarsPeriod.Value != 1)
                            {
                                Draw.TextFixed(this, "Error", "change minute chart to 15 Min chart", TextPosition.Center);
                                return;
                            }
            
                        }
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your suggestion and it worked.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              1 view
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              238 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              383 views
              1 like
              Last Post Gavini
              by Gavini
               
              Started by oviejo, Today, 12:28 AM
              0 responses
              1 view
              0 likes
              Last Post oviejo
              by oviejo
               
              Started by pechtri, 06-22-2023, 02:31 AM
              10 responses
              125 views
              0 likes
              Last Post Leeroy_Jenkins  
              Working...
              X