오류, 버그, 질문 - 페이지 2635

 

이 플랫폼(MT5)은 금융 시장이나 일종의 서커스 거래를 위해 만들어졌습니까? 업데이트할 때마다 코드를 다시 실행하려면 무엇이 필요합니까? 충분한.

 
Aleksandr Prishenko :

이 플랫폼(MT5)은 금융 시장이나 일종의 서커스 거래를 위해 만들어졌습니까? 업데이트할 때마다 코드를 다시 실행하려면 무엇이 필요합니까? 충분한.

흠....

정확히 무엇이 바뀌었나요? 어쩌면 나도 그것을 필요로합니까?

아무것도 업데이트되지 않은 것 같습니다....

 
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots    4
//--- plot Value
#property indicator_label1    "Volume;Volume1"
#property indicator_type1    DRAW_FILLING
#property indicator_color1    clrBlue , clrRed
#property indicator_style1    STYLE_SOLID
#property indicator_width1    2
//--- plot Middle
#property indicator_label2    "Middle line"
#property indicator_type2    DRAW_LINE
#property indicator_color2    clrMediumOrchid
#property indicator_style2    STYLE_SOLID
#property indicator_width2    1
//--- plot OverBought
#property indicator_label3    "Bands upper"
#property indicator_type3    DRAW_LINE
#property indicator_color3    clrDeepPink
#property indicator_style3    STYLE_SOLID
#property indicator_width3    1
//--- plot OverSold
#property indicator_label4    "Bands lower" //нижняя линия
#property indicator_type4    DRAW_LINE
#property indicator_color4    clrDeepPink
#property indicator_style4    STYLE_SOLID
#property indicator_width4    1
//---
enum OSCILLATOR_NAME {
   MACD,             // MACD
   MOMENTUM,         // Momentum
   RSI,               // RSI
   MFI,               // MFI 
   AC                 // AC
};
//---
enum LEVEL_MODE {
   CONST_VALUE_MODE, // Constant level value mode
   MA_MODE,           // Moving Average mode
   BB_MODE           // Bollinger Bands Mode
};
//---
enum DRAW_MODE {
   LINE,             // Line
   FILLING,           // Filling
   HISTOGRAM         // Histogram
};
//--- input parameters
input ENUM_TIMEFRAMES       TF_Oscillator = PERIOD_CURRENT ;                         // TIMEFRAMES Oscillator
input OSCILLATOR_NAME      InpOscillator = MACD;                         // Oscillator
input int                   InpOscPeriod1 = 1 ;                           // MACD Fast EMA / Period for: RSI,MFI,Momentum 
input int                   InpOscPeriod2 = 34 ;                           //  MACD Slow EMA
input int                   InpOscPeriod3 = 1 ;                           //  MACD Signal
input ENUM_APPLIED_PRICE    InpAppliedPrice = PRICE_CLOSE ;               // Applied price
input    ENUM_APPLIED_VOLUME InpVOLUME = VOLUME_TICK ;                     //Applied Volume for MFI
input DRAW_MODE            InpDrawMode = LINE;                       // Draw Mode 
input int                   InpLevelsPeriod = 40 ;                         // Levels Period Upper
input int                   InpLevelsPeriod1 = 35 ;                         // Levels Period  Lower
input double                InpLevelsIndent = 3.0 ;                       // Deviation Upper
input double                InpLevelsIndent1 = 4.0 ;                       //  Deviation Lower

 LEVEL_MODE           InpLevelsMode = BB_MODE;                     // Levels Mode
bool                  InpIndentAutoCorrection = true ;               // Levels Auto Correction
//input string               InpDivider = "---For Stochastic or MACD---"; // Just Divider NOT Parameter 
//input ENUM_STO_PRICE       InpStochPrice = STO_LOWHIGH;                 // Stochastic Price

