Logic for EA

 

One of the indicator in my EA I am using is the Bollinger Bands...
One of the check is to go long when the Ask is above the upperband by 5pips.

Now lets say, my EA finds all the checks to be good including the upperband check. The buy order is placed and lets say, I exist with 20pips profit. At this time, when the order is closed, all the checks are still good including the BB upperband check. My EA is immediately placing another order...But I dont want my EA to do this....
How to write a logic to avoid this second buy order immediately after the first one is closed?

 
Tom23824:

One of the indicator in my EA I am using is the Bollinger Bands...
One of the check is to go long when the Ask is above the upperband by 5pips.

Now lets say, my EA finds all the checks to be good including the upperband check. The buy order is placed and lets say, I exist with 20pips profit. At this time, when the order is closed, all the checks are still good including the BB upperband check. My EA is immediately placing another order...But I dont want my EA to do this....
How to write a logic to avoid this second buy order immediately after the first one is closed?

There are a lot of ways to do this, I suggest you implement a simple state machine and hysteresis, like bellow:


static int state=0; // global

start ()  { 
   ...
   switch (state)  {
	case 0:
		// here put the code to buy/sell on BB event (your strategy)
		if (condition)  {
			ordersend(...
			state=1;
		}
		break;
	case 1:
		// here put the code to wait the BB event finish (oposite of state 0)
		if (!condition && OrdersTotal()==0)  {
			state=0;
		}
		break;
   }
   ...
}


good lucky!


figurelli@fxcoder.com

 
Tom23824 wrote >>

One of the indicator in my EA I am using is the Bollinger Bands...
One of the check is to go long when the Ask is above the upperband by 5pips.

Now lets say, my EA finds all the checks to be good including the upperband check. The buy order is placed and lets say, I exist with 20pips profit. At this time, when the order is closed, all the checks are still good including the BB upperband check. My EA is immediately placing another order...But I dont want my EA to do this....
How to write a logic to avoid this second buy order immediately after the first one is closed?

You can check the last closed order of the concerned currency in the history and then test the time it has been closed, so your EA will always be correct even if you have to reset it for a reason or another (change of a parameter...).

Reason: