MQL5在测试时不会截图(MQL5 not taking screenshot while testing)

编程入门 行业动态 更新时间:2024-10-16 18:38:56
MQL5在测试时不会截图(MQL5 not taking screenshot while testing)

我试图将使用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; } } }

I have tried to modify the script written in MQL4 to MQL5. The output expected was to have the files in the Files folder. But there is nothing to be seeing. No error and warning found. Kindly, suggest me the improvement so I can take the screen shot of the graph while am testing.

Here is the script:

#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; } } }

最满意答案

对象事件必须在OnChartEvent()而不是OnTick()函数内处理。 在测试中OnChartEvent不起作用 - 它不受支持

object events must be handled inside OnChartEvent() not OnTick() function. In testing OnChartEvent doesnt work - it is not supported

更多推荐

本文发布于:2023-04-29 01:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334489.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:截图   测试   screenshot   testing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!