//--- indicator buffers
double          ExtBuffer1[]; //Line
double          ExtBuffer2[]; //Middle
double          ExtBuffer3[]; //Upper
double          ExtBuffer4[]; //Lowe
double          ExtBuffer5[];
double          ExtBuffer6[];
//--- global variables
int             oscPeriod1;
int             levelsPeriod;
int             levelsPeriod1;
int             minRequiredBars;
int             oscHandle;
int             oscPeriod2;
int             oscPeriod3;
double          midValue;
double          addValue;
double          levelsIndent,levelsIndent1 ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit () {
//---
   if ( InpOscPeriod1 < 1 ) {
      oscPeriod1 = 14 ;
       printf ( "Incorrected input parameter InpOscPeriod1 = %d. Indicator will use value %d." , InpOscPeriod1, oscPeriod1);
   } else {
      oscPeriod1 = InpOscPeriod1;
   }
   
   if ( InpLevelsPeriod < 1 ) {
      levelsPeriod = 10 ;
       printf ( "Incorrected input parameter InpLevelsPeriod = %d. Indicator will use value %d." , InpLevelsPeriod, levelsPeriod);
   } else {
      levelsPeriod = InpLevelsPeriod;
   }
   if ( InpLevelsPeriod1 < 1 ) {
      levelsPeriod = 10 ;
       printf ( "Incorrected input parameter InpLevelsPeriod = %d. Indicator will use value %d." , InpLevelsPeriod, levelsPeriod);
   } else {
      levelsPeriod1 = InpLevelsPeriod1;
   }
   
   if ( InpOscPeriod2 < 1 ) {
      oscPeriod2 = 3 ;
       printf ( "Incorrected input parameter InpOscPeriod2 = %d. Indicator will use value %d." , InpOscPeriod2, oscPeriod2);
   } else {
      oscPeriod2 = InpOscPeriod2;
   }
   
   if ( InpOscPeriod3 < 1 ) {
      oscPeriod3 = 3 ;
       printf ( "Incorrected input parameter InpOscPeriod3 = %d. Indicator will use value %d." , InpOscPeriod3, oscPeriod3);
   } else {
      oscPeriod3 = InpOscPeriod3;
   }
   
   levelsIndent = MathAbs (InpLevelsIndent); // Levels Indent / Deviation
   levelsIndent1 = MathAbs (InpLevelsIndent1); // Levels Indent / Deviation
//---
   minRequiredBars = 20 ; // oscPeriod1 + oscPeriod2 + oscPeriod3 + levelsPeriod - 1;
//--- indicator buffers mapping
   SetIndexBuffer ( 0 , ExtBuffer1, INDICATOR_DATA );
   SetIndexBuffer ( 1 , ExtBuffer2, INDICATOR_DATA );
   SetIndexBuffer ( 2 , ExtBuffer3, INDICATOR_DATA );
   SetIndexBuffer ( 3 , ExtBuffer4, INDICATOR_DATA );
   SetIndexBuffer ( 4 , ExtBuffer5, INDICATOR_DATA );
   SetIndexBuffer ( 5 , ExtBuffer6, INDICATOR_DATA );
//---
   string shortname = "Oscillator For BBS: " ;
//---
   switch ( InpOscillator ) {
 
       case MACD:
         oscHandle = iMACD ( _Symbol , TF_Oscillator, oscPeriod1, oscPeriod2, oscPeriod3, InpAppliedPrice);
         midValue = 0.0 ;
         shortname += "MACD (" + ( string )oscPeriod1 + ", " + ( string )oscPeriod2 + ", " + ( string )oscPeriod3 + ")" ;
         break ;
         
       case MOMENTUM:
         oscHandle = iMomentum ( _Symbol , TF_Oscillator, oscPeriod1, InpAppliedPrice);
         midValue = 100.0 ;
         levelsAutoCorrect( 0.03 , 5.0 , 0.5 );
         shortname += "Momentum (" + ( string )oscPeriod1 + ")" ;
         break ;
         
       case RSI:
         oscHandle = iRSI ( _Symbol , TF_Oscillator, oscPeriod1, InpAppliedPrice);
         midValue = 50.0 ;
         levelsAutoCorrect( 5.0 , 50.0 , 20.0 );
         shortname += "RSI (" + ( string )oscPeriod1 + ")" ;
         break ;
       case MFI:
         oscHandle = iMFI ( _Symbol , TF_Oscillator, oscPeriod1, InpVOLUME);
         midValue = 50.0 ;
         levelsAutoCorrect( 5.0 , 50.0 , 20.0 );
         shortname += "MFI (" + ( string )oscPeriod1 + ")" ;
         break ;
         
       case AC:
         oscHandle = iAC ( _Symbol , 0 );
         midValue = 0.0 ;
         levelsAutoCorrect( 5.0 , 50.0 , 20.0 );
         shortname += "AC" ;
         break ; 
               
       default :
         oscHandle = INVALID_HANDLE ;
         Print ( "Unknown Oscillator!" );
         return (- 1 );
   }
//---
   switch ( InpDrawMode ) {
       case FILLING:
         SetIndexBuffer ( 2 , ExtBuffer3, INDICATOR_DATA );
         PlotIndexSetInteger ( 0 , PLOT_DRAW_TYPE , DRAW_FILLING );
         break ;
         
       case HISTOGRAM:
         SetIndexBuffer ( 2 , ExtBuffer3, INDICATOR_COLOR_INDEX );
         PlotIndexSetInteger ( 0 , PLOT_DRAW_TYPE , DRAW_COLOR_HISTOGRAM2 );
         break ;
         
       case LINE:
       default :
         SetIndexBuffer ( 2 , ExtBuffer3, INDICATOR_DATA );
         PlotIndexSetInteger ( 0 , PLOT_DRAW_TYPE , DRAW_LINE );
         break ;
   }
//---
   IndicatorSetString ( INDICATOR_SHORTNAME , shortname); 
//---
   return ( 0 );
}
//+------------------------------------------------------------------+
//| Levels indent / deviation correction function                    |
//+------------------------------------------------------------------+
void levelsAutoCorrect( double minIndent, double maxIndent, double correctIndent)
 {
//---
   if ( InpLevelsMode == BB_MODE ) {
       if ( levelsIndent > 4.0    ) {
         levelsIndent = 2.0 ;
         printf ( "Incorrected deviation input parameter InpLevelsIndent = %f. Indicator will use value %f." , 
            InpLevelsIndent, levelsIndent);
      }
       if ( levelsIndent1 > 4.0   ) {
         levelsIndent1 = 2.0 ;
         printf ( "Incorrected deviation input parameter InpLevelsIndent = %f. Indicator will use value %f." , 
            InpLevelsIndent, levelsIndent1);
      }
   } else {
       if ( levelsIndent < minIndent || levelsIndent > maxIndent ) {
         levelsIndent = correctIndent;
         printf ( "Incorrected indent input parameter InpLevelsIndent = %f. Indicator will use value %f." , 
            InpLevelsIndent, levelsIndent);
      }
      
       if ( levelsIndent1 < minIndent || levelsIndent1 > maxIndent ) {
         levelsIndent1 = correctIndent;
         printf ( "Incorrected indent input parameter InpLevelsIndent = %f. Indicator will use value %f." , 
            InpLevelsIndent, levelsIndent1);
      } 
      
   }
//---
}
//+------------------------------------------------------------------+
//| 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 startBar, calculated, toCopy;
//---
   if ( rates_total < minRequiredBars ) {
       Print ( "Not enough bars for calculation." );
       return ( 0 );
   }
