Download MetaTrader 5
To add comments, please log in or register
Publish your article. We will translate it into other languages!
Jhonson
35
Jhonson 2014.03.04 19:30 

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

qjol
3243
qjol 2014.03.04 20:30  
u must restrict in ur code not 2 open if n order already exist
Daniel Petrovai
440
Daniel Petrovai 2014.03.05 03:48  
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.

Keith Watford
Moderator
7907
Keith Watford 2014.03.05 04:38  
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.

Daniel Petrovai
440
Daniel Petrovai 2014.03.05 05:45  
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.
/
To add comments, please log in or register