Having a problem

 

I am having a problem with my EA. I want to only enter trades when the 4 hour candle closes. A snippet of my code is as follows:


int startHour = TimeHour(Time[0]);
int startMinute = TimeMinute(Time[0]);
int startSecond = TimeSeconds(Time[0]);

if (previousMA1 > previousMA2 && currentMA1 < currentMA2)

{
if (startHour == 0 || startHour == 4 || startHour == 8 || startHour == 12 || startHour == 16 || startHour == 20)
{
if (startMinute == 0 && startSecond == 0)
{
double sLPrevDaysHi = iHigh(NULL,0,1440); // sets stop loss at previous day's high
OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, sLPrevDaysHi, 0, "order_2", 0, 0, Purple);
OrderPrint();
}
}
}


But, it enters me multiple times, not just at 04.00.00 for instance. How do I either restrict entering trades to these times only or stop the EA from executing after a trade has been entered on the current chart? If anyone can help me, I would appriciate it.

 

Try

if(iVolume(Symbol(), 240,0) == 1) {

First tick of new 4hr bar.

 
phy:

Try

if(iVolume(Symbol(), 240,0) == 1) {

First tick of new 4hr bar.

It is entering me in the second 4 hour close and not the first. Any ideas?


if ((previousMA1 > previousMA2 && currentMA1 < currentMA2)
|| (previousMA1MinusOne > previousMA2MinusOne && currentMA1 < currentMA2)
|| (previousMA1MinusTwo > previousMA2MinusTwo && currentMA1 < currentMA2))
{
if(iVolume(Symbol(), 240,0) == 1)
{
double sLPrevDaysHi = iHigh(NULL,0,1440); // sets stop loss at previous day's high
OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, sLPrevDaysHi, 0, "order_2", 0, 0, Purple);
OrderPrint();

}
}

if ((previousMA1 < previousMA2 && currentMA1 > currentMA2)
|| (previousMA1MinusOne < previousMA2MinusOne && currentMA1 > currentMA2)
|| (previousMA1MinusTwo < previousMA2MinusTwo && currentMA1 > currentMA2))
{
if(iVolume(Symbol(), 240,0) == 1)
{
double sLPrevDaysLo = iLow(NULL,0,1440); // sets stop loss at previous day's low
OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, sLPrevDaysLo, 0, "order_2", 0, 0, Green);
OrderPrint();

}
}