MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 564

 
Ihor Herasko :

위의 코드에서 shift 및 iy 변수의 값은 out-of- bounds array 에 대해 검사되지 않습니다. 따라서 모든 것이 논리적입니다. 사용하기 전에 값을 확인하면 오류가 사라집니다.

글쎄요, 자세히 말씀드리면 CountBars와 TimeFrame 변수의 값이 어떻게 형성되는지 알아야 합니다.

CountBars = 400 및 TimeFrame = 30은 외부에서 정적으로 설정됩니다.

M30에서는 모든 것이 정상이고 M15에서는 충돌합니다.

범위 벗어난 시프트 및 iy를 확인하는 방법은 무엇입니까?

   if (TimeFrame> Period ()) 
     {
       ArrayCopySeries (santa1, 5 , Symbol (),TimeFrame);
      summ=CountBars+TimeFrame/ Period ();
      shift= 0 ;
       for ( int iy= 0 ; shift<summ; shift++) 
        {
         if (iy> ArraySize (santa1)) continue ;
         if (shift> ArraySize (santa1)) continue ;
         if ( Time [shift]<santa1[iy]) iy++; //вот эта santa1[iy] "array out of range"

         list[shift]=bufbuy[iy];
        }
     }
 

아마도 누군가는 오류가 있는 곳을 찾을 시간을 찾을 것입니다.

 #property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Aqua

extern bool Crash= FALSE ;
extern int TimeFrame= 30 ;
extern int Length = 7 ;
extern int Method = 3 ;
extern int Smoothing= 2 ;
extern int Filter= 2 ;
extern bool RealTime= TRUE ;
extern bool Steady= FALSE ;
extern bool Color = TRUE ;
extern bool Alerts= TRUE ;

extern int CountBars= 400 ;
double sik[];
double list[];
double bufbuy[];
double par6[];
double par1[];
double par2[];
double par3[];
double nugni[];
bool flag2 = TRUE ;
bool flag1 = TRUE ;
datetime time1 = 0 ;
datetime time2 = 0 ;
int stad= 0 ;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   string lex;
   IndicatorBuffers ( 8 );
   SetIndexStyle ( 0 , DRAW_LINE , STYLE_SOLID );
   SetIndexBuffer ( 0 ,list);
   SetIndexStyle ( 1 , DRAW_LINE , STYLE_SOLID );
   SetIndexBuffer ( 1 ,par1);
   SetIndexStyle ( 2 , DRAW_LINE , STYLE_SOLID );
   SetIndexBuffer ( 2 ,par2);
   SetIndexStyle ( 3 , DRAW_ARROW );
   SetIndexArrow ( 3 , 233 );
   SetIndexBuffer ( 3 ,par3);
   SetIndexStyle ( 4 , DRAW_ARROW );
   SetIndexArrow ( 4 , 234 );
   SetIndexBuffer ( 4 ,nugni);
   SetIndexBuffer ( 5 ,sik);
   SetIndexBuffer ( 6 ,par6);
   SetIndexBuffer ( 7 ,bufbuy);
   if (Length< 2 ) Length= 2 ;
   if (Method < MODE_SMA ) Method = 0 ;
   if (Method> MODE_LWMA ) Method = 3 ;
   if (Smoothing< 0 ) Smoothing= 0 ;
   if (Filter< 0 ) Filter= 0 ;
   if (TimeFrame< Period () && TimeFrame!= 0 ) TimeFrame= Period ();
   switch (TimeFrame) 
     {
       case 1 :
         lex= "M1" ;
         break ;
       case 5 :
         lex= "M5" ;
         break ;
       case 15 :
         lex= "M15" ;
         break ;
       case 30 :
         lex= "M30" ;
         break ;
       case 60 :
         lex= "H1" ;
         break ;
       case 240 :
         lex= "H4" ;
         break ;
       case 1440 :
         lex= "D1" ;
         break ;
       case 10080 :
         lex= "W1" ;
         break ;
       case 43200 :
         lex= "MN1" ;
         break ;
       default :
         lex= "" ;
     }
   string str_lol= "trend " +lex+ " |  " +Length+ " , " +Method+ " , " +Smoothing+ " , " +Filter+ "  | " ;
   IndicatorShortName (str_lol);
   return ( 0 );
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   int santa1[];
   int summ;
   string str_lol;
   if ( Bars < 100 ) 
     {
       IndicatorShortName ( "Bars less than 100" );
       return ( 0 );
     }
   if (time1< iTime ( NULL ,TimeFrame, 0 )) 
     {
      flag1 = FALSE ;
      flag2 = FALSE ;
      time1= iTime ( NULL ,TimeFrame, 0 );
     }
   if (!RealTime) 
     {
       if (time2 == iTime ( NULL , TimeFrame, 0 )) return ( 0 );
      time2= iTime ( NULL ,TimeFrame, 0 );
      stad=TimeFrame/ Period ()+ 1 ;
       if (stad== 0 ) stad= 1 ;
     }
   double MA1 = 0 ;
   double MA2 = 0 ;
   double MA3 = 0 ;
   double MA4 = 0 ;
   double MA5 = 0 ;
   if (CountBars> iBars ( NULL ,TimeFrame) || CountBars> Bars -Length- 1 ) CountBars= MathMin ( Bars -Length- 1 , iBars ( NULL ,TimeFrame)-Length- 1 );
   if (Crash && CountBars> 0 ) 
     {
      CountBars-= 10 ;
       IndicatorShortName ( "Crash: " +CountBars+ "     " );
     }
   if (Crash && CountBars< 0 ) IndicatorShortName ( "Crash" );
   int shift=CountBars;
   list[shift+ 1 ]= Close [shift+ 1 ];
   bufbuy[shift+ 1 ]= Close [shift+ 1 ];
   while (shift>= 0 ) 
     {
      MA1 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_HIGH , shift);
      MA2 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_LOW , shift);
      MA3 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_OPEN , shift);
      MA4 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_CLOSE , shift);
      MA5 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_CLOSE , shift + Smoothing);
       if (Steady== TRUE ) 
        {
         MA4 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_MEDIAN , shift);
         MA5 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_MEDIAN , shift + Smoothing);
        }
      sik[shift]= MathAbs (((MA4-MA5)/ MathMax (MA1-MA2, MathMax (MA1-MA5,MA5-MA2))+(MA4-MA3)/(MA1-MA2))/ 2.0 ) *((MA4-MA5+
                         (MA4-MA3))/ 2.0 );
      list[shift]=list[shift+ 1 ]+sik[shift];
       if (Filter> 0 )
         if ( MathAbs (list[shift]-(list[shift+ 1 ]))<Filter* Point ) list[shift]=list[shift+ 1 ];
       if (TimeFrame> Period ()) bufbuy[shift]=list[shift];
      shift--;
     }
   if (TimeFrame> Period ()) 
     {
       ArrayCopySeries (santa1, 5 , Symbol (),TimeFrame);
      summ=CountBars+TimeFrame/ Period ();
      shift= 0 ;
       for ( int iy= 0 ; shift<summ; shift++) 
        {
         if (iy> ArraySize (santa1)) continue ;
         if (shift> ArraySize (santa1)) continue ;
         if ( Time [shift]<santa1[iy]) iy++; //вот эта 
         list[shift]=bufbuy[iy];
        }
     }
   for (shift=CountBars; shift>= 0 ; shift--) 
     {
      par6[shift]=par6[shift+ 1 ];
       if (list[shift] -(list[shift + 1 ])> 0.0 ) par6[shift] = 1 ;
       if (list[shift + 1 ] - list[shift] > 0.0 ) par6[shift] = - 1 ;
       if (Color== TRUE ) 
        {
         if (par6[shift]> 0.0 ) 
           {
            par1[shift]=list[shift];
             if (par6[shift+ 1 ]< 0.0 ) par1[shift+ 1 ]=list[shift+ 1 ];
            par2[shift]= EMPTY_VALUE ;
              } else {
             if (par6[shift]< 0.0 ) 
              {
               par2[shift]=list[shift];
               if (par6[shift+ 1 ]> 0.0 ) par2[shift+ 1 ]=list[shift+ 1 ];
               par1[shift]= EMPTY_VALUE ;
              }
           }
        }
       if (Alerts== TRUE ) 
        {
         par3[shift] = EMPTY_VALUE ;
         nugni[shift] = EMPTY_VALUE ;
         if (par6[shift] == 1.0 && par6[shift + 1 ] == - 1.0 ) par3[shift] = list[shift + 1 ] - ( Ask - Bid );
         if (par6[shift] == - 1.0 && par6[shift + 1 ] == 1.0 ) nugni[shift] = list[shift + 1 ] + ( Ask - Bid );
        }
     }

   return ( 0 );
  }
