Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1542

 
Artyom Trishkin #:
A person wanted to show in an example how to copy three bars. You can copy as many bars as you need. But for the Expert Advisor, as well as usually, it is enough to know the current volatility. It is only one zero, the current bar.

Good information. Thank you.

 

Can you tell me if this is the correct way to normalise to 5 decimal places?

//+------------------------------------------------------------------+
//|                                          Export Indicator Values |
//+------------------------------------------------------------------+
#property description "This Script Export Indicators Values to CSV File."
#property description "(You can change the iCustom function parameters to change what indicator to export)"
#property copyright "NFTrader"
#property version   "2.00"
#property script_show_inputs

input int    IndicatorPeriod=14;
input string Indicator_Directory_And_Name="Examples\\RSI";
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   MqlRates  rates_array[];
   string sSymbol=Symbol();

// Convert Period to string to use it in the file name
   string  sPeriod=EnumToString(Period());
// Comment to appear in the up left screen
   Comment("Exporting ... Please wait... ");

// Prepare file name, e.g: EURUSD_PERIOD_H1(RSI,14)
   string       ExtFileName; // ="XXXXXX_PERIOD_H1(RSI,14).CSV";
   ExtFileName=sSymbol;
   int pos=StringFind(Indicator_Directory_And_Name,"\\",0);
   string indicatorName=StringSubstr(Indicator_Directory_And_Name,pos+1,-1);
   string indicatorPeriod=IntegerToString(IndicatorPeriod);
   StringConcatenate(ExtFileName,sSymbol,"_",sPeriod,"(",indicatorName,",",indicatorPeriod,")",".CSV");

   ArraySetAsSeries(rates_array,true);
   int MaxBar=TerminalInfoInteger(TERMINAL_MAXBARS);
   int iCurrent=CopyRates(sSymbol,Period(),0,MaxBar,rates_array);

   double IndicatorBuffer[];
   SetIndexBuffer(0,IndicatorBuffer,INDICATOR_DATA);

   int bars=Bars(sSymbol,PERIOD_CURRENT);
   int to_copy=bars;

   int rsiHandle=iCustom(sSymbol,PERIOD_CURRENT,Indicator_Directory_And_Name,IndicatorPeriod);       // Change here.

   CopyBuffer(rsiHandle,0,0,to_copy,IndicatorBuffer);
   ArraySetAsSeries(IndicatorBuffer,true);

   int fileHandle=FileOpen(ExtFileName,FILE_WRITE|FILE_CSV);

   for(int i=iCurrent-IndicatorPeriod-1; i>0; i--)
     {
      string outputData=StringFormat("%s",TimeToString(rates_array[i].time,TIME_DATE));
      outputData+=","+TimeToString(rates_array[i].time,TIME_MINUTES);
      outputData+=","+ DoubleToString(IndicatorBuffer[i],5);
      outputData+="\n";

      FileWriteString(fileHandle,outputData);
     }

   FileClose(fileHandle);
   Comment("Exported Successfully");
  }
//+------------------------------------------------------------------+

Here in this place

outputData+=","+ DoubleToString(IndicatorBuffer[i],5);
I just get discrepancies with the real data.
 
EgorKim #:

Is this the correct way to normalise to 5 decimal places ?

This is

where

I get discrepancies with the real data

.

And it is definitely necessary to do it this way? It is just not clear to me for what purpose you take away the period of the indicator:

for(int i=iCurrent-IndicatorPeriod-1; i>0; i--)

Regards, Vladimir.

 

HI there.

My EA isn't running on meta4 desktop even if i use the preinstalled  EA expert that they have. I have selected the auto trade, allowed trading when changing accounts, it has a smiley face and in the bottom at experts it shows all is good. So why isn't it opening trades?


Any Advise or Help??

 
MrBrooklin #:
Is it really necessary to do it this way? It is just not clear to me for what purpose you take away the period of the indicator:

I don't know how to do it myself)

Code from the codebase.

 

Hello.

What is the error when compiling ?

'operator[]' - constant variable cannot be passed as reference

how to fix ?

 
EgorKim #:

I don't know the right way myself)

Code from the codebase.

For the sake of interest, remove what I highlighted in yellow and see the result. It will be interesting to see what you get. ))

Regards, Vladimir.

 
MrBrooklin #:
For the sake of interest, remove what I highlighted in yellow and see the result. It will be interesting to see what you get. ))

There are no differences.

The data is the same

 
MrBrooklin #:
For the sake of interest, remove what I highlighted in yellow and see the result. It will be interesting to see what you get. ))

In your variant, the export of indicator values is 1 bar earlier.

Otherwise, there are no differences.

I don't know why the author did it.

But I have a problem with normalisation of exported data to 5 digits

 
Roman Kutemov #:

Hello.

What is the compilation error ?

'operator[]' - constant variable cannot be passed as reference

how to fix ?

Maybe you should explicitly specify the wordconst?

Regards, Vladimir.