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

 
컴파일러 최적화 오류
 #define TOSTRING(A) #A + " = " + ( string )(A)

void OnStart ()
{
   color Color1 = ( color ) ColorToARGB ( clrWhite , 0xFF );
   color Color2 = - 1 ;
  
   Print (TOSTRING(Color1 == Color2));   // Color1==Color2 = true
   Print (TOSTRING(Color1 == - 1 ));       // Color1==-1 = false
   Print (TOSTRING(( int )Color1 == - 1 ));   // (int)Color1==-1 = true
   Print (TOSTRING(( uint )Color1 == - 1 )); // (uint)Color1==-1 = true
}
 
CPositionInfo::Commission 의 철자가 잘못되었습니다.
 
조건이 작동할 수 있습니까?
 if ( PositionGetInteger ( POSITION_TICKET ) != PositionGetInteger ( POSITION_IDENTIFIER ))
        ;
 
스크립트를 디버깅할 때 F11의 마지막 이동은 OnStart를 종료하는 것입니다. 그러나 OnStart를 종료한 후에도 여전히 실행 단계가 있습니다. 즉 전역 개체의 소멸자입니다. 결과적으로 F11 키를 누르면 잘못된 작업이 건너뜁니다.
 
히스토리(스피드 슬라이더 - 최대)에서 디버깅할 때 거래 환경의 GUI가 현실과 일치하지 않음
 #include <Trade\Trade.mqh>

input int Interval = 3600 ;
input int AmountLastDeals = 5 ;
input double Lots = 1 ;

double CorrectLot( const double Lot )
{
   static const double StepVol = SymbolInfoDouble ( _Symbol , SYMBOL_VOLUME_STEP );
   static const double MaxVol = SymbolInfoDouble ( _Symbol , SYMBOL_VOLUME_MAX );
   static const double MinVol = SymbolInfoDouble ( _Symbol , SYMBOL_VOLUME_MIN );
  
   const double Vol = StepVol * ( int )(Lot / StepVol + 0.5 );
  
   return ((Vol < MinVol) ? MinVol : ((Vol > MaxVol) ? MaxVol : Vol));
}

