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 an indicator in a strategy

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

    Plotting an indicator in a strategy

    Hello,

    I'm still a beginner with NT and have plenty to learn.

    In my strategy development I'd need to visualize the indicators and have been trying to understand how that should be done. So I took the NT Sample MACrossOver and modified a copy of it.

    But I fail to understand why my added:
    EMA(10).Plots[0].Pen.Color=Color.Gray;
    and
    Add(EMA(10));

    Don't produce anything visible while the original SMA(Fast) and (Slow) plot just fine.

    Thanks for any advice,
    Eelofi

    #2
    Hello eelofi,

    Thank you for your post.

    Try setting the SMAs to transparent for the color and then advise if you see the gray EMA plot.

    Comment


      #3
      Thanks Patrick,

      I set the SMA's to not plot at all. And now I see no indicators. There something fundamental about drawing an indicator in a strategy which I haven't spotted / understood

      BR,
      Eelofi

      Comment


        #4
        Hello eelofi,

        Please provide the full code you are using for the indicator.

        Comment


          #5
          Trying to make it as simple as possible in the beginning. So took the SampleMA Crossover and just added the EMA and tried to EMA visible in the chart.


          //
          // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
          //

          #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.Strategy;
          #endregion

          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
          /// <summary>
          /// Simple moving average cross over strategy.
          /// </summary>
          [Description("Simple moving average cross over strategy. Test 20150618")]
          public class Test20150618 : Strategy
          {
          #region Variables
          private int fast = 10;
          private int slow = 25;
          #endregion

          /// <summary>
          /// This method is used to configure the strategy and is called once before any strategy method is called.
          /// </summary>
          protected override void Initialize()
          {
          SMA(Fast).Plots[0].Pen.Color = Color.Orange;
          SMA(Slow).Plots[0].Pen.Color = Color.Green;
          EMA(10).Plots[0].Pen.Color=Color.Gray;

          Add(SMA(Fast));
          Add(SMA(Slow));

          Add(EMA(10));

          CalculateOnBarClose = true;
          }

          /// <summary>
          /// Called on each bar update event (incoming tick).
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (CrossAbove(SMA(Fast), SMA(Slow), 1))
          EnterLong();
          else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
          EnterShort();
          }

          #region Properties
          /// <summary>
          /// </summary>
          [Description("Period for fast MA")]
          [GridCategory("Parameters")]
          public int Fast
          {
          get { return fast; }
          set { fast = Math.Max(1, value); }
          }

          /// <summary>
          /// </summary>
          [Description("Period for slow MA")]
          [GridCategory("Parameters")]
          public int Slow
          {
          get { return slow; }
          set { slow = Math.Max(1, value); }
          }
          #endregion
          }
          }

          Comment


            #6
            OK, I noticed yesterday that this strategy doesn't in fact display the graph for the indicators, not SMA nor EMA.

            Then I tried to find an example which would actually draw the indicator onto the chart and found one at: http://traders.com/Documentation/FEE...ps.html#item12

            So from this one I now understand how to get an indicator values visualized into the graph. But as far as I can see the syntax is what I was trying to use in the first place:
            Add(SMA(8));
            SMA(8).Plots[0].Pen.Width = 2;

            But anyways, got my problem solved now. And now heading towards the next problem..

            Cheers,
            Eelofi

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sidlercom80, 10-28-2023, 08:49 AM
            170 responses
            2,270 views
            0 likes
            Last Post sidlercom80  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            17 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            3 views
            0 likes
            Last Post adeelshahzad  
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            3 views
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Working...
            X