//---
   calculated = BarsCalculated (oscHandle);
   if ( calculated < rates_total ) {
       Print ( "Not all data of oscHandle is calculated (" , calculated, " bars. Error #" , GetLastError ());
       return ( 0 );
   }
//---
   if ( prev_calculated > rates_total || prev_calculated <= 0 ) {
      startBar = minRequiredBars;
      toCopy = rates_total;
   } else {
      startBar = prev_calculated - 1 ;
      toCopy = rates_total - prev_calculated;
       if ( prev_calculated > 0 ) {
         toCopy += 1 ;
      }
   }
//---
   if ( CopyBuffer (oscHandle, 0 , 0 , toCopy, ExtBuffer1) <= 0 ) {
       Print ( "Getting Oscillator is failed. Error #" , GetLastError ());
       return ( 0 );
   }
//---
   if ( InpLevelsMode != CONST_VALUE_MODE ) { //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      SimpleMAOnBuffer(rates_total, prev_calculated, oscPeriod1+levelsPeriod, levelsPeriod, ExtBuffer1, ExtBuffer2);
   }
//---   
   for ( int bar = startBar; bar < rates_total; bar++ ) {
       double value, sum = 0.0 , sum1 = 0.0 ;
       double middleLine, indent, indent1;
       //---
       switch ( InpLevelsMode ) {
         case MA_MODE:
            middleLine = ExtBuffer2[bar];
            indent = levelsIndent;
            indent1 = levelsIndent1;
             break ;
         case BB_MODE:           //просмотреть формулу
            middleLine = value = ExtBuffer2[bar];
             for ( int i = bar - levelsPeriod + 1 ; i <= bar; i++ ) {
               sum += MathPow (ExtBuffer1[i]-value, 2 );
            }
            indent = levelsIndent * MathSqrt (sum/levelsPeriod); 
             for ( int k = bar - levelsPeriod1 + 1 ; k <= bar; k++ ) {
               sum1 += MathPow (ExtBuffer1[k]-value, 2 );
            }
            indent1 = levelsIndent1 * MathSqrt (sum/levelsPeriod1);            
             break ;
         case CONST_VALUE_MODE:
         default :
            middleLine = ExtBuffer2[bar] = midValue;
            indent = levelsIndent;
            indent1 = levelsIndent1;
             break ;
      }
       //---
       switch ( InpDrawMode ) {
         case LINE:
            ExtBuffer3[bar] = middleLine + indent; //Upper
            ExtBuffer4[bar] = middleLine - indent1; //Lowe
             break ;
         case FILLING:
            ExtBuffer3[bar] = middleLine;
            ExtBuffer4[bar] = middleLine + indent;
            ExtBuffer5[bar] = middleLine - indent1;
             break ;
         case HISTOGRAM:
             if ( ExtBuffer1[bar] >= ExtBuffer2[bar] ) {
               ExtBuffer3[bar] = 0 ;
            } else {
               ExtBuffer3[bar] = 1 ;
            }
            ExtBuffer4[bar] = middleLine;
            ExtBuffer5[bar] = middleLine + indent;
            ExtBuffer6[bar] = middleLine - indent1;
             break ;
      }
   }
