My questions (see code below):
1.what do I use to init values each day? (during back test) [I use Initialize() - is it correct?]
2. to get today's open I use CurrentDayOHL().CurrentOpen[0], for yesterday's low I use Bars.GetDayBar(1).Low - is it correct?]
3. to get current price, I use Close[0] - is it correct?
I listed the code below:
// User defined variables (add any user defined variables below)
private bool isLowerOpen = false;
private bool isHigherOpen = false;
private double refPrice = 0.0;
private bool tradedToday = false;
protected override void Initialize()
{
SetProfitTarget("Stg001", CalculationMode.Ticks, Profit);
SetTrailStop("Stg001", CalculationMode.Ticks, Loss, false);
CalculateOnBarClose = true;
isLowerOpen = CurrentDayOHL().CurrentOpen[0] < Bars.GetDayBar(1).Low;
isHigherOpen = CurrentDayOHL().CurrentOpen[0] > Bars.GetDayBar(1).High;
if (isLowerOpen)
refPrice = Bars.GetDayBar(1).Low;
else if (isHigherOpen)
refPrice = Bars.GetDayBar(1).High;
}
protected override void OnBarUpdate()
{
if (tradedToday)
return;
if (isLowerOpen && Close[0] > refPrice) {
EnterLong(DefaultQuantity, "Stg001");
tradedToday = true;
}
else if (isHigherOpen && Close[0] < refPrice) {
EnterShort(DefaultQuantity, "Stg001");
tradedToday = true;
}
}
Comment