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

 
Alex Pirate:
Hi all, what needs to be checked??? gives a warning on modification and on opening .... (???) it returns a value and i need to check it ... how ??? EA opens orders as i see fit ... (((
extern string MMM          = "MMM";
extern double Lot          = 0.1;
extern int    TakeProfit   = 50;
extern int    StopLoss     = 20;
extern int    Slippage     = 3;
extern int    Magic        = 888;
// Moving Average 1
extern string Indi_MA1        = "MA1";
extern int    MA1_Period   = 22;
extern int    MA1_Shift    = 0;
extern int    MA1_Method   = 0;
extern int    MA1_Price    = 0;
// Moving Average 2
extern string Indi_MA2        = "MA2";
extern int    MA2_Period   = 55;
extern int    MA2_Shift    = 0;
extern int    MA2_Method   = 0;
extern int    MA2_Price    = 0;
//+------------------------------------------------------------------+
double MA1,MA2,SL,TP;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
    if (Digits == 3 || Digits == 5)
    {
      TakeProfit = TakeProfit * 10;
      StopLoss = StopLoss     * 10;
      Slippage = Slippage     * 10;
    }
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
 return(0);
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() 
 {           
    MA1 = iMA(Symbol(),0,MA1_Period,MA1_Shift,MA1_Method,MA1_Price,0);
    MA2 = iMA(Symbol(),0,MA2_Period,MA2_Shift,MA2_Method,MA2_Price,0);
    
    if (Ask >= MA1 && MA1 >= MA2 && CountBuy() == 0)
    {
       SL = NormalizeDouble(Ask - StopLoss   * Point,Digits);
       TP = NormalizeDouble(Ask + TakeProfit * Point,Digits);
       ticket = OrderSend(Symbol(),OP_BUY ,Lot,Ask,Slippage,0,0,"",Magic,0,Green);
       if (ticket > 0)
       { 
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES) == true)
            if( !OrderModify(ticket,OrderOpenPrice(),SL,TP,0) )  return;

       }      
        
    if (Bid <= MA1 && MA1 <= MA2 && CountSell() == 0) 
    
       SL = NormalizeDouble(Bid + StopLoss   * Point, Digits);
       TP = NormalizeDouble(Bid - TakeProfit * Point, Digits);
       ticket = OrderSend(Symbol(),OP_SELL,Lot,Bid,Slippage,0,0,"",Magic,0,Red);
       if (ticket > 0)
       { 
         if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES) == true)
            if( !OrderModify(ticket,OrderOpenPrice(),SL,TP,0) ) return;

       }                
    }
 }
//+------------------------------------------------------------------+
int CountBuy()
{
   int count = 0; 
   for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
   {
      if( !OrderSelect(trade,SELECT_BY_POS, MODE_TRADES) ) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() ==  Magic)
      {
        if (OrderType() == OP_BUY)
        count++; 
      } 
   }
   return(count);
}
//+------------------------------------------------------------------+
int CountSell()
{
   int count = 0;
   for (int trade = OrdersTotal() - 1; trade >= 0; trade--)
   {
      if( !OrderSelect(trade,SELECT_BY_POS, MODE_TRADES) ) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() ==  Magic) 
      {
        if (OrderType() == OP_SELL)
        count++; 
      }
   }
   return(count);
}
//+------------------------------------------------------------------+
 
Konstantin Nikitin:

Thank you!!! I'll give it a try.

 
the errors are gone... But for some reason, not all orders are opening and upgrading... it looks like we need to check the modification somehow? I must have messed up somewhere...
 
Alex Pirate:
the errors are gone... But not all orders are opening and upgrading for some reason... it looks like we need to check the modification check somehow? I must have messed up somewhere...

I did not mess up the code. I don't understand it... So, you're the expert, I'll leave it up to you.

 
Konstantin Nikitin:

I didn't work out the code. So your expert, your cards are in your hands.

Got it. Thanks anyway.

 
Maxim Kuznetsov:

this can be done via the terminal's global variables. Provided that you have the source code of the indicator and you can edit it.

It means that the indicator will calculate the parameter not through extern, but from the call of GlobalVariableGet(). And accordingly, the Expert Advisor will change this variable through GlobalVariableSet

Thanks, Maxim, at least now I know where to start from.
 
How do I call a virtual method of a parent class ?
 
There is a zigzag indicator that shows the price value of an extremum, I need to draw a trend line from the extremum to the future (the next day), how can I do that without knowing the coordinates of the second point and the Time value of the first point?
 
Vladimir Pastushak:
How to call a virtual method of parent class ?

a virtual method is a virtual method because it only has a description, and the body is written in each class separately

although if your task is just to call a method from a parent class (i.e. the method already has a body), it (the method) will be available as a regular method through inheritance - see the source code

 
Igor Makanu:

a virtual method is a virtual method because it only has a description, and the body is written in each class separately

although if your task is just to call a method from a parent class (i.e. the method already has a body), it (the method) will be available as a regular method through inheritance - the source code should be seen

Thank you. I can't get a parent class method to be called.

As far as I remember it is done through parent :: method

Reason: