Secondly any chance there are more examples of multi-time frame strategies that have been handed out? I'm curious about the purpose of a few lines in the SampleMultiTimeFrame;
For example
if (sma50B1 == null || sma50B2 == null || sma5B1 == null || sma5B2 == null) -> is the purpose of this line in your SampleMultiTimeFrame just to make sure that the indicators aren't instantiated prior to assigning the values in the next few lines?
What's the purpose of the lines
if (BarsInProgress !=0)
return;
Does this make sure that you're only using the primary data series? Is there any benefit to having something like
if (BarsInProgress==0)
do primary bar data stuff
if (BarsInProgress ==1)
do bars array 1 stuff
so on for the rest of the data?
Curious because I tried to copy the format of the SampleMultiTimeFrame for the code below but still not really sure how this is supposed to work.
Anyways here's the code that's not printing right.
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class MTF_ATR : Strategy
{
private Indicators.RegressionChannel RegressionChannel1;
private ATR ATR1;
private ATR ATR2;
private ATR ATR3;
private ATR ATR4;
private ATR ATR5;
private Indicators.VWAP8 VWAP;
private Indicators.StdDev std_deviation;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"MTF_ATR";
Name = "MTF_ATR";
Calculate = Calculate.OnBarClose;
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 = 6900;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 15); // Array[1]
AddDataSeries(Data.BarsPeriodType.Minute, 60); // Array[2]
AddDataSeries(Data.BarsPeriodType.Minute, 240); // Array[3]
AddDataSeries(Data.BarsPeriodType.Day, 4); // Array[4]
}
else if (State == State.DataLoaded)
{
ATR1 = ATR(9);
}
}
protected override void OnBarUpdate()
{
//Add your custom strategy logic here.
if (CurrentBar < BarsRequiredToTrade)
return;
if (ATR2 == null || ATR3 == null || ATR4 == null || ATR5 == null)
{
ATR2 = ATR(BarsArray[1], 9);
ATR3 = ATR(BarsArray[2], 9);
ATR4 = ATR(BarsArray[3], 9);
ATR5 = ATR(BarsArray[4], 4);
// Print("1 min ATR: " + ATR1[0]);
// Print("15 min ATR: " +ATR2[0]);
// Print("60 min ATR: " +ATR3[0]);
// Print("4 hr ATR: " + ATR4[0]);
// Print("4 day ATR: " + ATR5[0]);
}
// if (BarsInProgress ==0)
// Print("Time: " +Time[0]);
// Print("1 min ATR: " + ATR1[0]);
if (BarsInProgress !=0)
Print("Time: " + Time[0]);
Print("1 min ATR: " + ATR1[0]);
Print("15 min ATR: " +ATR2[0]);
Print("1 hr ATR: " +ATR3[0]);
Print("4 hr ATR: " + ATR4[0]);
Print("4 day ATR: " + ATR5[0]);
}
}
}

Comment