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

 
YarTrade: VolC - that's what I called the file. Don't you need a file name?

Then it goes like this:

   string file_name="VolC_"+Symbol()+(string)Period();
   int file_handle=FileOpen(file_name,FILE_WRITE|FILE_TXT);
   FileWrite(file_handle,(double)V5);       // V5 - это что?
   FileClose(file_handle);
 
STARIJ:

Then it goes like this:


V5 is some kind of calculation result. I removed V5, put an array in its place and want it to be written to the file. The file is created, but only one value is written to it, not the indicator data array. What is missing? I have an indicator that is correctly plotted on the chart. I want to write its values into a file to be able to read them later. But only one number is written. Can you help me to understand what is wrong?

 
STARIJ:

Then it goes like this:


I did it with FileWriteArray, but now the file is empty. it won't write an array there :(. Do you know how to help? Sure you do. Please tell me what's wrong.

 
YarTrade: I did it with FileWriteArray, but now the file is empty. It won't write the array there :(. Do you know how to help? Sure you do. Please tell me what's wrong.

It goes like this

   int V5=555;
   string file_name="VolC_"+Symbol()+(string)Period();
   int file_handle=FileOpen(file_name,FILE_WRITE|FILE_TXT);
   FileWrite(file_handle,V5);
   FileClose(file_handle);

What type of array? Insert the code, stop being greedy! And here's an array writing apparently only a character array.

   string V5[5]={"Жили","были","дед","и","баба"};
   string file_name="VolC_"+Symbol()+(string)Period();
   int file_handle=FileOpen(file_name,FILE_WRITE|FILE_TXT);
   FileWriteArray(file_handle,V5);
   FileClose(file_handle);

And the array double in the loop writes

   double V5[5]={3.333,7.7777777,1.1,2.22,9.999999999};
   string file_name="VolC_"+Symbol()+(string)Period();
   int file_handle=FileOpen(file_name,FILE_WRITE|FILE_TXT);
   for(int n=0; n<5; n++)FileWrite(file_handle,V5[n]);
   FileClose(file_handle);
 
STARIJ:

It goes like this

What type of array? Insert the code, stop being greedy! And this array writes apparently only a character array

And here's the array double in the loop writing


How greedy is that? :)

#property copyright "ZyZy"
#property link      "https://www.mql5.com/ru/users/alexeyvik/news"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
// #property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellow
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_separate_window
//--- input parameters
input int      Aver=15;
datetime Время=0;   // Время прошлого бара
double Bid1;
long V1; // объем для текущего тика вверх
long V2; // накопленный объем для всех тиков вверх текущего бара
long V3; // накопленный объем для всех тиков вниз для текущего бара
long V4; // объем текущего тика вниз
long V5;

//--- indicator buffers
double         Buf_1[];   // буфер для значений идикатора
double         Counter[];     // буфер для расчетов   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IndicatorBuffers(2);
   SetIndexBuffer(0,Buf_1,INDICATOR_DATA); // создаю буфер для значений индикатора
   SetIndexBuffer(1,Counter,INDICATOR_CALCULATIONS);
   SetIndexEmptyValue(0,0.0);
//---
   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[])
  {
//---
//int limit = prev_calculated > 0 ? rates_total-prev_calculated : rates_total-1;
//for(int i =  limit; i >= 0; i--)
// {
//  Counter[i] = close[i];
//  Indicator[i] = iMAOnArray(Counter, 0, 5, 0, 0, i);
// }
   if(prev_calculated==0)
     {
      ArrayInitialize(Counter,0.0);
      ArrayInitialize(Buf_1,0.0);
     }
   datetime Вр=Time[0];   // Время текущего бара
   if(Вр>Время)           // Если новый бар
     {
      Время=Вр;           // Запомнить
      Counter[0]=0;         // и обнулить последний элемент буфера
      V2 = 0;
      V4 = 0;
     }

   if(Bid>=Bid1)
     {
      if(Bid>Bid1)
        {
         V1 = iVolume(NULL, 0, 0);
         V2 = V1 + V2;
        }
      else
        {
         V1 = 0;
         V2 = V1 + V2;
        }
     }
   else
     {
      V3 = iVolume(NULL, 0, 0);
      V4 = V3 + V4;
     }

   V5=V2-V4;
   Bid1=Bid;
   Counter[0]=(double)V5;
   Buf_1[0]=iMAOnArray(Counter,0,Aver,0,MODE_SMA,0);
   Comment("Counter ",Counter[0],"\n"
           ,"Buf_1 ",Buf_1[0]);
   
   string file_name="VolC_"+Symbol()+(string)Period();
   int file_handle=FileOpen(file_name,FILE_WRITE|FILE_TXT);
   FileWriteArray(file_handle,Counter, 0, WHOLE_ARRAY);     
   FileClose(file_handle);

   return(rates_total);
  }
//+------------------------------------------------------------------+
 
YarTrade: What greed is involved? :)

Why would you print anything from an indicator? Everything is on the screen - that's what an indicator is. When I need a table - I run a script with iCustom()

 

Hello, I've been struggling with the code that is supposed to check the price of the order in the terminal. I decided to try checking against the tickets. Put the tickets into an array, started checking.

All is good, it returns TRUE. I think, I will delete one, it will return FALSE. But no((( I deleted all, and script still returns 1 instead of 0. What I do wrong?


int start()
{
   while(!IsStopped())
   {
      int ordsel = 0;
      double ticord[3] = {8895969,8901032,8901033};
         for(ordsel=0; ordsel<=2;ordsel++) 
         {
            Sleep(5000); 
            Alert(OrderSelect(ticord[ordsel],SELECT_BY_TICKET,MODE_TRADES)); 
         }
      if(!IsExpertEnabled()) break;
   }
   return;
}
 

Hello, fellow experts! Please help a beginner. I'm trying to put an indicator into my Expert Advisor(I've racked my brains ...)! Gives out an error: 'limit' - declaration without type.

In this line: limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName, "returnBars",0,0)*timeFrame/Period());


 
Dimitry-1983:

Hello, I've been struggling with the code that's supposed to check the order price in the terminal. I decided to try checking against the tickets. Put the tickets into an array, started checking.

All is good, it returns TRUE. I think, I will delete one, it will return FALSE. But no((( I deleted all, and script still returns 1 instead of 0. What I do wrong?



The thing is that if you select (OrderSelect(...)) by ticket, parameter 3 is ignoredMODE_TRADES

so, to find out from which list (closed, open) you have chosen the order, you need to check its close time

0- open and pending, >0 closed

 
Ptichka12:

Hello, fellow experts! Please help a beginner. I'm trying to put an indicator into an Expert Advisor (I've racked my brains ...)! Gives out an error: 'limit' - declaration without type.

In this line: limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName, "returnBars",0,0)*timeFrame/Period()));



This is quite an interesting way of doing it.

Try the following on the error

int limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));