Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting difference in indicator-strategy

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

    Plotting difference in indicator-strategy

    Hello all,

    I am trying to convert a simple PMA indicator into strategy. I have searched for answers on the forum but at no avail. I am not quite familiar with the difference of plotting in indicator vs strategy. This is really simple but I am stumped.

    Can you just point out the correct syntax for these plottings(in bold) in Initialize area? I will much appreciate your expertise!

    Thanks!
    -traderjh

    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
           public class PMAtest : Strategy
        {
            #region Variables
           	// declare the variables here
            double WMA2;
            double Trigger;
    		// create the dataseries here
    		private DataSeries WMA1;
    		private DataSeries Predict;
            #endregion
    
            protected override void Initialize()
            {
                CalculateOnBarClose = false;
    			
    	    [B]Add(new Plot(new Pen(Color.Blue, 3), "Predict_Plot"));
        	    Add(new Plot(new Pen(Color.Red, 3), "Trigger_Plot"));[/B]
    			
    	    WMA1 = new DataSeries(this);
    	    Predict = new DataSeries(this);
            }
    
            protected override void OnBarUpdate()
            {
    			// if there isn't enough data just set the variables to 0
                if (CurrentBar < 7) 
                {
                    WMA1.Set(0);
                    WMA2 = 0;
                    Predict.Set(0);
                    Trigger = 0;
                }
    			// else set the variables to the real values
                else
                {
    				WMA1.Set((7*Median[0] + 6*Median[1] + 5*Median[2] + 4*Median[3] + 3*Median[4] + 2*Median[5] + Median[6])/28);
    				WMA2 = (7*WMA1[0] + 6*WMA1[1] + 5*WMA1[2] + 4*WMA1[3] + 3*WMA1[4] + 2*WMA1[5] + WMA1[6])/28;
    				Predict.Set(2*WMA1[0] - WMA2);
    				Trigger = (4*Predict[0] + 3*Predict[1] + 2*Predict[2] + Predict[3])/10;
    			}
    			
    			// set the plots
    			Predict_Plot.Set(Predict[0]);
    			Trigger_Plot.Set(Trigger); 
            }
    
            #region Properties
            #endregion
        } 
    }

    #2
    Hello traderjh,

    Thank you for your post.

    Plotting in a strategy is very different from the indicators, you can view an example at the following link: http://www.ninjatrader.com/support/f...ead.php?t=6651

    However, this is not necessary as you can just Add() the indicator to the strategy to plot it on the chart and if you need to check it's values you will just call the method of the indicator:
    Please let me know if I may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    637 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    366 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    572 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X