• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help me understand Plot0.Set() better

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

    help me understand Plot0.Set() better

    Question 1:
    This code works great:
    protected override void OnBarUpdate()
    {
    Plot0.Set(EMA(21)[0]);
    }
    Now all I do is change the "[0]" to "[1]".
    This code doesn't plot anything... just blank... not even a zero-line:
    protected override void OnBarUpdate()
    {
    Plot0.Set(EMA(21)[1]);
    }
    why doesn't it plot anything?
    ------------------------------------------------------------------------------------------------------------
    Question 2:
    This code works great on "/ES 09-16" between 6AM and 2PM pacific time 8/19/16:
    protected override void OnBarUpdate()
    {
    double v1;
    if (EMA(21)[0] > 2178.5) {v1 = 1.0;} else {v1 = 0.0;}
    Plot0.Set(v1);
    }

    Again, just change the "[0]" to "[1]" and, as expected...
    This code doesn't plot anything... just blank... not even a zero-line:
    protected override void OnBarUpdate()
    {
    double v1;
    if (EMA(21)[1] > 2178.5) {v1 = 1.0;} else {v1 = 0.0;}
    Plot0.Set(v1);
    }

    Now add in the ADX(14)[0] < 50 qualification to the if statement, and, voila...
    This code works great:
    protected override void OnBarUpdate()
    {
    double v1;
    if (ADX(14)[0] < 50 && EMA(21)[1] > 2178.5) {v1 = 1.0;} else {v1 = 0.0;}
    Plot0.Set(v1);
    }
    why does adding the "ADX(14)[0] < 50" clause suddenly perk it up again?

    #2
    Hello jalexan1,

    Thank you for writing in.

    Question 1

    Before attempting to access EMA(21)[1], you'll need to ensure that you have at least two bars on your chart. EMA(21)[1] would be grabbing the EMA value from the previous bar. When your script attempts to access a previous bar's value when evaluating on the first bar, that value does not exist since there isn't a bar previous to the first bar on the chart.

    You will want to use this code to prevent your script from evaluating EMA(21)[1] before two bars have elapsed:

    Code:
    if (CurrentBar < 1)
         return;
    More information about this concept can be found here: http://ninjatrader.com/support/forum...ead.php?t=3170

    Question 2

    When using && in your if statement, both conditions specified need to be true.

    The reason why your indicator does not run into any error is because, at the time it is checking for ADX(14)[0] < 50, it is not true. And because it is not true, there is no need to check if EMA(21)[0] > 2178.5 is true, therefore, preventing any errors from occurring because that second condition is never evaluated in the first place.

    The next time this condition is checked again, at least two bars have elapsed and therefore EMA(21)[1] will not produce any error.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      thanks

      very subtle, very tricky, very elegant, and VERY WELL EXPLAINED!!! thanks so much, Zachary. : )

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by dsxfcv, Today, 02:02 AM
      0 responses
      4 views
      0 likes
      Last Post dsxfcv
      by dsxfcv
       
      Started by FMtrader, Today, 01:57 AM
      0 responses
      8 views
      0 likes
      Last Post FMtrader  
      Started by Nat11, Yesterday, 04:30 AM
      1 response
      19 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Option Whisperer, 12-07-2019, 11:50 AM
      2 responses
      14 views
      0 likes
      Last Post Option Whisperer  
      Started by TraderJim618, 12-07-2019, 01:20 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Working...
      X