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

ContainsValue(1) = false

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

    ContainsValue(1) = false

    Hello, I have an indicator with some N/A values I just want to ignore in my strategy. I´m trying to code this:

    Code:
    if ContainsValue(1) = false
    			return;
    (I want 1 bar ago, because if there´s no value in bar 0, my strategy would do nothing. But didn´t find the way to also do nothing if previous bar value is N/A too.)

    As usual in my learning path, it doesn´t work what I try to do, help please!

    How can I tell my strategy to do nothing if previous bar contains a N/A value?

    PS: I´ve red some posts about ContainsValue, and DataSeries class info in the help guide, but did not get anything clear.

    #2
    Hello tomaslolo, and thank you for your question.

    If by N/A value you are referring to the value that shows up in the DataBox for an indicator, this is not something either visible or configurable through NinjaScript.

    If you mean something else, could you send a screenshot with an N/A value displayed within it?

    To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.
    Click here for instructions
    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.
    Click here for detailed instruction
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Yes, I mean the N/A value that shows up in the DataBox for an indicator. I want my strategy to ignore those values, but I think it doesn't.


      Imagine I modify MACD indicator, so I only want to show positive MACD's, by adding the condition:

      Code:
      if ( fastEma[0] - slowEma[0] > 0) 
                      { 
                          Value.Set(macd); 
                      }
      So the modified indicator now is:

      Code:
       protected override void OnBarUpdate() 
              { 
                  if (CurrentBar == 0) 
                  { 
                      fastEma.Set(Input[0]); 
                      slowEma.Set(Input[0]); 
                      Value.Set(0); 
                      Avg.Set(0); 
                      Diff.Set(0); 
                  } 
                  else 
                  { 
                      fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]); 
                      slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]); 
       
                      double macd        = fastEma[0] - slowEma[0]; 
                      double macdAvg    = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; 
                       
                      [B]if ( fastEma[0] - slowEma[0] > 0) 
                      { 
                          Value.Set(macd); 
                      }  [/B]   
                      Avg.Set(macdAvg); 
                      Diff.Set(macd - macdAvg); 
                  } 
              }
      The indicator is plot as shown in "NA value.jpg" attached file. It's fine because only shows positive values of MACD.

      Then imagine you create a strategy with this condition to go long:

      Code:
              protected override void OnBarUpdate() 
              { 
                  // Condition set 1 
                  if (MACDonlypositive(12, 7, 9)[0] > 0 
                      && MACDonlypositive(12, 7, 9)[1] > 0) 
                  { 
                      EnterLong(DefaultQuantity, ""); 
                  }
      So you need two consecutive bars with positive values of MACD's to go long. But as you can see in attached file (Goes long even witrh NA value.jpg), it goes long and should not. Is this correct?

      Is there a way to go long only if you have two consecutive bars with positives values of MACD?

      Thank you in advance.
      Attached Files

      Comment


        #4
        That's why I wanted to use something like

        Code:
        if ContainsValue(1) = false 
        return;
        If previous bar has no value (N/A), return.

        Comment


          #5
          Originally posted by tomaslolo View Post
          That's why I wanted to use something like

          Code:
          if ContainsValue(1) = false 
          return;
          If previous bar has no value (N/A), return.
          You are very close, you're easily within 5% of getting it.

          ContainsValue() is a method call for a DataSeries, so just append ".ContainsValue(indx)" to anything that returns a DataSeries and you're done.

          For example, I have an indicator that has a public DataSeries property called "EcoRising", and it will have non-rising values basically set to N/A, same as your situation.

          So, I first declare an indicator reference,

          Code:
          private ECO EcoIndy = null;
          save my indicator reference in Initialize(),

          Code:
          EcoIndy = ECO(7, 4, 21);
          Then in OnBarUpdate() I can check if the public "EcoRising" DataSeries contains a value for the current bar and the previous bar, like this,

          Code:
          if (EcoIndy.EcoRising.ContainsValue(0) && EcoIndy.EcoRising.ContainsValue(1))
             // ECO indicator is rising for most recent two bars
          Does this example help?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by PaulMohn, Today, 05:00 AM
          0 responses
          5 views
          0 likes
          Last Post PaulMohn  
          Started by ZenCortexAuCost, Today, 04:24 AM
          0 responses
          5 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by ZenCortexAuCost, Today, 04:22 AM
          0 responses
          2 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by SantoshXX, Today, 03:09 AM
          0 responses
          15 views
          0 likes
          Last Post SantoshXX  
          Started by DanielTynera, Today, 01:14 AM
          0 responses
          3 views
          0 likes
          Last Post DanielTynera  
          Working...
          X