I am currently struggling with strategy with two data series. I am sure that it must be an easy thing but I am not a programming expert.
I have a simple strategy which enters long or short when the prise crosses above or below the 30minute opening range. This strategy works fine:
protectedoverridevoid Initialize()
{
Add(HiLoOfTimeRange(15, 30, 16, 0));
Add(HiLoOfTimeRange(15, 30, 16, 0));
SetTrailStop("", CalculationMode.Ticks, 6, false);
CalculateOnBarClose = false;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (CrossAbove(Close, HiLoOfTimeRange(15, 30, 16, 0).TheHigh, 1) && Bars.BarsSinceSession > 30)
{
EnterLong();
}
if (CrossBelow(Close, HiLoOfTimeRange(15, 30, 16, 0).TheLow, 1) && Bars.BarsSinceSession > 30)
{
EnterShort();
}
}
But if I want to extend the entering condition to depend on other data serie (e.g. ^TICK) the strategy does not work:
protectedoverridevoid Initialize()
{
Add("^TICK",PeriodType.Minute,1);
Add(HiLoOfTimeRange(15, 30, 16, 0));
Add(HiLoOfTimeRange(15, 30, 16, 0));
SetTrailStop("", CalculationMode.Ticks, 6, false);
CalculateOnBarClose = false;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (CrossAbove(Closes[0][0], HiLoOfTimeRange(15, 30, 16, 0).TheHigh, 1) && Closes[1][0]> 800 && Bars.BarsSinceSession > 30)
{
EnterLong();
}
if (CrossBelow(Closes[0][0], HiLoOfTimeRange(15, 30, 16, 0).TheLow, 1) && Closes[1][0]> 800 && Bars.BarsSinceSession > 30)
{
EnterShort();
}
}
Could you please me help me to make it work?
Thanks a lot!
Stepan

Comment