EA will open trade Only Once per Condition.

Post Reply
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

EA will open trade Only Once per Condition.

Post by Arav »

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
You do not have the required permissions to view the files attached to this post.
MrLong

EA will open trade Only Once per Condition.

Post by MrLong »

Off the cuff and untested:

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);
  }
and call

if(CheckTodaysOrders(Symbol(), OP_BUY)>=1) return; or

if(CheckTodaysOrders(Symbol(), OP_SELL)>=1) return;
Post Reply

Return to “Coders Hangout”