Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1076

 
danil77783:

Hello. Can you help me if you have time Question is this, I need the EA to open an order on each signal of two indicators, (they give a signal when they are in certain combination) in a word, there should be several orders to buy or to sell in the market, accordingly, according to the signals of the indicators. But I have only one order in the market and until it closes the next one does not open...... Is it a matter of counting orders? Please give me a hint. If you need it, i can send you the code.

Thanks in advance!

remove "if (OrdersTotal()==0)...." condition. - They just say: search for entries and open new orders only when there are no orders at all.

If you do not want to open a big pack of new orders without such a condition, you need to create an additional condition. And this depends on your strategy: not to open a new one within time T of the previous one, or to control the bars or to keep distances in pips between orders...

 

Hello. I will start by saying thank you very much for helping newbies. I wouldn't be able to answer elementary questions for myself day after day to one newbie and then another.

And the question is this:

I thought before, when mql4 was a bit different, that any order processing, like opening/closing/modifying after possible error should be interrupted by return(0) function. Because of that, if I had to close several open orders at the current price, the tester would close them one by one on every new bar and that would probably distort the real picture (quite dramatically, sometimes) in the tester (for every tick of a frame). The new EA has to close several orders exactly by the signal and partially.

Question: Is it possible to process all of them (close them partially) in a loop, without interrupting the loop each time? Will the tester be able to handle it? I.e., will it be able to partially close all of them on one bar?

 
XpeHHukoB:

Hello. I will start by saying thank you very much for helping newbies. I wouldn't be able to answer elementary questions for myself day after day to one newbie and then another.

And the question is this:

I thought before, when mql4 was a bit different, that any order processing, like opening/closing/modifying after possible error should be interrupted by return(0) function. Because of that, if I had to close several open orders at the current price, the tester would close them one by one on every new bar and that would probably distort the real picture (quite dramatically, sometimes) in the tester (for every tick of a frame). The new EA has to close several orders exactly by the signal and partially.

Question: Is it possible to process all of them (close them partially) in a loop, without interrupting the loop each time? Will the tester be able to handle it? I.e., will it be able to partially close all of them on one bar?

It can do it without any problems on one small condition. The code must be written correctly.

 
Seric29:
If there are 2 functions (possibly overloaded), for example, int Funkz(int a) int Funkz(int a, int b, int w), and then the program is compiled, which function will work faster, the first considering that it has one argument or it does not matter, because the program is already built and what is described in the body, or all the same there is a small effect, because the function arguments represent a stack for which the memory is reserved?

If you have two functions of the same name with different number of arguments, it's not a question of which one will be called faster. When you call a function, you don't write Funkz(), you specify the number of arguments.

The question is whether the compiler will chew up functions with the same name.

As I understand it, we are not talking about the code, but about the compiled file?

 
Um... Thank you for your answer, Alexei. a lot has been cleared up.
 
Help please, we have SL equal to a value in pips (this level of loss - user-adjustable parameter), and we have a symbol price for the day low or high - it's like a second stop loss and at different points in time they will be different, I need the auto comparing function - so that after that robot sets a stop loss for the smallest parameter (SL or Ilow - for buy or SL -iHign for sell) below is the code that does not give the desired result, I can not understand what it is...
   пользовательский параметр - extern int    SL               = 1000;
//---------------------------------------------------------------
bool CheckForStopLossSell()
  {
   double Hign=iHigh(Symbol(),PERIOD_D1,1);
   double StopLoss=NormalizeDouble(SL*Point,Digits);
   double uroven = StopLoss;
   double OOPS=iLow(Symbol(),PERIOD_D1,1)-StepOpenOrder*Point;
   double StopLossS=NormalizeDouble(OOPS+StopLoss,Digits);
   //----------------------------------------
   if(Hign>StopLoss) Alert("StopLoss");
   return bool(StopLossS);
   
   //else
   if(Hign<StopLoss) Alert("Hign");
   return bool(Hign); 
   
   //else
   Alert("uroven");
   return bool(uroven); 
   
  }
