Download MetaTrader 5

How to programmatically get list of input parameters

To add comments, please log in or register
Marc Dixon
32
Marc Dixon  

Hi there,

I was wondering if it was possible to get a list of input parameters given to an EA or Indicator?

Right now I'm logging my EA's settings to a new file automatically whenever it detects that I'm using different settings so that I can look back and see what I was using in the past.  However, this relies on me hard coding the input variables into a function which was ok at first but sometimes I forget to update the function when I add a new input and then of course it's settings aren't logged to the file.

Thanks

Osama Shaban
1686
Osama Shaban  

I'm using a simple code like ...

input bool ShowInfoOnChart = true;

Then, use Comment( ) to display all settings on chart.

This way you cans switch On and Off the setting show on the chart the easy way.

Blahtech Limited
6186
James Cater  
Marc Dixon:

Hi there,

I was wondering if it was possible to get a list of input parameters given to an EA or Indicator?

Right now I'm logging my EA's settings to a new file automatically whenever it detects that I'm using different settings so that I can look back and see what I was using in the past.  However, this relies on me hard coding the input variables into a function which was ok at first but sometimes I forget to update the function when I add a new input and then of course it's settings aren't logged to the file.

Thanks

Sadly there are no built in methods to programmatically load/save the input variables. You must manage them yourself.
Marc Dixon
32
Marc Dixon  

That's unfortunate.


Thanks for your help.

fxsaber
8953
fxsaber  

Use ChartSaveTemplate + parsing of new tpl-file.

Example for buffer's color

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Как в индикаторе узнать текущий цвет индикаторной линии?

fxsaber, 2017.05.12 13:45

#property strict

#property indicator_chart_window
#property indicator_buffers 2

#define PATH "MQL4\\indicators\\"

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

string GetIndicatorName( void )
{
  const string StrName = ::MQLInfoString(MQL_PROGRAM_PATH);
  const int Pos = ::StringFind(StrName, PATH) + ::StringLen(PATH);
  
  return(::StringSubstr(StrName, Pos, ::StringLen(StrName) - Pos - 4));
}

void SeekToString( const int handle, const string Str )
{
  while (!::FileIsEnding(handle))
    if (::FileReadString(handle) == Str)
      break;
  
  return;
}  

struct BUFFER_STRUCT
{
  int Shift;
  int Type;
  color Color;
  ENUM_LINE_STYLE Style;
  int Width;
};

const BUFFER_STRUCT GetBufferProperties( const uint Num = 0, const bool FlagSave = true )
{
  BUFFER_STRUCT Res = {0};
  
  const string FileName = ::WindowExpertName() + ".tpl";

  if (FlagSave ? ::ChartSaveTemplate(0, "..\\MQL4\\Files\\" + FileName) : true)
  {
    const int handle = ::FileOpen(FileName, ::FILE_READ|::FILE_CSV);

    if (handle > 0)
    {
      ::SeekToString(handle, "name=" + ::GetIndicatorName());
      
      if (Num == 0)
        ::SeekToString(handle, "</expert>");
      else
      {
        const string TmpStr = "weight_" + (string)(Num - 1);
        
        while (!::FileIsEnding(handle))
          if (::StringFind(::FileReadString(handle), TmpStr) == 0)
            break;
      }
            
      if (!::FileIsEnding(handle))
      {
        static const string Property[] = {"shift", "draw", "color", "style", "weight"};
        const string StrNum = "_" + (string)Num + "=";
              
        for (int i = 0; i < ::ArraySize(Property); i++)
          _W(Res)[i * sizeof(int)] = (int)::StringToInteger(::StringSubstr(::FileReadString(handle), ::StringLen(Property[i] + StrNum)));
      }
      
      ::FileClose(handle);
    }
  }
  
  return(Res);
}  

void OnInit()
{  
  string Str = "Colors:";
  
  for (int i = 0; i < indicator_buffers; i++)
    Str += " " + (string)i + "-" + (string)::GetBufferProperties(i).Color;
    
  Alert(Str);
}

void start()
{
}
fxsaber
8953
fxsaber  
Marc Dixon:

I was wondering if it was possible to get a list of input parameters given to an EA or Indicator?

#include <fxsaber\Expert.mqh> // https://www.mql5.com/ru/code/19003

void OnStart()
{
  MqlParam Parameters[];
  string Names[];

  if (EXPERT::Parameters(0, Parameters, Names))
    ArrayPrint(Names);
}
Stanislav Korotky
22447
Stanislav Korotky  
fxsaber:

This is MT4 section. The library supports MT5 only.

fxsaber
8953
fxsaber  
Stanislav Korotky:

This is MT4 section. The library supports MT5 only.

It was an example. The library can be made to work in MT4 by adding a few lines. TPL-format is the same in MT4/5.

To add comments, please log in or register