I am trying to create a simple strategy using BSTVolume indicator ( publicly available on user share ).
I want to use renko bars ( ninzarenko or Unirenko ), and since the BSTVolume indicator needs to be used on each tick, i set my strategy that way.
The problem is that I can not read the values from 1 or 2 bars ago, i printed the values and i always get 0.
If i set the data series to tick replay, the strategy works in the history, but on real market conditions, it doesn't work, regardless if I use tick replay or not.
You can see in the screenshot ( both the strategy and the indicator were loaded more than 10 bars ago ) that the indicator plots values, but my strategy can't read them.
What am I doing wrong here?
namespace NinjaTrader.NinjaScript.Strategies
{
public class BSTStrategy : Strategy
{
private BSTVolume BSTVolume1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "BSTStrategy";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
Contracts = 1;
Stop = 9;
Target = 4;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
else if (State == State.DataLoaded)
{
BSTVolume1 = BSTVolume(Close, true, true, 2);
SetStopLoss("", CalculationMode.Ticks, Stop, false);
SetProfitTarget("", CalculationMode.Ticks, Target);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 4)
return;
Print(
Time[1]
+ " Buys 1:" + BSTVolume1.Buys[1]
+ " Buys 2:" + BSTVolume1.Buys[2]
);
// Set 1
if (
IsFirstTickOfBar &&
BSTVolume1.Sells[1] > BSTVolume1.Sells[2] &&
Close[1] > Open[1]
)
{
EnterLongLimit(Convert.ToInt32(Contracts), Close[1], "");
}
// Set 2
if (
IsFirstTickOfBar &&
BSTVolume1.Buys[1] > BSTVolume1.Buys[2] &&
Close[1] < Open[1]
)
{
EnterShortLimit(Convert.ToInt32(Contracts), Close[1], "");
}
}

Comment