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

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.

        WRT to the equavolume candles, Sierra has this built in, but it suffers the same visual display problems as NinjaTrader due to the locked time axis. If you look at Linda's webinar, her husbands platform "Photon" does not seem to suffer the same limitations, and also I believe the logic is different (at least from Sierra). I am not sure if Sierra is weighting based on session average, or some sort of fixed value of 'x' bars, but either way during the webinar the Photon platform seemed to …

        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 patrickmlee007, Today, 09:33 AM
          2 responses
          15 views
          0 likes
          Last Post patrickmlee007  
          Started by magnatauren, 08-15-2020, 02:12 PM
          5 responses
          206 views
          0 likes
          Last Post RaddiFX
          by RaddiFX
           
          Started by rene69851, 05-02-2024, 03:25 PM
          1 response
          21 views
          0 likes
          Last Post rene69851  
          Started by ETFVoyageur, Yesterday, 07:05 PM
          5 responses
          45 views
          0 likes
          Last Post ETFVoyageur  
          Started by jpeep, 08-16-2020, 08:31 AM
          13 responses
          487 views
          0 likes
          Last Post notenufftime  
          Working...
          X