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

MAcrossover plots wrong

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

    MAcrossover plots wrong

    I have developed a dashboard that looks at SMAs on upper timeframes (minute charts) to see trend of SMAs but when I plot the current chart SMAs (10 sec. in this case), it does not plot correctly. As a standalone indicator it works fine but I wanted to combine it into one indicator to also show the 3 higher timeframes. What am I missing??
    Thanks!

    -------------------------------------------------------------------------------
    Code for Panel 3 indicator which works fine:
    if ((SMA(5)[0]>=SMA(15)[0]) && (SMA(15)[0]>=SMA(50)[0]))
    BackColor = Color.Lime;
    if ((SMA(5)[0]<SMA(15)[0]) && (SMA(15)[0]<SMA(50)[0]))
    BackColor = Color.Red;

    -------------------------------------------------------------------------------
    Code for Panel 2 indicator does not plot correctly as shown in pic:
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "tF0"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "uTF1"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "uTF2"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Block, "uTF3"));
    Add(PeriodType.Minute, timePeriod);
    Add(PeriodType.Minute, timePeriod2);
    Add(PeriodType.Minute, timePeriod3);
    Plots[0].Pen.Width = 3;
    Plots[1].Pen.Width = 3;
    Plots[2].Pen.Width = 3;
    Plots[3].Pen.Width = 3;
    Overlay = false;
    PaintPriceMarkers = false;
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar<200)
    return;

    if ((SMA(BarsArray[1],5)[0])>=(SMA(BarsArray[1],15)[0]) &&
    (SMA(BarsArray[1],15)[0])>=(SMA(BarsArray[1],50)[0]))
    PlotColors[0][0] = upColor;
    else if ((SMA(BarsArray[1],5)[0])<(SMA(BarsArray[1],15)[0]) &&
    (SMA(BarsArray[1],15)[0])<(SMA(BarsArray[1],50)[0]))
    PlotColors[0][0] = downColor;

    if ((SMA(BarsArray[2],5)[0])>=(SMA(BarsArray[2],15)[0]) &&
    (SMA(BarsArray[2],15)[0])>=(SMA(BarsArray[2],50)[0]))
    PlotColors[1][0] = upColor;
    else if ((SMA(BarsArray[2],5)[0])<(SMA(BarsArray[2],15)[0]) &&
    (SMA(BarsArray[2],15)[0])<(SMA(BarsArray[2],50)[0]))
    PlotColors[1][0] = downColor;

    if ((SMA(BarsArray[3],5)[0])>=(SMA(BarsArray[3],15)[0]) &&
    (SMA(BarsArray[3],15)[0])>=(SMA(BarsArray[3],50)[0]))
    PlotColors[2][0] = upColor;
    else if ((SMA(BarsArray[3],5)[0])<(SMA(BarsArray[3],15)[0]) &&
    (SMA(BarsArray[3],15)[0])<(SMA(BarsArray[3],50)[0]))
    PlotColors[2][0] = downColor;

    if ((SMA(5)[0])>=(SMA(15)[0]) && (SMA(15)[0])>=(SMA(50)[0]))
    PlotColors[3][0] = upColor;
    else if ((SMA(5)[0])<(SMA(15)[0]) && (SMA(15)[0])<(SMA(50)[0]))
    PlotColors[3][0] = downColor;

    tF0.Set(3); //plots on top
    uTF1.Set(2);
    uTF2.Set(1);
    uTF3.Set(0); //plots on bottom
    Attached Files

    #2
    Hello,

    Thank you for the post.

    In this case, this would likely not be enough information to know what specifically is different that is causing the "noise". However, I can say that adding more series will alter the way OnBarUpdate is called which could potentially be related to what you are seeing. For this question, you would likely need to use prints to see if the logic is still being executed the same as your original indicator.

    One possiblilty would be surrounding your syntax in a BarsInProgress check for the primary series:

    if(BarsInProgress == 0)
    {
    //insert existing logic here
    }

    If the original indicator and this indicator work on the same primary series, this may be the difference you are seeing or that the added second series are also calling OnBarUpdate which the original would not have had occurred.

    I would likely suggest reducing the chart data to a small number of bars, but enough for the indicator to produce values. After doing this, add Prints into OnBarUpdate in both the original indicator and the new indicator. Then run each in a test and take the output from each and compare it. This can tell you if your values are the same and also if the script is logically working the same.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse!!
      Figured it was something simple.
      Sure enough adding the below check did the trick!!

      if(BarsInProgress == 0)
      {
      //insert existing logic here
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Fran888, 02-16-2024, 10:48 AM
      3 responses
      43 views
      0 likes
      Last Post Sam2515
      by Sam2515
       
      Started by martin70, 03-24-2023, 04:58 AM
      15 responses
      114 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by The_Sec, Today, 02:29 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by jeronymite, 04-12-2024, 04:26 PM
      2 responses
      31 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by Mindset, 05-06-2023, 09:03 PM
      10 responses
      265 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X