라이브러리: 전문가 - 페이지 3

 
라이브러리의 다른 응용 프로그램의 예

트레이딩, 자동매매 시스템 및 트레이딩 전략 테스트 포럼

ParameterGetRange()

fxsaber, 2018.11.16 09:17

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

#define  TOSTRING(A) (" " + #A + " = " + (string)(A))

// 최적화를 위해 입력 매개변수 범위에 대한 데이터를 수집합니다.
string OptimizationData( void )
{
  string Str = NULL;
  MqlParam Params[];
  string Names[];
  
  if (EXPERT::Parameters(0, Params, Names))
  {
    const int Size = ArraySize(Names);
    bool Enable;
    long Value, Start, Step, Stop;
    long Total = 1;
    
    Str = Params[0].string_value;
    
    for (int i = 0; i < Size; i++)
      if (ParameterGetRange(Names[i], Enable, Value, Start, Step, Stop))
      {
        const long Interval = Stop - Start + 1;
        const long Amount =  Enable ? Interval / Step + ((bool)(Interval % Step) ? 1 : 0) : 1;
        
        Str += "\n" + Names[i] + " = " + (string)Value + (Enable ? TOSTRING(Start) + TOSTRING(Step) + TOSTRING(Stop) + TOSTRING(Amount) : NULL);
        
        Total *= Amount;
      }
      
    Str += "\n" + TOSTRING(Total);
  }
  
  return(Str);
}

input int Range1 = 5;
input int Range2 = 5;
input int Range3 = 5;

void OnTesterInit()
{
  ParameterSetRange("Range1", true, 5, 1, 2, 3);
  
  Print(__FUNCTION__ + "\n" + OptimizationData());
}

void OnTesterDeinit()
{
  Print(__FUNCTION__ + "\n" + OptimizationData());
  
  ChartClose();
}

int OnInit()
{
  return(INIT_FAILED);
}


OnTesterInit
Experts\fxsaber\Test3.ex5
Range1 = 5 Start = 5 Step = 1 Stop = 50 Amount = 46
Range2 = 5 Start = 23 Step = 1 Stop = 78 Amount = 56
Range3 = 5 Start = 26 Step = 5 Stop = 83 Amount = 12
 Total = 30912

OnTesterDeinit
Experts\fxsaber\Test3.ex5
Range1 = 5 Start = 1 Step = 2 Stop = 3 Amount = 2
Range2 = 5 Start = 23 Step = 1 Stop = 78 Amount = 56
Range3 = 5 Start = 26 Step = 5 Stop = 83 Amount = 12
 Total = 1344
 
버그 수정.
 
버그 수정. 마지막 버전.
 

다른 이름의 Expert Advisor에 연결하여 .ex4 형식의 Expert Advisor를 실행하려면 어떻게해야하며 입력 매개 변수가 표시되어야합니다. 즉, 완전히 작업 할 수있었습니다.

"Trade.ex4"라는 이름의 컴파일된 Expert Advisor가 있습니다.

"Hand.ex4"라는 이름의 새 Expert Advisor를 만듭니다.

"Hand.ex4"가 실행될 때 "Trade.ex4"가 완전히 작동하고 "Trade.ex4"가 "Hand.ex4"에 포함되도록 결합하는 방법.

즉, 컴퓨터에는 Hand.ex4 파일만 있지만 업무에서는 Trade.ex4를 사용하는 것입니다.

감사합니다!

 
Vitaly Muzichenko:

.ex4 형식의 Expert Advisor를 실행하려면 어떻게 해야 하나요?

현재 형식의 라이브러리는 EX5에서만 작동합니다.

 
Sergey Eremin:

저는 특정 프로젝트의 일부로 이런 식으로 해결했습니다 ("이름"태그와 같은 방식으로):

고마워요, 그렇게 작동합니다!

다른 차트에서 동일한 EA가 동일한 파일을 놓고 싸우지 않도록 저장된 템플릿의 이름에 chartId를 추가했을 뿐입니다.


코드에 "#ifndef __MQL5__"가 있는데, 크로스 플랫폼을 논리적 결론으로 가져가면 어떨까요?

Is가 작동하도록 하려면 코드의 시작 부분에 추가합니다:

#property strict

#ifdef __MQL4__
        class SubstringParser
        {
           private:
              string m_text;
              string m_subStart;
              string m_subEnd;
           
           public:
              SubstringParser(const string text, const string subStart, const string subEnd)
              {
                 m_text = text;
                 m_subStart = subStart;
                 m_subEnd = subEnd;
              }
              
              string Get()
              {
                 int startPhraseLengt = StringLen(m_subStart);
                 int startPos = StringFind(m_text, m_subStart) + startPhraseLengt;
                 int endPos = StringFind(m_text, m_subEnd, startPos);
                         
                 if(startPos >= startPhraseLengt && endPos > startPos)
                 {
                    return StringSubstr(m_text, startPos, endPos - startPos);      
                 }
                 else
                 {
                    return "";
                 }
              }
        };

   string GetChartEAName(const long chartId)
   {
      if(!SaveTemplate(chartId))
      {
         return "";
      }
      
      string result = "";
      
      int handle = FileOpen("ea_name_checking_" + (string)chartId + ".tpl",FILE_TXT|FILE_READ);
      if(handle == INVALID_HANDLE)
      {
         Print
         (
            "Error in ", __FILE__,", line ", __LINE__,
            ": can't open template file 'ea_name_checking_" + (string)chartId + ".tpl', error code = ", GetLastError()
         );
      }
      else
      {
         string text = "";
         
         while(!FileIsEnding(handle)) 
         { 
            text = text + FileReadString(handle, (uint)FileSize(handle)) +"\r\n";
         }
         
         SubstringParser eaSectionTextParser(text, "<expert>", "</expert>");            
         string eaSectionText = eaSectionTextParser.Get();
         
         if(StringTrimLeft(StringTrimRight(eaSectionText)) != "")
         {
            SubstringParser eaNameParser(eaSectionText, "name=","\r\n");
            string eaName = StringTrimLeft(StringTrimRight(eaNameParser.Get()));
            
            if(eaName != "")               
            {
               result = eaName;
            }
         }            
      }
      
      FileClose(handle);
      FileDelete("ea_name_checking_" + (string)chartId + ".tpl");
      
      return result;
   }
   
   bool SaveTemplate(const long chartId)
   {
      ResetLastError();
      
      if(!ChartSaveTemplate(chartId, "\\Files\\ea_name_checking_" + (string)chartId + ".tpl"))
      {            
         Print
         (
            "Error in ", __FILE__,", line ", __LINE__,
            ": can't save template to the file 'ea_name_checking_" + (string)chartId + ".tpl', error code = ", GetLastError()
         );
         
         return false;
      }
      
      return true;
   }      
 #endif

그리고 함수 자체를 수정합니다:

  static bool Is( const long Chart_ID = 0 )
  {
                #ifdef __MQL4__
                        string chartEAName = GetChartEAName(Chart_ID);
                #endif 
                
                #ifdef __MQL5__     
                        string chartEAName = ChartGetString(Chart_ID, CHART_EXPERT_NAME);
                #endif
                return(chartEAName != NULL);
  }


다른 어려움은 없나요?

 
Andrey Khatimlianskii:

다른 어려움은 없나요?

하나의 인디케이터만 실행 중인 차트.


ZY 작동 방식은 다음과 같습니다.

SubstringParser eaSectionTextParser(text, "\r\n\r\n<expert>", "</expert>");
 

이제 라이브러리의 모든 기능이 MT4에서 작동합니다.

라이브러리가 크로스 플랫폼이 되었습니다.

 
이제 모든 라이브러리 기능이 MT4에서 작동합니다.
라이브러리가 크로스 플랫폼이 되었습니다.


MT4 예시:

트레이딩, 차트 분석 및 차트 시각화 기능 추가

Библиотеки: 전문가

fxsaber, 2019.04.09 13:19

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

void OnStart()
{
  MqlParam Params[2];

  // Путь к советнику
  Params[0].string_value = "Moving Average";
  
  // 고객 지원 페이지 바로가기
  Params[1].type = TYPE_DOUBLE;
  Params[1].double_value = 0.5;  

  Print(EXPERT::Run(ChartOpen(_Symbol, _Period), Params));
}
 
Vitaly Muzichenko:

.ex4에서 EA를 실행하는 가장 좋은 방법은 무엇인가요?

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

void OnStart()
{
  MqlParam Params[2];

  // 상담사 연결 경로
  Params[0].string_value = "Moving Average";
  
  // 전문가 어드바이저의 첫 번째 입력 파라미터입니다.
  Params[1].type = TYPE_DOUBLE;
  Params[1].double_value = 0.5;  

  Print(EXPERT::Run(ChartOpen(_Symbol, _Period), Params));
}