//+------------------------------------------------------------------+
 
PolarSeaman :

아마도 누군가는 오류가 있는 곳을 찾을 시간을 찾을 것입니다.

 #property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Aqua

extern bool Crash= FALSE ;
extern int TimeFrame= 30 ;
extern int Length = 7 ;
extern int Method = 3 ;
extern int Smoothing= 2 ;
extern int Filter= 2 ;
extern bool RealTime= TRUE ;
extern bool Steady= FALSE ;
extern bool Color = TRUE ;
extern bool Alerts= TRUE ;

extern int CountBars= 400 ;
double sik[];
double list[];
double bufbuy[];
double par6[];
double par1[];
double par2[];
double par3[];
double nugni[];
bool flag2 = TRUE ;
bool flag1 = TRUE ;
datetime time1 = 0 ;
datetime time2 = 0 ;
int stad= 0 ;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   string lex;
   IndicatorBuffers ( 8 );
   SetIndexStyle ( 0 , DRAW_LINE , STYLE_SOLID );
   SetIndexBuffer ( 0 ,list);
   SetIndexStyle ( 1 , DRAW_LINE , STYLE_SOLID );
   SetIndexBuffer ( 1 ,par1);
   SetIndexStyle ( 2 , DRAW_LINE , STYLE_SOLID );
   SetIndexBuffer ( 2 ,par2);
   SetIndexStyle ( 3 , DRAW_ARROW );
   SetIndexArrow ( 3 , 233 );
   SetIndexBuffer ( 3 ,par3);
   SetIndexStyle ( 4 , DRAW_ARROW );
   SetIndexArrow ( 4 , 234 );
   SetIndexBuffer ( 4 ,nugni);
   SetIndexBuffer ( 5 ,sik);
   SetIndexBuffer ( 6 ,par6);
   SetIndexBuffer ( 7 ,bufbuy);
   if (Length< 2 ) Length= 2 ;
   if (Method < MODE_SMA ) Method = 0 ;
   if (Method> MODE_LWMA ) Method = 3 ;
   if (Smoothing< 0 ) Smoothing= 0 ;
   if (Filter< 0 ) Filter= 0 ;
   if (TimeFrame< Period () && TimeFrame!= 0 ) TimeFrame= Period ();
   switch (TimeFrame) 
     {
       case 1 :
         lex= "M1" ;
         break ;
       case 5 :
         lex= "M5" ;
         break ;
       case 15 :
         lex= "M15" ;
         break ;
       case 30 :
         lex= "M30" ;
         break ;
       case 60 :
         lex= "H1" ;
         break ;
       case 240 :
         lex= "H4" ;
         break ;
       case 1440 :
         lex= "D1" ;
         break ;
       case 10080 :
         lex= "W1" ;
         break ;
       case 43200 :
         lex= "MN1" ;
         break ;
       default :
         lex= "" ;
     }
   string str_lol= "trend " +lex+ " |  " + string (Length)+ " , " + string (Method)+ " , " + string (Smoothing)+ " , " + string (Filter)+ "  | " ;
   IndicatorShortName (str_lol);
   return ( 0 );
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   int santa1[];
   int summ;
   string str_lol;
   if ( Bars < 100 ) 
     {
       IndicatorShortName ( "Bars less than 100" );
       return ( 0 );
     }
   if (time1< iTime ( NULL ,TimeFrame, 0 )) 
     {
      flag1 = FALSE ;
      flag2 = FALSE ;
      time1= iTime ( NULL ,TimeFrame, 0 );
     }
   if (!RealTime) 
     {
       if (time2 == iTime ( NULL , TimeFrame, 0 )) return ( 0 );
      time2= iTime ( NULL ,TimeFrame, 0 );
      stad=TimeFrame/ Period ()+ 1 ;
       if (stad== 0 ) stad= 1 ;
     }
   double MA1 = 0 ;
   double MA2 = 0 ;
   double MA3 = 0 ;
   double MA4 = 0 ;
   double MA5 = 0 ;
   if (CountBars> iBars ( NULL ,TimeFrame) || CountBars> Bars -Length- 1 ) CountBars= MathMin ( Bars -Length- 1 , iBars ( NULL ,TimeFrame)-Length- 1 );
   if (Crash && CountBars> 0 ) 
     {
      CountBars-= 10 ;
       IndicatorShortName ( "Crash: " + string (CountBars)+ "     " );
     }
   if (Crash && CountBars< 0 ) IndicatorShortName ( "Crash" );
   int shift=CountBars;
   list[shift+ 1 ]= Close [shift+ 1 ];
   bufbuy[shift+ 1 ]= Close [shift+ 1 ];
   while (shift>= 0 ) 
     {
      MA1 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_HIGH , shift);
      MA2 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_LOW , shift);
      MA3 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_OPEN , shift);
      MA4 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_CLOSE , shift);
      MA5 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_CLOSE , shift + Smoothing);
       if (Steady== TRUE ) 
        {
         MA4 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_MEDIAN , shift);
         MA5 = iMA ( NULL , TimeFrame, Length, 0 , Method, PRICE_MEDIAN , shift + Smoothing);
        }
      sik[shift]= MathAbs (((MA4-MA5)/ MathMax (MA1-MA2, MathMax (MA1-MA5,MA5-MA2))+(MA4-MA3)/(MA1-MA2))/ 2.0 ) *((MA4-MA5+
                         (MA4-MA3))/ 2.0 );
      list[shift]=list[shift+ 1 ]+sik[shift];
       if (Filter> 0 )
         if ( MathAbs (list[shift]-(list[shift+ 1 ]))<Filter* Point ) list[shift]=list[shift+ 1 ];
       if (TimeFrame> Period ()) bufbuy[shift]=list[shift];
      shift--;
     }
   if (TimeFrame> Period ()) 
     {
       ArrayCopySeries (santa1, 5 , Symbol (),TimeFrame);
      summ=CountBars+TimeFrame/ Period ();
      shift= 0 ;
       for ( int iy= 0 ; shift<summ; shift++) 
        {
         if (iy> ArraySize (santa1)) continue ;
         if (shift> ArraySize (santa1)) continue ;
         if ( Time [shift]<santa1[iy]) iy++; //вот эта 
         list[shift]=bufbuy[iy];
        }
     }
   for (shift=CountBars; shift>= 0 ; shift--) 
     {
      par6[shift]=par6[shift+ 1 ];
       if (list[shift] -(list[shift + 1 ])> 0.0 ) par6[shift] = 1 ;
       if (list[shift + 1 ] - list[shift] > 0.0 ) par6[shift] = - 1 ;
       if (Color== TRUE ) 
        {
         if (par6[shift]> 0.0 ) 
           {
            par1[shift]=list[shift];
             if (par6[shift+ 1 ]< 0.0 ) par1[shift+ 1 ]=list[shift+ 1 ];
            par2[shift]= EMPTY_VALUE ;
              } else {
             if (par6[shift]< 0.0 ) 
              {
               par2[shift]=list[shift];
               if (par6[shift+ 1 ]> 0.0 ) par2[shift+ 1 ]=list[shift+ 1 ];
               par1[shift]= EMPTY_VALUE ;
              }
           }
        }
       if (Alerts== TRUE ) 
        {
         par3[shift] = EMPTY_VALUE ;
         nugni[shift] = EMPTY_VALUE ;
         if (par6[shift] == 1.0 && par6[shift + 1 ] == - 1.0 ) par3[shift] = list[shift + 1 ] - ( Ask - Bid );
         if (par6[shift] == - 1.0 && par6[shift + 1 ] == 1.0 ) nugni[shift] = list[shift + 1 ] + ( Ask - Bid );
        }
     }

   return ( 0 );
  }
//+
 

얘들 아, 새 줄 에서 파일에 데이터를 추가하는 방법을 알려주세요

내 쓰기 기능:

 void Write( string file, string text, bool print)
  {
   filehandle= FileOpen (file, FILE_WRITE | FILE_CSV , '|' );
   FileWriteString (filehandle,text);
   FileClose (filehandle);
  }

내가 그녀에게 보내는 내용은 다음과 같습니다.

Write(subfolder+ "\\" + string (TF)+ "\\TS" + string (ts)+ "\\" + string (st)+ "_" + string (st2)+ ".txt" ,
                                 string (mv)+ "|" +
                                 string (b)+ "|" +
                                 string (rs)+ "|" +
                                 string (m1)+ "|" +
                                 string (m2)+ "|"
                                 ,NoPrint);

줄 아래에 많이 추가해야 합니다.

Write(subfolder+ "\\" + string (TF)+ "\\TS" + string (ts)+ "\\" + string (st)+ "_" + string (st2)+ ".txt" ,
                                 string (mv)+ "|" +
                                 string (b)+ "|" +
                                 string (rs)+ "|" +
                                 string (m1)+ "|" +
                                 string (m2)+ "|"
                                 ,NoPrint);
 
Nikolay Gaylis :

얘들 아, 새 줄 에서 파일에 데이터를 추가하는 방법을 알려주세요

