Please help! I cant figured it out where is the problem in my program, I tried to debug and print but could not find why my logic is not executing entries correctly.
Here is the code:
double highPrice = 12;
double lowPrice = 8;
private bool breakout;
private bool breakdown;
private bool TradingHours;
//defaults here, did not change anything here
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 3)
return;
//Entry Conditions
breakout = (Close[1] >= highPrice && Open[1] >= highPrice && Close[2] >= highPrice && Open[2] >= highPrice && Position.MarketPosition == MarketPosition.Flat);
breakdown = (Close[1] <= lowPrice && Open[1] <= lowPrice && Close[2] <= lowPrice && Open[2] <= lowPrice && Position.MarketPosition == MarketPosition.Flat);
TradingHours = ((ToTime(Time[0])>=000000 && ToTime(Time[0])<=160000) || (ToTime(Time[0])>=180100 && ToTime(Time[0])<=235959));
if(TradingHours){
// LongEntry
if (breakout && Close[0] == highPrice) {
EnterLongLimit(0, false, 1, highPrice, "LongEntry1");
}
// ShortEntry
if (breakdown && Close[0] == lowPrice) {
EnterShortLimit(0, false, 1, lowPrice, "ShortEntry1");
}
}
Please see also attachment I visually draw what I want to achieve.
Comment