//--------------------------------------------------------------
bool CheckForStopLossBuy()
  {
   double LOW=iLow(Symbol(),PERIOD_D1,1);
   double StopLoss=SL*Point;
   double uroven = StopLoss;
   double SPREAD = MarketInfo(Symbol(),MODE_SPREAD)*Point;
   double OOPB = (iHigh(Symbol(),PERIOD_D1,1)+SPREAD)+StepOpenOrder*Point;
   double StopLossB=OOPB-StopLoss;
   //-------------------------------------------
   if(LOW<StopLoss) Alert("StopLoss"); 
   return bool(StopLossB);  
   
   //else
   if(LOW>StopLoss) Alert("LOW"); 
   return bool(LOW);  
   
   //else
   Alert("uroven");
   return bool(uroven);  
   
  }
//---------------------------------------------------------------
 
XpeHHukoB:

If you have two functions of the same name with different number of arguments, it's not a question of which one will be called faster. When you call a function, you don't write Funkz(), you specify the number of arguments.

The question is whether the compiler will chew up functions with the same name.

You mean the compiled file, not the code?

And if the functions are different, then which one will work faster with fewer or more arguments? I think overloading with different numbers also carries a load or is it just for convenience?

 

Please tell me how to write #define ?

I write it like this

#define  my_POS    cst_Position.my_Position

If I change this construction to def - everything works.

my_POS.SelectByTicket(pos_DATA(DATA_TICKET))

But when I just write my_POS., the function list won't pop up after a dot.

Same for

#define  pos_DATA  cst_Position.getPositionData

there are no hints after the pos_DATA(.

What am I doing wrong?

 
bool operation=0;for(int pos=0;pos<OrdersTotal();pos++)
     {if ( OrderSelect (pos, SELECT_BY_POS) == false )  continue;
      if ( OrderSymbol()==Symbol()) break;}


//=========================================================================================================
if(Hour()>=2&&Hour()<=18&&operation==0){
if(OPB1==1)
   {operation=1;if(operation==0 &&OrderSymbol()!=Symbol()||OrdersTotal()==0)
        {OrderSend(Symbol(),OP_BUY,lots,Ask,0,Bid-ss*Point,Ask+T*Point,"My order#",mn,0,Green);}}
        if (OrderType()==OP_BUY &&OrdersTotal()==1&&OrderMagicNumber()==8)
        {OrderSend(Symbol(),OP_SELLSTOP,5*lots,OrderOpenPrice()-(ss-ss/4)*Point,0,0,SstopClose,"My order#",80,0,Red);}
       

if(OPS1==1)
   {operation=1;if(operation==0 &&OrderSymbol()!=Symbol()||OrdersTotal()==0)        
         {OrderSend(Symbol(),OP_SELL,lots,Bid,0,Ask+ss*Point,Bid-T*Point,"My order#",mn,0,Red);}}
         if (OrderType()==OP_SELL &&OrdersTotal()==1&&OrderMagicNumber()==8)
         {OrderSend(Symbol(),OP_BUYSTOP,5*lots,OrderOpenPrice()+(ss-ss/4)*Point,0,0,BstopClose,"My order#",80,0,Green);}}



if(OrderMagicNumber()==80){operation=0;
 {for( int  ii=OrdersTotal()-1;ii>=0;ii--)
       {OrderSelect(ii, SELECT_BY_POS);
        int  type   = OrderType();bool result = false;
        switch(type)
         {case OP_BUYSTOP   : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );//break;
          case OP_SELLSTOP  : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); //break;
         
          result = OrderDelete( OrderTicket() );//break;
          }}}}

Hello, dear experts!

Please help me to solve this problem.

When testing any pair, everything works properly, but when working with other currencies, the pending orders are not placed (I have to expose the pending order) and are not closed after take profit triggering.

Please advise how to change the code, if possible:



Thank you very much in advance

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
Files:
c5k8icfo.png  55 kb
 
Motzaart:

Hello, dear experts!

Please help me to solve this problem.

...

Please insert the code correctly:


Reason: