Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What's wrong with the middle line ?

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

    What's wrong with the middle line ?

    if(SMA(Input, fastPeriod)[0] - SMA(Input, slowPeriod)[0] >=
    SMA((SMA(Input, fastPeriod)[
    0] - SMA(Input, slowPeriod))[0],3)[0])
    BackColorAll = Color.FromArgb(opacity,ColorAbove);

    I'm trying to color the background if Line 1 is greater than a
    moving average of Line 1... It's the middle line that won't compile. Do I just have a Bracket or Parentheses in the wrong place ?

    Thanks

    #2
    Hi,

    The error is in the following:

    Code:
    SMA( [B]([/B] SMA(Input, fastPeriod)[0] - SMA(Input, slowPeriod) [B])[/B] [0],3)[0]
    From how the parenthesis are shaped it seems that you want the difference of the sma fast and sma slow to be the input series for another call to the sma with a period of 3.

    This would not work because you cannot use a double for an indicators input series. Even so, the syntax for that would be like the following:
    Code:
    if(SMA(Input, fastPeriod)[0] - SMA(Input, slowPeriod)[0] >= SMA((SMA(Input, fastPeriod)[0] - SMA(Input, slowPeriod)[0]),3)[0])
    Again, this will not work. You can use another indicator as a series for your another indicators input series but you cannot use a double which is what the difference of 1 point of data in two indicator calls would return.

    You could instead make a custom dataseries that contains the values of SMA(Input, 1)[0] - SMA(Input, 1)[0] and use that as your input series.

    Take a look at the following script that achieves something similar:
    http://www.ninjatrader.com/support/f...ead.php?t=7299


    For example:

    Code:
    #region Variables
    private DataSeries myDataSeries;
    #endregion
    
    protected override void Initialize()
    {
    myDataSeries = new DataSeries(this);
    }
    
    protected override void OnBarUpdate()
    {
    myDataSeries.Set(SMA(Input, fastPeriod)[0] - SMA(Input, slowPeriod)[0]);
    
    if(SMA(Input, fastPeriod)[0] - SMA(Input, slowPeriod)[0] >= SMA(myDataSeries, 3)[0])
    {
    BackColorAll = Color.FromArgb(opacity,ColorAbove);
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you.

      That was quite a bit above my current understanding.

      Thanks again.

      Comment


        #4
        The difference between two SMAs is a raw MACD, which is not caculated from EMAs but from SMAs. This is also known as the awesome oscillator. The SMA of the differences is the signal line of the Awesome Oscillator. Your condition is equivalent with the raw MACD being above its signal line, or otherwise put a MACD histogram > 0.

        Easiest solution: Take a MACD histogram from a MACD built from SMAs and check whether it is above or below zero.

        You can code this by hand, then you would need to use a DataSeries object to collect the MACD values prior to smoothing them.

        Or you can simply use the MACDUniversal, select SMA as type for the two moving averages and the signal line. It comes with paintbars, which you would need to replace with code to change the back color.

        Comment


          #5
          Thanks Harry.
          Guess that's another way of doing it. I'm up and running now .

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          624 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          359 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          562 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          567 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X