Hopefully a simple question. I have code that is trying to only take trades when position is flat. This was working when I was only check the OnBarUpdate for the primary 1min bars. I then went to the added tick bars and it doesn't seem to like it.
Any help as to why this is not functioning in my code?
#region Variables
// Wizard generated variables
private int profit = 10; // Default setting for Profit
private int stop = 5; // Default setting for Stop
private int zonePos = 1; // Default setting for ZonePos
private int zoneNeg = 1; // Default setting for ZoneNeg
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
SetProfitTarget("", CalculationMode.Ticks, Profit);
SetStopLoss("", CalculationMode.Ticks, Stop, false);
// Add a 5 minute Bars object to the strategy
Add(PeriodType.Minute, 15);
//Add(PeriodType.Minute, 1);
Add(PeriodType.Tick, 1);
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Ignore bar update events for the supplementary Bars object added above
if (BarsInProgress == 0 || BarsInProgress == 1)
return;
if (Position.MarketPosition != MarketPosition.Flat)
return;
// Condition set 1
if (Closes[2][0] <= Lows[1][1] + ZonePos * TickSize
&& Closes[2][0] >= Lows[1][1] - ZonePos * TickSize
&& ToTime(Time[0]) >= ToTime(8, 45, 0)
&& ToTime(Time[0]) <= ToTime(10, 30, 0))
{
Print("15m low " + Lows[1][1]);
Print("Trigger long " + Closes[2][0]);
EnterLong(DefaultQuantity, "");
}
Comment