학습 논리 - 페이지 4

 

다음은 이 표시기의 원래 start() 함수입니다.

 int start()
{
   int limit;
   double a;
   int counted_bars = IndicatorCounted();
   if (counted_bars < 0 ) return (- 1 );
   if (counted_bars > 0 ) counted_bars--;
   limit = Bars - counted_bars;
   for ( int i = 0 ; i < limit; i++)
    {
       for ( int j = 0 ; j < nPeriod; j++)
       {
         a = a + (iHigh( NULL , 0 , i + j) + iLow( NULL , 0 , i + j) + iClose( NULL , 0 , i + j) * 2 ) / 4 ;
       }       
      MaBuffer[i]  =  a / nPeriod;
      a = 0 ;
       if (iClose( NULL , 0 , i) > MaBuffer[i])
       {
         MaTUp[i] = MaBuffer[i] + iATR ( NULL , 0 , nPeriod, i) * Deviation;
         MaTDn[i] = MaBuffer[i] - iATR ( NULL , 0 , nPeriod, i);
       }  
       else if (iClose( NULL , 0 , i) < MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR ( NULL , 0 , nPeriod, i) * Deviation;
         MaTUp[i] = MaBuffer[i] + iATR ( NULL , 0 , nPeriod, i);
       } 
       else if (iClose( NULL , 0 , i) == MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR ( NULL , 0 , nPeriod, i) * Deviation;
         MaTUp[i] = MaBuffer[i] + iATR ( NULL , 0 , nPeriod, i) * Deviation;
       }  
    }  
   //-----
   return ( 0 );
}

이 함수는 평균 계산을 사용합니다. 그래서 표준 기능으로 대체할 것을 요청합니다.

이 정도

 //=================================================================================================
// Замена расчета среднего на стандартную функцию
//=================================================================================================
//   Старый вариант расчета
//      for(int j = 0; j < nPeriod; j++)
//       {
//         a = a + (iHigh(NULL, 0, i + j) + iLow(NULL, 0, i + j) + iClose(NULL, 0, i + j) * 2) / 4;
//       }       
//      MaBuffer[i]  =  a / nPeriod;
//      a = 0;
//=================================================================================================
//   Новый вариант расчета

      MaBuffer[i]= iMA ( NULL , 0 , nPeriod, 0 , MODE_SMA , PRICE_WEIGHTED ,i);
//=================================================================================================

수정된 표시기의 변형이 첨부되었습니다.

파일:
 

이제 지표의 바로 그 논리로 넘어가겠습니다(제안된 옵션이 이상적이라고 말하는 것이 아닙니다)

난 그냥 그를 더 좋아

       // Вариант два. Убираем избыточные условия  и делаем одно обращение к функции
      
      atr= iATR ( NULL , 0 , nPeriod, i);
      MaTDn[i] = MaBuffer[i] - atr * Deviation;
      MaTUp[i] = MaBuffer[i] + atr * Deviation;

       if (iClose( NULL , 0 , i) > MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - atr;
       }  
       else if (iClose( NULL , 0 , i) < MaBuffer[i])
       {
         MaTUp[i] = MaBuffer[i] + atr;
       } 
파일:
 
좋은 예입니다. 이것은 논리보다 최적화에 관한 것입니다.
 
denis_orlov :
좋은 예입니다. 이것은 논리보다 최적화에 관한 것입니다.


그리고 논리도 생각의 논리입니다.

세 번째 옵션은 지표의 논리적 조건을 완전히 포기하는 것입니다. 질문이 생깁니다. 가능합니까?

해보자

이렇게 하려면 몇 가지 부울 변수를 추가하십시오.

시작 함수의 전체 코드는 다음과 같습니다.

 int start()
{
   int limit;
   double atr;
   bool bUP, bDN;
   int counted_bars = IndicatorCounted();
   if (counted_bars < 0 ) return (- 1 );
   if (counted_bars > 0 ) counted_bars--;
   limit = Bars - counted_bars;
   for ( int i = 0 ; i < limit; i++)
    {

      MaBuffer[i]= iMA ( NULL , 0 , nPeriod, 0 , MODE_SMA , PRICE_WEIGHTED ,i);

       // Вариант три. 
      
      atr= iATR ( NULL , 0 , nPeriod, i);
      bUP=Close[i] < MaBuffer[i];
      bDN=Close[i] > MaBuffer[i];
      MaTDn[i] = MaBuffer[i] - atr - atr * (Deviation - 1.0 ) * bUP;
      MaTUp[i] = MaBuffer[i] + atr + atr * (Deviation - 1.0 ) * bDN;

    }  
   //-----
   return ( 0 );
}
파일:
 

if(counted_bars < 0) return(-1);

어떤 논리를 기반으로 이 라인이 존재합니까?

 
Roger :

if(counted_bars < 0) return(-1);

어떤 논리를 기반으로 이 라인이 존재합니까?


이것은 내 라인이 아닙니다. 이것은 저작권입니다

start() 함수에 대한 최적의 코드

 int start()
{
   int limit;
   double atr;
   int counted_bars = IndicatorCounted();
   
   limit = Bars - counted_bars- 1 ;
   if ( Bars - counted_bars > 2 ) limit = Bars - nPeriod- 1 ;

   for ( int i = limit; i >= 0 ; i--)
    {
      MaBuffer[i]= iMA ( NULL , 0 , nPeriod, 0 , MODE_SMA , PRICE_WEIGHTED ,i);
      atr= iATR ( NULL , 0 , nPeriod, i);

      MaTDn[i] = MaBuffer[i] - iATR ( NULL , 0 , nPeriod, i) * Deviation;
      MaTUp[i] = MaBuffer[i] + iATR ( NULL , 0 , nPeriod, i) * Deviation;

       if (iClose( NULL , 0 , i) > MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR ( NULL , 0 , nPeriod, i);
       }  
       else if (iClose( NULL , 0 , i) < MaBuffer[i])
       {
         MaTUp[i] = MaBuffer[i] + iATR ( NULL , 0 , nPeriod, i);
       } 

    }  
   //-----
   return ( 0 );
}
파일:
 

직업 옵션의 비교 분석

최적의 옵션 번호 2. 논리적 조건을 거부할 수 없습니다.

옵션 5는 기본으로 만들어졌습니다.

파일:
 

나는 대본을 완전히 잊어 버렸습니다.

파일:
 
Vinin :

나는 대본을 완전히 잊어 버렸습니다.

재치있는 방법, 나는 취한다))
 
Mathemat :

gip 을 비판하는 섹션에 대해 추가하겠습니다.


다음과 같이 작성할 수 있을 때 부울 변수 주위에서 이러한 춤이 발생하는 이유는 절대적으로 명확하지 않습니다.

   showEUR  = ( StringFind ( Symbol (), "EUR" , 0 ) != - 1 );
   showUSD  = ( StringFind ( Symbol (), "USD" , 0 ) != - 1 );
   showGBP  = ( StringFind ( Symbol (), "GBP" , 0 ) != - 1 );
   showCHF  = ( StringFind ( Symbol (), "CHF" , 0 ) != - 1 );
   showJPY  = ( StringFind ( Symbol (), "JPY" , 0 ) != - 1 );