I am building a multi-timeframe strategy that uses 2 timeframes on 1 instrument. The shorter timeframe is BarsArray[0] and the longer is BarsArray[1].
The strategy has 4 entry conditions and 4 exit conditions which create limit orders. The limit orders use a calculated double as the entry price. The Entry and exit conditions use data from both BarsArray[0] and BarsArray[1]. The Entry and Exit price targets use data from BarsArray[1]. Please see the sample code below for EntryTarget1, ExitTarget1, Entry Condition 1 and Exit condition 1 as a sample.
When I run the strategy, I either get the log error:
Strategy Array out of Bounds Error (If I start the strategy with BarsInProgress == 0
or Output CancelAllOrders: BarsInProgress = 0 (If I start the strategy with BarsInProgress != 0
Do you have any suggestions on how to get this strategy to run on a single instrument referencing a couple of timeframes? (I've gone through Help and the forum numerous times already)
protectedoverridevoid OnBarUpdate()
{
if (BarsInProgress == 0)
return;
{
// Set Target Limit Trigger Price for Long Entry 1 (Referred to as "LEa" on charts)
double longEntry1 = IndicatorValuesfrom(BarsArray[1]);
// Set Exit Target Limit Trigger Price for Long Exit 1 (Referred to as "LX1" on charts)
double longExit1 = IndicatorValuesfrom(BarsArray[1]);
// Condition set 1 Entry Condition1
if (BarsInProgress == 0)
{
if (Entry conditionA from BarsArray[1] and ConditionsB-D from BarsArray[0] are true)
{
EnterLongLimit(DefaultQuantity, longEntry1, "LEa");
}
// Condition set 2 ... Exit Condition 1
if (BarsInProgress == 0)
{
if (Position.MarketPosition == MarketPosition.Long
&& Exit ConditionsA-C from BarsArray[0] are true)
{
ExitLongLimit(longExit1,"LX1","");
}
}
Comment