void OnTick ()
{
   static CTrade Trade;
   static CDealInfo Deal;
   static CPositionInfo Position; 

   if (!Position.Select( _Symbol ))
  {
     if ( HistorySelect ( 0 , TimeCurrent ()))
    {
       const int Total = HistoryDealsTotal () - 1 ;

       double SumProfit = 0 ;
       double SumLots = 0 ;

       for ( int i = Total, Count = 0 ; (i >= 0 ) && (Count < AmountLastDeals); i--)
         if (Deal.SelectByIndex(i) && (Deal.Entry() == DEAL_ENTRY_OUT ))
        {        
          SumProfit += Deal.Profit() * (AmountLastDeals - Count) / AmountLastDeals;
          SumLots += Deal. Volume () * (AmountLastDeals - Count) / AmountLastDeals;
          
          Count++;
        }

       if (Total == 2 )
      {
         string Str;
        
         for ( int i = Total; i >= 0 ; i--)
           if (Deal.SelectByIndex(i))
             Print (Deal.FormatDeal(Str));
        
         DebugBreak ();
      }

       if ((Total >= 0 ) && Deal.SelectByIndex(Total) && (Deal.DealType() == DEAL_TYPE_SELL ))
        Trade.Sell((SumProfit >= 0 ) ? Lots : CorrectLot(SumLots));
       else
        Trade.Buy((SumProfit >= 0 ) ? Lots : CorrectLot(SumLots));
    }       
  }
   else if ( TimeCurrent () - Position. Time () >= Interval)
    Trade.PositionClose( _Symbol );
}
DebugBreak 시 로그
2017.06.07 23:29:03.554 EURUSD : real ticks begin from 2017.04.10 00:00:00
2017.06.07 23:29:03.564 2017.04.10 00:00:00   instant buy 1.00 EURUSD at 1.05918 (1.05885 / 1.05918)
2017.06.07 23:29:03.564 2017.04.10 00:00:00   deal #2 buy 1.00 EURUSD at 1.05918 done (based on order #2)
2017.06.07 23:29:03.564 2017.04.10 00:00:00   deal performed [#2 buy 1.00 EURUSD at 1.05918]
2017.06.07 23:29:03.564 2017.04.10 00:00:00   order performed buy 1.00 at 1.05918 [#2 buy 1.00 EURUSD at 1.05918]
2017.06.07 23:29:03.566 2017.04.10 00:00:00   CTrade::OrderSend: instant buy 1.00 EURUSD at 1.05918 [done at 1.05918]
2017.06.07 23:29:03.569 2017.04.10 01:00:00   instant sell 1.00 EURUSD at 1.05833 (1.05833 / 1.05845 / 1.05831)
2017.06.07 23:29:03.569 2017.04.10 01:00:00   deal #3 sell 1.00 EURUSD at 1.05833 done (based on order #3)
2017.06.07 23:29:03.569 2017.04.10 01:00:00   deal performed [#3 sell 1.00 EURUSD at 1.05833]
2017.06.07 23:29:03.569 2017.04.10 01:00:00   order performed sell 1.00 at 1.05833 [#3 sell 1.00 EURUSD at 1.05833]
2017.06.07 23:29:03.570 2017.04.10 01:00:00   CTrade::OrderSend: instant sell 1.00 EURUSD at 1.05833 [done at 1.05833]
2017.06.07 23:29:03.570 2017.04.10 01:00:00   #3 sell 1.00 EURUSD at 1.05833
2017.06.07 23:29:03.570 2017.04.10 01:00:00   #2 buy 1.00 EURUSD at 1.05918
2017.06.07 23:29:03.570 2017.04.10 01:00:00   CSymbolInfo::CheckMarketWatch: Unknown symbol ''
2017.06.07 23:29:03.570 2017.04.10 01:00:00   #1 balance 100000.00 []
화면


마지막 거래는 GUI에 표시되지 않습니다. 1596-1606에 의해 재생산.

 
고전적인 오류 이지만 컴파일러는 분명히 잘못된 오류를 제공합니다.
 struct STRUCT
{
   string Str;

   void operator =( STRUCT& ) {}

   void operator =( int & ) {}
};

STRUCT Func()
{
  STRUCT Res = { 0 };
  
   return (Res); // OK

   return ( true ? Res : Res); // Неадекватные ошибки компилятора
//  'operator=' - no one of the overloads can be applied to the function call
//  could be one of 2 function(s)
//    void STRUCT::operator=(int&)
//    void STRUCT::operator=(STRUCT&)
//  'operator=' - structure have objects and cannot be copied  
}
 
테스터에서 HistorySelect 가 작동하지 않음
 void OnTick ()
{
   static bool FirstRun = true ;
  
   if (FirstRun)
  {
     if ( HistorySelect ( TimeCurrent () + 1 , TimeCurrent () + 2 )) // берем историю заведомо там, где ничего нет
       Print ( HistoryDealsTotal ()); // 1 - балансовая сделка
    
    FirstRun = false ;
  }
}
 

코드베이스에서 소스 파일은 잘못된 __X 접미사를 받았습니다.

예를 들어 TypeToBytes __10 .mqh

TypeToBytes
TypeToBytes
  • 투표: 21
  • 2016.09.13
  • fxsaber
  • www.mql5.com
Побайтовая работа со структурами, массивами и стандартными типами данных
 
fxsaber :
CPositionInfo::Commission의 철자가 잘못되었습니다.
정확히 무엇?
 
Rashid Umarov :
정확히 무엇?
 double CPositionInfo::Commission( void ) const
  {
   return ( PositionGetDouble ( POSITION_COMMISSION ));
  }
POSITION_COMMISSION 은 더 이상 관련이 없습니다.