• 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

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 krofs, Today, 03:37 PM
      2 responses
      9 views
      0 likes
      Last Post krofs
      by krofs
       
      Started by kalalex, Today, 03:51 PM
      0 responses
      2 views
      0 likes
      Last Post kalalex
      by kalalex
       
      Started by bdelorm, Today, 12:26 PM
      5 responses
      26 views
      0 likes
      Last Post bdelorm
      by bdelorm
       
      Started by kalalex, Today, 02:23 PM
      0 responses
      3 views
      0 likes
      Last Post kalalex
      by kalalex
       
      Started by kevinenergy, Today, 01:43 PM
      4 responses
      19 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X