Trade Once Only - Coding Help needed

 

Hi, I have an EA that is working quite well. The problem is that in a fast moving market (based on 30min EUR/USD chart) it will open and close two or more trades in the 30min period. What happens is that quite often it will lose on the second or third trade. What I want it to do is to only trade ONCE on a 30min bar. Once a trade has been entered it MUST NOT trade again for at least the next 30mins to an hour. Any help appreciated

 

You can avoid duplicating orders by using Time[0] which returns value of current bar's open time.

 

Like chinplant suggest, you could use this trick :

datetime

CheckTime;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

return(0);

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

int start()

{

//----------------------- CHECK FOR NEW BAR

if(CheckTime!=iTime(NULL,TimeFrame,0))

{

CheckTime = iTime(NULL,TimeFrame,0);

//----------------------- YOUR ENTRY AND EXIT CONDITION

}

//----------------------- YOUR TRAILING STOP FUNCTION

}

Hope this help

 

Many thanks guys. much appreciated

 

Or as simply as:

...

if(CheckTime!=Time[0])

CheckTime = Time[0];

...

 
akiruis:
Or as simply as:

...

if(CheckTime!=Time[0])

CheckTime = Time[0];

...

Yes, that's also could do the trick

Reason: