stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

EA will open trade Only Once per Condition.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=3832
Page 1 of 1
Author:  Arav [ Mon Sep 15, 2014 5:04 pm ]
Post subject:  EA will open trade Only Once per Condition.

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
Author:  MrLong [ Mon Sep 15, 2014 5:33 pm ]
Post subject:  EA will open trade Only Once per Condition.

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;
All times are UTC Page 1 of 1