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

Moving average on spread (high minus low)

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

    Moving average on spread (high minus low)

    Hi

    I'm trying to make a indicator which uses a moving average of the spread (high minus low). I'm not interested in using the ATR(1) because I don't want to include any gaps.

    My problem is that I get an error CS0200 and CS0029

    Can anyone please help. The following is my code.

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class test: Indicator
    {

    SMA _maspread;
    private Series<double> _spread;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"test signals";
    Name = "test";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    NarrowSpreadRatio = 0.8;
    WideSpreadRatio = 1.5;

    }

    else if (State == State.Configure)
    {

    }

    }

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

    _spread[0] = High[0] - Low[0];
    _maspread[0] = SMA(_spread, 14);
    }

    #2
    You've declared class vars but have not initialized them in OnStateChange().
    _maspread = SMA(14);
    _spread = new Series<double>(this);

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by junkone, Today, 11:37 AM
    0 responses
    1 view
    0 likes
    Last Post junkone
    by junkone
     
    Started by quantismo, 04-17-2024, 05:13 PM
    5 responses
    33 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by proptrade13, Today, 11:06 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    34 views
    0 likes
    Last Post love2code2trade  
    Started by cls71, Today, 04:45 AM
    2 responses
    10 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Working...
    X