//--- return value of prev_calculated for next call
   return (rates_total);
}
//+------------------------------------------------------------------+

여기서 무슨 문제가 있습니까? 이런 종류의 오류가 발생한 빌드는 몇 가지 없었습니다.

         case BB_MODE:
            middleLine = value = ExtBuffer2[bar];
             for ( int i = bar - levelsPeriod + 1 ; i <= bar; i++ ) {
               sum += MathPow(ExtBuffer1[i]- value , 2 );
2020.02.05 10:56:13.220 코어 1 2017.11.01 00:00:00 'Oscillator For BBS.mq5'(308,41)에서 범위를 벗어난 배열

 
Aleksandr Prishenko :

여기서 무슨 문제가 있습니까? 이런 종류의 오류가 발생한 빌드는 몇 가지 없었습니다.

2020.02.05 10:56:13.220 코어 1 2017.11.01 00:00:00 'Oscillator For BBS.mq5'(308,41)에서 범위를 벗어난 배열

아, 분명...

글쎄요, 아마도 업데이트와 관련이 없을 것입니다. 우리는 그 이유를 알아내야 합니다...

 
Vladislav Andruschenko :

아, 분명...

글쎄요, 아마도 업데이트와 관련이 없을 것입니다. 우리는 그 이유를 알아내야 합니다...

글쎄, 모든 것이 5 년 이상 동안 작동했습니다)) 코드는 변경되지 않았습니다)

 
Aleksandr Prishenko :

글쎄, 모든 것이 5 년 이상 동안 작동했습니다)) 코드는 변경되지 않았습니다)

오류가 플랫폼 업데이트와 관련된 것은 아닙니다. 배열 이 부족합니다.

 
Evgeny Potapov :

안녕하세요!

배치 파일로 여러 MT4를 실행하고 싶습니다.

이 작업을 수행하는 방법과 내 코드가 작동하지 않는 이유를 알려주세요.

기껏해야 여러 MT4가 실행된 다음 멈춥니다.

물론 RAM이 부족한 것은 아닙니다.

또한 다른 컴퓨터에서 시도했습니다.

혹시 휴대용 모드 키가 필요하지 않습니까?

모든 터미널에서 손이 시작되었습니까?

 
Alexey Viktorov :

Roman, 두 번째로 당신 은 문서 를 읽고 싶어하지 않는 기초적인 태도를 갖게 됩니다.

그리고 mql4 문서에서 내 기억이 완전히 바뀌지 않았다면 변수를 배열 크기로 사용하는 것이 허용되지 않는다는 점에 대해 명확하게 명시되어 있습니다.

실제로는 아니지만 문서를 인용해 주셔서 감사합니다.

 
Koldun Zloy :

저는 개발자는 아니지만 댓글을 달겠습니다.

정적 배열 의 경우 컴파일러는 이미 컴파일 시 메모리에 특정 바이트 수를 할당해야 합니다.

컴파일 시 행과 열을 알 수 없는 경우 컴파일러는 얼마나 많은 메모리를 할당해야 합니까?

초기값은 호출 시 매개변수가 생략된 경우에만 사용됩니다. 실제 매개변수는 런타임에만 알 수 있습니다.

그러니 농담하지 말고 언어를 배우십시오.

여기도 사실인 것 같고, 덕분에 추억에 대한 생각도 있었다.
C 언어의 예는 단지 안내를 받은 것뿐입니다.

 int N, M;
int i, j;
scanf( "%d" , &N);
scanf( "%d" , &M);

int A[N][M];
for (i = 0 ; i < N; i++) { 
   for (j = 0 ; j < M; j++) {
      A[i][j] = 10 + rand () % ( 20 - 10 + 1 );
       printf ( "%d " , A[i][j]);
   }
}

puts( "\n" );

그러나 분명히 현대 컴파일러는 더 엄격해졌습니다.
VS에서 이 코드를 확인했는데 할당되지 않은 어레이 메모리에서도 마찬가지입니다.
분명히 예제는 다른 컴파일러를 위한 것입니까, 아니면 구식이며 언어 표준에 따라 달라집니까?

 

이제 프로필 버튼 옆에 있는 mql5.com 사이트 헤더에 세 개의 아이콘이 있습니다.

1.즐겨찾기

2. 리본

3. 메시지

다음과 같은 다른 아이콘을 추가하세요.

4. 돈

하루에 받은 모든 자금(마켓, 프리랜서 등)의 합계가 표시되는 곳에 매우 편리할 것이지만 이제 사용 가능한 잔액을 보려면 프로필로 이동해야 합니다.