EA dosen't working as expected, please help me

 

I wite code

      double price_Open = iOpen(Symbol(),0,1);
      double point = MarketInfo(Symbol(),MODE_POINT);
      
      if (  Ask > price_Open   ) 
       { 
            OrderSend(Symbol(),OP_BUY, B_lot, Ask, 0, Ask-B_SL*point, Ask+B_TP*point,"BUY one ",MagicNumber,0, Green);
       }

it is continuous order.

I want it to just enter a order when Ask > Open price

in two frame EUR/USD, GBP/USD when Ask > Open price it is enter two order

thanks

 
u must restrict in ur code not 2 open if n order already exist
 
axbc:

I wite code

it is continuous order.

I want it to just enter a order when Ask > Open price

in two frame EUR/USD, GBP/USD when Ask > Open price it is enter two order

thanks


You need to understand that if you don't place a proper condition, EA will place orders as long as Ask > OpenPrice.

So you need to add an extra condition to say only if no orders are already placed then .....

Here is how :

int    myTrades=CountTrades();
double price_Open=iOpen(Symbol(),0,1);
double point=MarketInfo(Symbol(),MODE_POINT);
if(myTrades <1)
   {
   if(Ask>price_Open)OrderSend(Symbol(),OP_BUY,B_lot,Ask,0,Ask-B_SL*point,Ask+B_TP*point,"BUY one ",MagicNumber,0,Green);
   }
//+------------------------------------------------------------------+


// Add this function to the end of your EA code

//+------------------------------------------------------------------+
int CountTrades()
  {
   int count=0;
   int trade;
   for(trade=OrdersTotal()-1;trade>=0;trade--)
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
           {
            if(OrderType()==OP_SELL || OrderType()==OP_BUY)
               count++;
           }
         else
            Print("Error selecting orders in CountTrades() function : "+GetLastError());
        }
     }
   return(count);
  }
//========================================================================

The myTrades variable is calling on the CountTrades function that checks if there are any orders already.

If there aren't any orders, only then allows the OrderSend function to open one.

Ask if you have any other questions.

 
thrdel:


You need to understand that if you don't place a proper condition, EA will place orders as long as Ask > OpenPrice.

So you need to add an extra condition to say only if no orders are already placed then .....

Here is how :

The myTrades variable is calling on the CountTrades function that checks if there are any orders already.

If there aren't any orders, only then allows the OrderSend function to open one.

Ask if you have any other questions.


Hi Thrdel,

I think that you didn't paste the whole function. It's not declared and there is no return value.

 
GumRai:


Hi Thrdel,

I think that you didn't paste the whole function. It's not declared and there is no return value.


Thanks for the heads up man. It's updated now.
Reason: