MQL5 не снимает скриншот во время тестирования - PullRequest
0 голосов
/ 14 мая 2018

Я пытался изменить скрипт, написанный на MQL4, на MQL5.Ожидаемый результат должен был иметь файлы в папке Files.Но смотреть нечего.Ошибки и предупреждения не найдены.
Пожалуйста, предложите мне улучшение, чтобы я мог сделать снимок экрана графика во время тестирования.

Вот сценарий:

#define        WIDTH  800     // Image width to call ChartScreenShot() 
#define        HEIGHT 600     // Image height to call ChartScreenShot() 

//--- input parameters 
input int      pictures=5;    // The number of images in the series 
int            mode=1;       // -1 denotes a shift to the right edge of the chart, 1 - to the left 
int            bars_shift=300;// The number of bars when scrolling the chart using ChartNavigate() 
//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
void OnInit() 
  { 
//--- Disable chart autoscroll 
   ChartSetInteger(0,CHART_AUTOSCROLL,false); 
//--- Set the shift of the right edge of the chart 
   ChartSetInteger(0,CHART_SHIFT,true); 
//--- Show a candlestick chart 
   ChartSetInteger(0,CHART_MODE,CHART_CANDLES); 
//--- 
   Print("Preparation of the Expert Advisor is completed"); 
  } 
//+------------------------------------------------------------------+ 
//| Expert tick function                                             | 
//+------------------------------------------------------------------+ 
void OnTick() 
  { 
//--- 
int id = 0;

  Print(__FUNCTION__,TimeCurrent(),"   id=",id,"   mode=",mode); 
//--- Handle the CHARTEVENT_CLICK event ("A mouse click on the chart") 
   if(id==CHARTEVENT_CLICK) 
     { 
      //--- Initial shift from the chart edge 
      int pos=0; 
      //--- Operation with the left chart edge 
      if(mode>0) 
        { 
         //--- Scroll the chart to the left edge 
         ChartNavigate(0,CHART_BEGIN,pos); 
         for(int i=0;i<pictures;i++) 
           { 
            //--- Prepare a text to show on the chart and a file name 
            string name="ChartScreenShot"+"CHART_BEGIN"+string(pos)+".gif"; 
            //--- Show the name on the chart as a comment 
            Comment(name); 
            //--- Save the chart screenshot in a file in the terminal_directory\MQL5\Files\ 
            if(ChartScreenShot(0,name,WIDTH,HEIGHT,ALIGN_LEFT)) 
               Print("We've saved the screenshot ",name); 
            //--- 
            pos+=bars_shift; 
            //--- Give the user time to look at the new part of the chart 
            Sleep(3000); 
            //--- Scroll the chart from the current position bars_shift bars to the right 
            ChartNavigate(0,CHART_CURRENT_POS,bars_shift); 
           } 
         //--- Change the mode to the opposite 
         mode*=-1; 
        } 
      else // Operation with the right chart edge 
        { 
         //--- Scroll the chart to the right edge 
         ChartNavigate(0,CHART_END,pos); 
         for(int i=0;i<pictures;i++) 
           { 
            //--- Prepare a text to show on the chart and a file name 
            string name="ChartScreenShot"+"CHART_END"+string(pos)+".gif"; 
            //--- Show the name on the chart as a comment 
            Comment(name); 
            //--- Save the chart screenshot in a file in the terminal_directory\MQL5\Files\ 
            if(ChartScreenShot(0,name,WIDTH,HEIGHT,ALIGN_RIGHT)) 
               Print("We've saved the screenshot ",name); 
            //--- 
            pos+=bars_shift; 
            //--- Give the user time to look at the new part of the chart 
            Sleep(3000); 
            //--- Scroll the chart from the current position bars_shift bars to the right 
            ChartNavigate(0,CHART_CURRENT_POS,-bars_shift); 
           } 
         //--- Change the mode to the opposite 
         mode*=1; 
        } 
     } 
  } 

1 Ответ

0 голосов
/ 14 мая 2018

события объекта должны обрабатываться внутри OnChartEvent (), а не функции OnTick (). В тестировании OnChartEvent не работает - он не поддерживается

...