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

 
Igor Makanu:

If it is a question of increasing the lot size of a new order relative to the maximum lot size of already open orders, then when counting orders, remember the maximum lot size of orders

like this:

I have the lots counted. I would like the step to also increase with each trade. By coefficient

 
Carcass77:

I have the lots counting. I would like the pitch to increase with each trade. By the coefficient.

This is the second time you've written about the "magic step" and we have to guess what the step is! )))

If we are talking about the opening prices of "extreme" orders and you want to place new orders relative to the opening prices of these orders, then the principle is the same, when recalculating orders look for the maximum/minimum opening prices by order type, roughly so:

int NumberOfOrders(int magic_,double &openpricemaxbuy_,double &openpriceminsell_)
  {
   int i,ot,buy_=0,sell_=0,k=OrdersTotal();
   openpricemaxbuy_=0.0; openpriceminsell_=0.0;
   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         ot=OrderType();
         if((OrderMagicNumber()==magic_) && (OrderSymbol()==_Symbol))
           {
            if(ot==OP_BUY) { buy_++;  openpricemaxbuy_  = fmax(openpricemaxbuy_,OrderOpenPrice());  }
            if(ot==OP_SELL){ sell_++; openpriceminsell_ = fmin(openpriceminsell_,OrderOpenPrice()); }
           }
        }
     }
   return(buy_+sell_);
  }



ZZY: if we are talking about closed orders, the code will be different, and the principle of enumeration of orders is slightly different - look for an order with the maximum closing time and remember its parameters

 

Hi all. Can you tell me why the Print function does not work in the indicator.

//+------------------------------------------------------------------+
//|                                                        test3.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
       Print("Hello");
       Print("---- First indicator -----");

   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Alexander Mikryukov:

Hi all. Can you tell me why the Print function does not work in the indicator.

there is no reason for it not to work, see the experts' logbook for your messages

 
Igor Makanu:

there's no reason not to work, look in the experts' logbook for your messages

Yeah, stupid. Thank you.

 
Good night! Can you tell me if it is possible to manage several accounts with one script? Thank you!
 
Maxim Voronin:
Good night! Can you tell me if it is possible to manage several accounts with one script? Thank you!

You can, but not with a script, with an advisor. The accounts have to be run in different terminals...

 
Vladimir Pastushak:

You can, but not with a script, with an advisor. The accounts must be run in different terminals...

Continue if you don't mind
 
Maxim Voronin:
Continue if you don't mind

You write an EA that can communicate with other terminals, copiers are an example for you.

It's simple, one EA transmits something and receives it in another terminal...

 

INIT_PARAMETERS_INCORRECT

Designed to indicate an incorrect set of input parameters to the programmer, the result string with this return code will be highlighted in red in the general optimization table.

Testing will not be performed for this set of parameters of the Expert Advisor.



Something is not highlighted in red.

Is it so for everyone?


this is the code in OnInit:
int OnInit()
{

if (Koef2<=Koef) return(INIT_PARAMETERS_INCORRECT); 

return(INIT_SUCCEEDED);


And in the log it writes errors like this:



Reason: