I'm using Heikin-Ashi bars in the chart currently. When running this for backtesting I'm not able to get the switching of changes in the color indicator with the strategy builder to work out like I wanted so far.
private int EMA8_Dn_Up;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "AutoTrade";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.ImmediatelySubmitSynchronizeAccount;
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;
EMA8_Dn_Up = 0;
}
else if (State == State.Configure)
{
AddDataSeries("MNQ 03-22", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (EMA8_Dn_Up != -1)
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"");
EMA8_Dn_Up = -1;
}
// Set 2
if (EMA8_Dn_Up != 1)
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"");
EMA8_Dn_Up = 1;
}
// Set 3
if ((EMA8_Dn_Up != 0)
&& (EMA8_Dn_Up == -1))
{
ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
EMA8_Dn_Up = 0;
}
// Set 4
if ((EMA8_Dn_Up != 0)
&& (EMA8_Dn_Up == 1))
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"");
EMA8_Dn_Up = 0;
}
}

Comment