내 쓰기 기능:

내가 그녀에게 보내는 내용은 다음과 같습니다.

줄 아래에 많이 추가해야 합니다.

SEEK_END 플래그가 있는 FileSeek()가 도움이 될 것입니다.

<
 
Nikolay Gaylis :

당신은 당신의 코드에서 대체했습니다

 //+------------------------------------------------------------------+

 //+

그러나 도움이되지 않았습니다)

 

여러분, Alparicent 고문이 로트 크기가 최대값을 초과하지 않지만 23-45에서 1-00으로 거래되는 [Invalid volume]이 종종 실패하는 이유를 알려주세요.

로그를 첨부했는데 다른 보커에는 그런 오류가 없습니다

파일:
Alpari_Logs.txt  35 kb
 

나는 here 의 예제에서 코드를 가져 와서 처리했습니다.

나는 방법을 정의했다

 bool CControlsDialog::OnEvent( const int id, const long &lparam, const double &dparam, const string &sparam){

         //....

}

그는 자신이 이미 정의되어 있고 몸이 있다는 사실에 맹세합니다.

질문: 어디에 정의되어 있습니까?

Документация по MQL5: Стандартная библиотека / Панели и диалоги / CButton
Документация по MQL5: Стандартная библиотека / Панели и диалоги / CButton
  • www.mql5.com
//|                                               ControlsButton.mq5 | //|                        Copyright 2017, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| defines                                                          |  INDENT_LEFT                         (11)      ...
 
Roman Sharanov :

나는 here 의 예제에서 코드를 가져 와서 처리했습니다.

나는 방법을 정의했다

그는 자신이 이미 정의되어 있고 몸이 있다는 사실에 맹세합니다.

질문: 어디에 정의되어 있습니까?

터미널 폴더 에서 검색해 보십시오. ControlsDialog.mqh 파일을 찾았고 여기에는 OnEvent()가 포함되어 있습니다.
 

좋은 저녁이에요!

나는 보증금의 %를 기반으로 거래의 로트를 계산하기 위해 범용(다양한 도구에 대해) 코드를 추가하는 방법에 대해 머리를 쓰고 있습니다.

다음과 같이 했습니다.

 input double MaximumRisk= 0.02 ;                   //Риск в сделке от депозита

{Lots = NormalizeDouble ((( AccountBalance ()*MaximumRisk)/(( MathAbs (Price-SL))/ Point )/(( MarketInfo ( Symbol (), MODE_LOTSIZE )*( MarketInfo ( Symbol (), MODE_ASK )+ Point ))
-( MarketInfo ( Symbol (), MODE_LOTSIZE )* MarketInfo ( Symbol (), MODE_ASK )))), Digits );}

가격( 포지션 시가 )과 SL(손절매)은 별도로 계산되며 여기에 추가하지 않았습니다.

견적 통화가 달러로 표시되는 쌍(예: EURUSD), SPX500 지수 및 금의 경우 - 모든 것이 올바르게 계산되지만 달러가 견적에서 첫 번째인 쌍(예: USDJPY)의 경우 작동하지 않습니다.

무엇을 놓쳤는지 말해주세요?