Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CandleSize

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

    CandleSize

    The following is a script that simply subtracts the low from the high of a candle and returns the size (in number of ticks) of a candle. I've downloaded a free indicator called BarCounter that tells how many bars have passed since a session has started. The question is what code do I need to add to make it so that I can add the candlesize parameter to the barcounter indicator:

    region Using declarations
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    [Description("Calculates the size of a candle on any timeframe")]
    public class CandleSize : Indicator
    {
    private double candleSize;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Calculates the size of a candle on any timeframe";
    Name = "CandleSize";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = false;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = ScaleJustification.Right;
    IsSuspendedWhileInactive = true;
    AddLine(Brushes.DarkCyan, 25, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLo wer);
    AddLine(Brushes.DarkCyan, 40, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUp per);
    }
    else if (State == State.Configure)
    {
    AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, "CandleSize");
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] == 0)
    {
    return;
    }
    double high = High[0];
    double low = Low[0];
    candleSize = Math.Abs(high - low);
    CandleSizePlot[0] = candleSize / TickSize;
    }

    region Properties
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> CandleSizePlot
    {
    get { return Values[0]; }
    }
    #endregion
    }
    }​

    #2
    Hello, thanks for writing in. It would not be a good idea to edit scripts without fully understanding each part of the script and how it works and knowledge of fixing compile errors should one occur. If you are just starting out making indicators, we have some tutorials here that you can follow:



    To combine two indicators you will want to use one script that contains from each, the AddPlot, the OnBarUpdate method, and the properties of each indicator.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by stafe, 04-15-2024, 08:34 PM
    9 responses
    41 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by frslvr, 04-11-2024, 07:26 AM
    7 responses
    111 views
    1 like
    Last Post caryc123  
    Started by rocketman7, Today, 09:41 AM
    3 responses
    8 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by traderqz, Today, 09:44 AM
    2 responses
    5 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by rocketman7, Today, 02:12 AM
    7 responses
    31 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X