Hello All,
I've been trying for a while to establish a logic thus EA will Open trade(s) only Once per condition.
That means, if the BUY Condition is met, EA will open a Buy Order. Then let assume that Buy Order got closed either by hitting TP/SL but the Buy condition is Still Valid.
In this situation the EA will try to Open another Buy order but I don't want that.
The EA wont open any more Buy order. It should open a Sell order upon getting Sell condition.
So I tried to implement the attached code. I used 'Static' variable to keep the changed Boolean value once a trade got opened unless the opposite trade occurs but the EA isn't abiding by it.
So please Help me to develop an Accurate logic.
Thanks
EA will open trade Only Once per Condition.
-
Arav
- Trader
- Posts: 15
- Joined: Tue Jan 21, 2014 2:06 pm
EA will open trade Only Once per Condition.
You do not have the required permissions to view the files attached to this post.
-
MrLong
EA will open trade Only Once per Condition.
Off the cuff and untested:
and call
if(CheckTodaysOrders(Symbol(), OP_BUY)>=1) return; or
if(CheckTodaysOrders(Symbol(), OP_SELL)>=1) return;
Code: Select all
int CheckTodaysOrders(string symbol, int type)
{
int TodaysOrders=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderMagicNumber()!=MagicNumber)
continue;
if( OrderType() == type && OrderSymbol()==symbol && (OrderCloseTime()>=iTime(symbol,1440,0)))
{
TodaysOrders+=1;
}
}
return(TodaysOrders);
}
if(CheckTodaysOrders(Symbol(), OP_BUY)>=1) return; or
if(CheckTodaysOrders(Symbol(), OP_SELL)>=1) return;