Troubleshooting: EA stops working when I add a time condition to the code.

 

Hello

I've successfully programmed my first backtest profitable EA and naturally I want to tweak it to ensure it's max profitability.

The strategy is a simple sell on the break of last weeks high if last week was bullish, and buy at the break of last weeks low if last week was bearish strategy.

The more intricate part of the strategy is the use of 4hr candles.  If we are bearish in the new week, on the day that last weeks high was broken, I'm looking for a bearish engulfing pattern.

The time condition would be that the High Of The Day occurs before the current candle breaks the open of the previous bullish candle.

When I add the time condition the EA takes no trades, which I know can't be true from manually trading this strategy.

Can anyone tell me what I'm doing wrong or how to properly code the time condition to make it not confuse the algorithm?  I've posted the code used to call the time condition, and one section of the code showing how the time condition code is used.  Thank you.


time condition calculated

//levels to time
datetime TodaysOpen = iTime(NULL,1440,0);
datetime Current4hropen = iTime(NULL,240,0);
datetime CurrentTime = TimeCurrent();
int DailyMinutes = Bars(NULL,1,TodaysOpen,CurrentTime);
int HODMinute = iHighest(NULL,1,MODE_HIGH,DailyMinutes,0);
int LODMinute = iLowest(NULL,1,MODE_LOW,DailyMinutes,0);
int Crnt4HRMinutes = Bars(NULL,1,Current4hropen,CurrentTime);
int HO4hrminute = iHighest(NULL,1,MODE_HIGH,Crnt4HRMinutes,0);
int LO4hrminute = iLowest(NULL,1,MODE_LOW,Crnt4HRMinutes,0);

datetime TimeTodaysHigh = Time[HODMinute];
datetime TimeTodaysLow = Time[LODMinute];
datetime TimeCrnt4hrHigh = Time[HO4hrminute];
datetime TimeCrnt4hrlow = Time[LO4hrminute];
bool HODAboveHOLW = iHigh(NULL,1440,0) > iHigh(NULL,10080,1);


time condition in use

//last week bullish, last week high broken, and todays high is higher than last week
if (LWblsh && WbreakH && HODAboveHOLW)
//previous 4hr candle bullish
if (blshcndl)
//previous 4hr candle not a doji
if (blshcndl != bldoji)
//current 4hr candle engulfs previous candle
if (SellSignal)
//in first hour, first hour break, with swing
 {
 //entry price
 double ent1 = NormalizeDouble(((prv1hrH - prv1hrL)*.75) + prv1hrL,Digits);
 //stop loss
 double sl1 = ent1+sl;
 //take profit
 double tp1 = ent1 - (tp - (iHigh(NULL,1440,0) - ent1));
 if (frst1hr)//we are in first hour of new 4hr candle
 if (iLow(NULL,60,0) < Popen)//and this 1hr candle low is below previous 4hr open
 if (TimeTodaysHigh < TimeCrnt4hrlow)//=== TIME CONDITION ====//
 if (swinghigh1hr1hr)//and there is a swing high on the 1hr chart
 if (Bid > ent1)//and bid price is above entry price
 if 
  {
  bool SendSell = OrderSend(_Symbol,OP_SELLSTOP,lots,ent1,10,sl1,tp1,NULL,MNb,CP2);
  if(!SendSell) 
   {
   static datetime currenttick = 0;
   MqlTick last_tick;
   if (SymbolInfoTick(Symbol(),last_tick) == currenttick)
   Print("unable to open order"+"-"+Error);
   else;
   }
  } 

here's a screenshot of the EA in the backtester while running as you can see it takes no trades and prints no failed trade error messages. 


 
Since you were previously rude to me, I will not respond. Live in ignorance.
 
William Roeder #:
Since you were previously rude to me, I will not respond. Live in ignorance.

I just gave you back your rude energy, and now you're crying, live a man child. 

 
William Roeder #:
Since you were previously rude to me, I will not respond. Live in ignorance.
Whats funny is I read the forums long before I started asking questions, and noticed you were frequently rude with new people.  So I had that in mind when I posted my first post to make sure I added everything I could to just get a straight answer if you did reply, and you were rude anyway.  So it doesn’t matter, you just get a kick out of throwing your knowledge around knowing you know more than other people -but that’s temporary, and there are people who know more than you believe it or not.  Nobody is perfect, not even you.  
 
To anyone who might run into a similar issue in the future, using 1min candles to call higher time frame OHLC levels causes some type of conversion issue.  I ran the backtester on the 1min chart and the EA opened trades like normal.  So I either can just leave my charts on the 1min timeframe or figure out how to properly convert 1min charts into higher time frames.  I’m going with the former for now. 
Reason: