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

 
Artyom Trishkin:
Print() in visual mode

Great! Thank you! It all worked out. Checked all the variables at once.

 
Roni Iron:

Good afternoon!

What are the options to get data of this type:

Time (UTC),Ask,Bid,AskVolume,BidVolume

Ask,Bid - it is enough to specify. You don't have to get too complicated, and there is only 1 Volume in Forex.

iVolume

Returns the value of the tick volume of the bar (specified by the shift parameter) of the corresponding chart.

long  iVolume( 
   string           symbol,          // символ 
   int              timeframe,       // период 
   int              shift            // сдвиг 
   );
 
Hello, could you please advise me, when I install a custom indicator in MQL4, everything works, but when I switch to another timeframe only deinit (from previous timeframe) works, and init does not work on a new one, i.e. the program does not restart, it just removes from the window. When I manually set the indicator to the new timeframe all goes well. What may be the problem?
 

This is exactly the trick - forex has a tick volume of a bar, but there is no tick trade volume. But the sources of tick quotes (Ducascopy, etc.) giveAskVolume,BidVolume valuesafter price values in the form 0.32,0.12 (and it is not clear whether it is 2 digits with commas or 4.

Thank you!

 
Is there any trick to create a CSV file without separators?
 

Hello.

Please advise, I have rewritten my code for MQL5, which was written for MQL4.

I've got two EMAs, one for one.

I've gotno errors when compiling it, but it doesn't show the same results as in MQL4.

I've looked through the MQL5 manual, but I don't understand anything.

//+------------------------------------------------------------------+
//|                                                           MA.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot 1
#property indicator_label1  "MA 1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLime
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot 2
#property indicator_label2  "MA 2"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//
input int PER=8; //Period
//
double         MA_1[];
double         MA_2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,MA_1,INDICATOR_DATA);
      SetIndexBuffer(1,MA_2,INDICATOR_DATA);
         IndicatorSetInteger(INDICATOR_DIGITS,2);
//---
   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[])
  {
   program(rates_total,prev_calculated,close);
   return(rates_total);
  }
//+------------------------------------------------------------------+
//+---EMA

double EMA(double N,double P,double EMA0=0)//формула
  {
   double  A=2/(N+1);                      //расчета
   return(A*P+(1-A)*EMA0);                 //ЕМА
  }
//+---
void program(int rates_total,int prev_calculated,const double &close[])
  {

   int Y=rates_total-prev_calculated;
   if(prev_calculated==0) Y=Y-PER-1;

   for(Y=Y; Y>=0; Y=Y-1)

     {
     
      MA_1[Y]=EMA(PER,close[Y],MA_1[Y+1]);//первая
      MA_2[Y]=EMA(PER,MA_1[Y],MA_2[Y+1]);//на неё вторая

     }
   return;
  }
//+------------------------------------------------------------------+
 
imknk:

Hello.

Please advise, I have rewritten my code for MQL5, which was written for MQL4.

I've got two EMAs, one for one.

I've gotno errors when compiling it, but it doesn't show the same results as in MQL4.

I've already broken my eyes in theMQL5 manual, I don't understand anything.

In mql5, buffers have to be flipped, as they go backwards.

Add a construction and read about it

ArraySetAsSeries(MA_1,true);
Документация по MQL5: Пользовательские индикаторы / SetIndexBuffer
Документация по MQL5: Пользовательские индикаторы / SetIndexBuffer
  • www.mql5.com
[in]  Тип данных, хранящихся в индикаторном массиве. По умолчанию INDICATOR_DATA (значения рассчитанного индикатора). Может также принимать значение INDICATOR_COLOR_INDEX, тогда данный буфер предназначен для хранения индексов цветов для предыдущего индикаторного буфера. Можно задать до 64 цветов в строке #property indicator_colorN. Значение...
 
Vitaly Muzichenko:

In mql5 you have to flip the buffers, they go backwards.

Add a construction and read about it

Thank you, I will try it now.
 

Please help, where is the error?

Why when an if condition is passed to a function, it swears " 'all_clouse' - function not defined"

if(buy>=position)
 {
   All_clouse();  // 'All_clouse' - wrong parameters count

 }
..............
дальше код
..............
Уже за пределами OnTick
void All_clouse(int a,double x, double y)
  {
.............
   } к самой функции закрытия ордеров у него претензий нет.
 
Gilmor:

Please help, where is the error?

Why is it that in an if condition with a jump to a function it says " 'all_clouse' - function not defined"?

Because you have to feed parameters into the function and you are calling it empty All_clouse()

void All_clouse(int a,double x, double y)
Reason: