The reversal size is x ticks from the true open + 1 tick before a reversal bar is formed that is not time based. I tried my hand at coding it for the first time but I ran into a bunch of issues, which I'm sure I'm doing something wrong lol. Here is the code i tried to build.
region Using declarations
using System;
using System.ComponentModel;
using System.Windows.Media;
using NinjaTrader.Cbi;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.Design;
#endregion
namespace NinjaTrader.NinjaScript.BarsTypes
{
[Description("Custom Bar Type with specified trend size and reversal size")]
public class CustomBarType : BarsType
{
private int trendSize = 5;
private int reversalSize = 5;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Custom Bar Type with specified trend size and reversal size";
Name = "CustomBarType";
BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Custom0 };
}
else if (State == State.Configure)
{
BarsPeriod.Value = "CustomBarType";
}
}
public override void ApplyOptions(BarsTypeCustom0 barsTypeCustom0)
{
base.ApplyOptions(barsTypeCustom0);
trendSize = barsTypeCustom0.TrendSize;
reversalSize = barsTypeCustom0.ReversalSize;
}
public override void OnBarUpdate()
{
if (CurrentBar == 0)
{
AddBar(BarsPeriod.Value);
}
else
{
double open = FirstTickOfBar ? Open[1] : Close[1];
double high = FirstTickOfBar ? High[0] : Math.Max(High[0], open);
double low = FirstTickOfBar ? Low[0] : Math.Min(Low[0], open);
double close = LastTickOfBar ? Close[0] : 0;
bool isTrend = Math.Abs(high - open) >= trendSize * TickSize && Math.Abs(open - low) < reversalSize * TickSize;
bool isReversal = Math.Abs(open - close) >= reversalSize * TickSize;
if (isReversal)
{
AddBar(BarsPeriod.Value);
open = close;
high = close;
low = close;
}
else if (!isTrend)
{
AddBar(BarsPeriod.Value);
open = High[0];
high = High[0];
low = Low[0];
}
Open[0] = open;
High[0] = high;
Low[0] = low;
Close[0] = close;
}
}
public override string ToString()
{
return string.Format("{0} - TrendSize:{1} ReversalSize:{2}", Name, trendSize, reversalSize);
}
[Browsable(false)]
public override bool IsIntraday
{
get { return true; }
}
[Description("Trend size in ticks")]
[GridCategory("Parameters")]
public int TrendSize
{
get { return trendSize; }
set { trendSize = Math.Max(1, value); }
}
[Description("Reversal size in ticks")]
[GridCategory("Parameters")]
public int ReversalSize
{
get { return reversalSize; }
set { reversalSize = Math.Max(1, value); }
}
}
}
I apologize as this is my first time trying to code. These are the errors I receive
line 13 column 34 it says the type or namespace name "barstype" could not be found are you missing a using directive or an assembly reference?
line 32 column 43 it says the type or namespace name "BarstypeCustomO" could not be found are you missing a using directive or an assembly reference?
line 86 column 10 it says the type or namespace name "GridCategory" could not be found are you missing a using directive or an assembly reference?
line 86 column 10 it says the type or namespace name "GridCategoryAttribute" could not be found are you missing a using directive or an assembly reference?
line 94 column 10 it says the type or namespace name "GridCategory" could not be found are you missing a using directive or an assembly reference?
line 94 column 10 it says the type or namespace name "GridCategoryAttribute" could not be found are you missing a using directive or an assembly reference?
Any help would be much appreciated!

Comment