Download MetaTrader 5

need your help : OrderSend opens multiple orders

To add comments, please log in or register
ARRESSS23
18
ARRESSS23  

Hello every  body,

How are you,
I need your helps please .I cant use English so correctly,
that's why , I use the google translation service.

I'm sorry if you find some errors.

I am a beginner in programming, I just studied the language mql4.
I am
training to create some functions,

I want to program a very easy code:
I want Metatraider to execute a buy order without any conditions.
then if the price go up or down by 30 points, it opens a second sale order.

By doing a backtest, the code opens multiples buy orders knowing that I gave it the order to open a single buy order.

where is the error please ???

Files:
TEST_3.mq4 3 kb
Stanislav Ivanov
1450
Stanislav Ivanov  

You can use a check function to see if there are already any orders with the same magic number and symbol 

like this one

bool AreThereOrders ()
{
int i;
for (i=OrdersTotal()-1; i>=0; i--)
   {
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   continue;
   if( OrderMagicNumber()== magic && OrderSymbol()==Symbol()) 
   {
   return (true);
   } 
  }         
   return (false) ;   
   }

in the trading conditions just add AreThereOrders()==false 

whroeder1
18252
whroeder1  
  1. No problems. When using mechanical translation, always use simple language structure.

  2. It opens multiple orders because that is what you told it to do, when a tick comes in, open.
    void OnTick(){
         RefreshRates();                                                                      // on raffraichit la valeur de Ask
         ticket_buy=OrderSend(Symbol(),OP_BUY,lot_buy,Ask,slippage,0,0,NULL,magic_buy,0,0);   //executer l'ordre d'achat  
    
    Check if there is already an open order. Per #1 Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  3. No need for the RefreshRates. Only after Sleep and between server calls the market will have changed. You must update your variables. To use any pre-defined variables and series arrays you must call RefreshRates
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference RefreshRates updates:
    Predefined variables: Ask, Bars, Bid, Close[], High[], Low[], Open[], Point, Time[], Volume[]
              RefreshRates - Timeseries and Indicators Access - MQL4 Reference
              Predefined Variables - MQL4 Reference
    Also updates: Hour, Minute, and Seconds
              Minute() returns wrong values - or am I wrong? - MQL4 and MetaTrader 4 - MQL4 programming forum
    And updates: OrderClosePrice() on the next order select call.

  4.      if (price == price_open_buy + (distance*pip))      
    Doubles are rarely equal.
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

ARRESSS23
18
ARRESSS23  
it works ,
thank you Stanislav Ivanov, I used your function and it works very well.
thank you whroeder1, i followed all your valuable advice and i visited all the links you put.
I am currently working on the equality of double. 
I hope to benefit from your help
Files:
To add comments, please log in or register