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

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 JoMoon2024, Today, 06:56 AM
    0 responses
    6 views
    0 likes
    Last Post JoMoon2024  
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    17 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    5 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,786 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Working...
    X