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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    649 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    573 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    576 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X