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

 
Igor Kryuchkov :

Ctrl+B --> "전체" 버튼 - 내가 말하는 개체가 하나 있습니다. 문제는 Canvas 없이 일반적인 방법으로 RECTANGLE을 만들면 된다는 것 입니다. 필요한 수의 RECTANGLE 개체가 생성됩니다.

어떤 이유로 Canvas를 통해 하나만 생성됩니다. 왜 그럴 수 있습니까? 각 RECTANGLE 에 대해 고유한 이름을 지정합니다.


프로그래머에게 감사합니다.

왜 당신의 이름이 독특하다고 생각합니까? 새 개체를 만들기 전에 확인했습니까? 그리고 객체 생성 결과를 확인합니까? 이에 대한 오류 코드는 무엇입니까?

 
Artyom Trishkin :

완전히 재현 가능한 코드가 없습니다. 구체적인 논의가 없습니다. 나는 당신이 거기에서 무엇을했는지 모르겠어요. 가장 단순한 것에서 어떤 종류의 문제를 만들었습니다.

 #property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"
#property strict
#property indicator_chart_window
#include <Canvas\Canvas.mqh>
CCanvas C;

int History = 5000 ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
        
//---
   return ( INIT_SUCCEEDED );
  }
  
void OnDeinit ( const int reason)
{


}  
  
//+------------------------------------------------------------------+
//| 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 BarsCounted = IndicatorCounted();
           if (BarsCounted < 0 ) return (- 1 );
           if (BarsCounted > 0 ) BarsCounted--;
           int BarsTotal = Bars - BarsCounted;
           if ( BarsTotal > History ) BarsTotal = History;
   

           for ( int i = BarsTotal- 1 ; i >= 1 ; i--)
           { 
           
         
         
               double rsi = iRSI ( NULL , 0 , 14 , PRICE_CLOSE , i);
               
         
               
               if (rsi > 70 ) {
         
                  C.CreateBitmap( 0 , 0 , i, Time[i+ 5 ], Close[i+ 1 ], 50 , 70 , COLOR_FORMAT_ARGB_NORMALIZE );
                  C.Rectangle( 10 , 40 , 70 , 80 , ColorToARGB ( clrRed , 200 ));
                  C.Update( true ); 
                  
                   Print (i);
                  
               } 
           
               
           
         
           
           }
  

  
//--- return value of prev_calculated for next call
   return (rates_total);
  }
 
Igor Kryuchkov :

재부팅은 무슨 뜻인가요?

전역 변수 를 사용하여 주문을 여는 계산이 있습니다. 예를 들어 비용이 5라면 5개의 주문이 이미 개설되었으며 6번째 주문은 상승을 기다리고 있습니다. 컴파일하면 카운터가 5로 설정되고 이미 열려 있지만 5개의 추가 주문을 엽니다. 터미널을 껐다가 켜도 마찬가지입니다. 그것을 고치는 방법? .

 
Rustam Bikbulatov :

전역 변수 를 사용하여 주문을 여는 계산이 있습니다. 예를 들어 비용이 5라면 5개의 주문이 이미 개설되었으며 6번째 주문은 상승을 기다리고 있습니다. 컴파일하면 카운터가 5로 설정되고 이미 열려 있지만 5개의 추가 주문을 엽니다. 터미널을 껐다가 켜도 마찬가지입니다. 그것을 고치는 방법? .

int OnInit() 함수에서 전역 변수가 존재하는지 확인해야 합니다. 예를 들어, 0보다 큰 경우 전역 변수를 0으로 만듭니다.

 
Igor Kryuchkov :
4개인가요?
 
Artyom Trishkin :
4개인가요?

네. Canvas에 대해 물었을 때 MQL4가

 
Artyom Trishkin :
4개인가요?
4에서도 작동해야합니다.
 
Igor Kryuchkov :
4에서도 작동해야합니다.
 //+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|              Copyright 2019, Artem A. Trishkin, Skype artmedia70 |
//|                         https://www.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Artem A. Trishkin, Skype artmedia70"
#property link        "https://www.mql5.com/ru/users/artmedia70"
#property version    "1.00"
#property strict
#property indicator_chart_window
#include <Arrays\ArrayObj.mqh>
#include <Canvas\Canvas.mqh>
class CCanvObj : public CObject
  {
public :
   CCanvas           m_canvas;
  };
int History = 5000 ;
string prefix= MQLInfoString ( MQL_PROGRAM_NAME )+ "_" ;
CArrayObj list_canvas;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
   
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom deindicator initialization function                       |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
  {
//--- indicator buffers mapping
   ObjectsDeleteAll ( 0 ,prefix);
//---
   return ;
  }
//+------------------------------------------------------------------+
//| 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 limit=rates_total-prev_calculated;
   if (limit> 1 )
     {
      limit=rates_total- 1 ;
     }
//--- Цикл расчёта индикатора
   for ( int i= fmin (limit,History); i>= 0 ; i--)
     {
       double rsi= iRSI ( NULL , PERIOD_CURRENT , 14 , PRICE_CLOSE ,i);
       if (rsi> 70 )
        {
         //--- Создаём новый объект CCanvas
         CCanvObj *obj= new CCanvObj();
         if (obj== NULL )
             continue ;
         if (!list_canvas.Add(obj))
             continue ;
         string name=prefix+( string )i;
         //--- Создаём ресурс Bitmap с именем name
         if (obj.m_canvas.CreateBitmap( 0 , 0 ,name,time[i+ 5 ],close[i+ 1 ], 50 , 70 , COLOR_FORMAT_ARGB_NORMALIZE ))
           {
            obj.m_canvas.Rectangle( 0 , 0 , 49 , 69 , ColorToARGB ( clrRed , 200 ));
            obj.m_canvas.Update( true ); 
           }
        }
     }
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin :

감사합니다. 작동합니다.

그래프 크기 를 조정할 때 사각형도 더 작게 만들 수 있습니까?


규모가 추적됩니다. 그러나 표시기는 새로운 틱으로 만 이것을 이해합니다.

큰 지연이 있습니다. 그것에 대해 무엇을 할 수 있습니까?

 
Igor Kryuchkov :

감사합니다. 작동합니다.

그래프 크기 를 조정할 때 사각형도 더 작게 만들 수 있습니까?


규모가 추적됩니다. 그러나 표시기는 새로운 틱으로 만 이것을 이해합니다.

큰 지연이 있습니다. 그것에 대해 무엇을 할 수 있습니까?

  1. 크기 조정 시 크기 조정에서 벗어나고 싶었습니다...
  2. OnChartEvent()는 틱에 의존하지 않습니다.
  3. 필요한 차트 이벤트를 등록할 때 OnChartEvent()에서 생성된 모든 객체를 업데이트합니다. 그렇지 않으면 새 틱에서만 업데이트됩니다.