I have an strategy that uses an indicator in 30 min timeframe and this indicator needs tick replay mode to works.
I need to run backtesting to this, using ES at 30 min timeframe but filling the orders at tick granularity. It is not possible to do this, because the indicator needs tick replay to work. So, how could I change the code in order to the strategy allways take the indicator data from 30 min TF (enabling the tick replay feature), but fills the orders with 1 tick resolution data?
This is the original code:
namespace NinjaTrader.NinjaScript.Strategies.GomPro
{
public class GomOFNakedPOCSampleStrat : Strategy
{
private Indicators.GomPro.GomOrderFlowProLevels GomOrderFlowProLevels1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Fades closest naked POC";
Name = "GomOFNakedPOCSampleStrat";
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;
Target = 10;
Stop = 10;
MinimumAge =5;
}
else if (State == State.Configure)
{
SetProfitTarget("L", CalculationMode.Ticks, Target);
SetStopLoss("L", CalculationMode.Ticks, Stop, false);
}
else if (State == State.DataLoaded)
{
// you can use the ninja strategy builder to get the correct initializer
// here are the enums:
// public enum DeltaCalcType {BidAsk,UpDownTick};
// public enum ImbalanceComparisonType { Ratio, Difference };
// public enum ImbalanceTypeType { Diagonal, Horizontal, Both };
GomOrderFlowProLevels1 = GomOrderFlowProLevels(Close, Gom.DeltaLib.DeltaCalcType.BidAsk, -1, 0, 1, false,
Gom.OrderFlow.ImbalanceDirectionType.Diagonal, Gom.OrderFlow.ImbalanceComparisonType.Ratio, 3,
Gom.OrderFlow.ImbalanceDirectionType.None, Gom.OrderFlow.ImbalanceComparisonType.Ratio, 3,
0,-1, 3, 0, Gom.OrderFlow.SRZoneEndConditionType.FullCandleCro ss, 1, false);
}
}
protected override void OnBarUpdate()
{
if (IsFirstTickOfBar)
{
GomOrderFlowProLevels1.Update();
double price=0;
bool found=false;
// for each level like NakedPOCLow1, we have to check is the data series actually contains a number.
// NakedPOCLow1BarsAgo contains the "age" of the naked poc, ie how many bars ago it created.
if ( GomOrderFlowProLevels1.NakedPOCLow1.IsValidDataPoi nt(0) && // check if value is populated
GomOrderFlowProLevels1.NakedPOCLow1BarsAgo[0] >=MinimumAge) // check if poc is old enough
{
found=true;
price=GomOrderFlowProLevels1.NakedPOCLow1[0]; // get the poc
}
//same for second level
else if ( GomOrderFlowProLevels1.NakedPOCLow2.IsValidDataPoi nt(0) && // check if value is populated
GomOrderFlowProLevels1.NakedPOCLow2BarsAgo[0] >=MinimumAge) // check if poc is old enough
{
found=true;
price=GomOrderFlowProLevels1.NakedPOCLow2[0]; // get the poc
}
// etc etc all levels can be checked
if (found)
EnterLongLimit(Convert.ToInt32(DefaultQuantity), price, @"L");
}
}
Thanks!
Comment