Hello,
I use in my mql5 EA ;to avoid the OnChartEvent's call; the following code
But when i press the buton "Buy" the fuction does not work well, it might enter a trade but ofen not!!!( It seems thatthe buton can't be often bushed )
knowing that it works very well in mql4
is there any solution for that?
You need to work through events - in this case, you will not miss the event, and when polling the button status, you will always miss clicks.
Actually I use it to manually backtest, the OnchartEvent can't be called in testing mode.
In mql4 it works very well in both live and backtesting mode without missing an event .
In mql5 must be a solution for that.
Hello,
I use in my mql5 EA ;to avoid the OnChartEvent's call; the following code
But when i press the buton "Buy" the fuction does not work well, it might enter a trade but ofen not!!!( It seems thatthe buton can't be often bushed )
knowing that it works very well in mql4
is there any solution for that?
I would suggest, printing the output, to see what it receives when it is not working, since it works certain times
The jornal does show nothing when I was pushing the buton, until the order tooked, and it works only on the testing mode when the speed of testing is high near maximal
NP 0 02:43:13.360 Startup MetaTester 5 x64 build 3110 (19 Nov 2021) DF 0 02:43:13.560 Server MetaTester 5 started on 127.0.0.1:3000 FO 0 02:43:13.569 Startup initialization finished CM 0 02:43:14.039 127.0.0.1 login (build 3050) OJ 0 02:43:14.281 Network 4372 bytes of account info loaded EL 0 02:43:14.281 Network 1470 bytes of tester parameters loaded MI 0 02:43:14.281 Network 188 bytes of input parameters loaded LO 0 02:43:14.290 Network 13931 bytes of symbols list loaded (1775 symbols) LI 0 02:43:14.291 Tester expert file added: Experts\y.ex5. 31531 bytes loaded CF 0 02:43:14.332 Tester initial deposit 50.00 USD, leverage 1:500 JN 0 02:43:14.341 Tester successfully initialized OO 0 02:43:14.341 Network 42 Kb of total initialization data received LR 0 02:43:14.341 Tester AMD A10-5745M APU with Radeon HD, 3269 MB RG 0 02:43:14.381 Symbols GBPUSD: symbol to be synchronized NS 0 02:43:14.382 Symbols GBPUSD: symbol synchronized, 3720 bytes of symbol info received EI 0 02:43:14.544 History GBPUSD: history synchronization started CN 0 02:43:14.547 History GBPUSD: load 27 bytes of history data to synchronize in 0:00:00.003 NQ 0 02:43:14.547 History GBPUSD: history synchronized from 2020.01.02 to 2021.12.16 QH 0 02:43:14.548 Ticks GBPUSD: ticks synchronization started KO 0 02:43:14.550 Ticks GBPUSD: load 34 bytes of tick data to synchronize in 0:00:00.015 NK 0 02:43:14.550 Ticks GBPUSD: history ticks synchronized from 2021.11.25 to 2021.12.15 LE 0 02:43:15.326 History GBPUSD,M1: history cache allocated for 727331 bars and contains 726301 bars from 2020.01.02 00:00 to 2021.12.14 23:58 DF 0 02:43:15.326 History GBPUSD,M1: history begins from 2020.01.02 00:00 HL 0 02:43:15.425 Tester GBPUSD,M1 (ICMarketsSC-Demo): generating based on real ticks EJ 0 02:43:15.425 Tester testing with execution delay 133 milliseconds CJ 0 02:43:15.428 Tester GBPUSD,M1: testing of Experts\y.ex5 from 2021.12.15 00:00 to 2021.12.16 00:00 started LS 0 02:43:15.489 Ticks GBPUSD : real ticks begin from 2021.11.25 00:00:00 KN 0 02:43:35.092 Trade 2021.12.15 17:54:24 market sell 0.01 GBPUSD (1.32116 / 1.32116) HH 0 02:43:35.092 Trades 2021.12.15 17:54:24 deal #2 sell 0.01 GBPUSD at 1.32116 done (based on order #2) GJ 0 02:43:35.092 Trade 2021.12.15 17:54:24 deal performed [#2 sell 0.01 GBPUSD at 1.32116] CS 0 02:43:35.092 Trade 2021.12.15 17:54:24 order performed sell 0.01 at 1.32116 [#2 sell 0.01 GBPUSD at 1.32116] MO 0 02:43:35.101 y (GBPUSD,M1) 2021.12.15 17:54:24 CTrade::OrderSend: market sell 0.01 GBPUSD [done at 1.32116] GO 3 02:43:54.260 Tester stopped by user FO 0 02:43:54.260 test Experts\y.ex5 on GBPUSD,M1 thread finished GE 0 02:43:54.415 127.0.0.1 prepare for shutdown
I would suggest, printing the output, to see what it receives when it is not working, since it works certain times
Here is my EA mql 5 code simplified, Iknow it will helps a lot of traders like me.
#property copyright "Copyright 2021, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #include<Trade\Trade.mqh> CTrade Trade; double BuyLot=0.01; double SellLot=0.01; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); Seconds(); Hour(); Minute(); Day(); Month(); Year(); Object(); ////////////////////////////////////////////////////////////////Buy if(ObjectGetInteger(0,"Buy",OBJPROP_STATE)) { Trade.Buy(NormalizeDouble(BuyLot,2),NULL,Ask,0,0,""); ObjectSetInteger(0,"Buy",OBJPROP_STATE,false); } ////////////////////////////////////////////////////////////////Sell if(ObjectGetInteger(0,"Sell",OBJPROP_STATE)) { Trade.Sell(NormalizeDouble(SellLot,2),NULL,Bid,0,0,""); ObjectSetInteger(0,"Sell",OBJPROP_STATE,false); } } //+------------------------------------------------------------------+ void Object() { ///////////////////////////////////////////////////////////////////////////////////////////Time ObjectCreate(0,"Time",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"Time",OBJPROP_XDISTANCE,300); ObjectSetInteger(0,"Time",OBJPROP_YDISTANCE,20); //--- set button size ObjectSetInteger(0,"Time",OBJPROP_XSIZE,150); ObjectSetInteger(0,"Time",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"Time",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"Time",OBJPROP_TEXT,DoubleToString(Hour(),0)+":"+ DoubleToString(Minute(),0)+":"+DoubleToString(Seconds(),0)); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"Time",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"Time",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"Time",OBJPROP_BGCOLOR,clrGreen); //--- set border color ObjectSetInteger(0,"Time",OBJPROP_BORDER_COLOR,clrGray); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"Time",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"Time",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"Time",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"Time",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"Time",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"Time",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////Date ObjectCreate(0,"Date",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"Date",OBJPROP_XDISTANCE,150); ObjectSetInteger(0,"Date",OBJPROP_YDISTANCE,20); //--- set button size ObjectSetInteger(0,"Date",OBJPROP_XSIZE,150); ObjectSetInteger(0,"Date",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"Date",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"Date",OBJPROP_TEXT,DoubleToString(Day(),0)+"/"+ DoubleToString(Month(),0)+"/"+DoubleToString(Year(),0)); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"Date",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"Date",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"Date",OBJPROP_BGCOLOR,clrRed); //--- set border color ObjectSetInteger(0,"Date",OBJPROP_BORDER_COLOR,clrGray); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"Date",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"Date",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"Date",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"Date",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"Date",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"Date",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////buy buton ObjectCreate(0,"Buy",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"Buy",OBJPROP_XDISTANCE,300); ObjectSetInteger(0,"Buy",OBJPROP_YDISTANCE,40); //--- set button size ObjectSetInteger(0,"Buy",OBJPROP_XSIZE,50); ObjectSetInteger(0,"Buy",OBJPROP_YSIZE,40); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"Buy",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"Buy",OBJPROP_TEXT,"Buy"); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"Buy",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"Buy",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"Buy",OBJPROP_BGCOLOR,clrGreen); //--- set border color ObjectSetInteger(0,"Buy",OBJPROP_BORDER_COLOR,clrGray); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"Buy",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"Buy",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"Buy",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"Buy",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"Buy",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"Buy",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////NextBuyLot ObjectCreate(0,"NextBuyLot",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"NextBuyLot",OBJPROP_XDISTANCE,250); ObjectSetInteger(0,"NextBuyLot",OBJPROP_YDISTANCE,40); //--- set button size ObjectSetInteger(0,"NextBuyLot",OBJPROP_XSIZE,100); ObjectSetInteger(0,"NextBuyLot",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"NextBuyLot",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"NextBuyLot",OBJPROP_TEXT,DoubleToString(BuyLot,2)); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"NextBuyLot",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"NextBuyLot",OBJPROP_COLOR,clrBlack); //--- set background color ObjectSetInteger(0,"NextBuyLot",OBJPROP_BGCOLOR,clrBeige); //--- set border color ObjectSetInteger(0,"NextBuyLot",OBJPROP_BORDER_COLOR,clrGreen); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"NextBuyLot",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"NextBuyLot",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"NextBuyLot",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"NextBuyLot",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"NextBuyLot",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"NextBuyLot",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////Sell buton ObjectCreate(0,"Sell",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"Sell",OBJPROP_XDISTANCE,50); ObjectSetInteger(0,"Sell",OBJPROP_YDISTANCE,40); //--- set button size ObjectSetInteger(0,"Sell",OBJPROP_XSIZE,50); ObjectSetInteger(0,"Sell",OBJPROP_YSIZE,40); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"Sell",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"Sell",OBJPROP_TEXT,"Sell"); //--- set text font // ObjectSetString(0,"Sell",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"Sell",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"Sell",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"Sell",OBJPROP_BGCOLOR,clrRed); //--- set border color ObjectSetInteger(0,"Sell",OBJPROP_BORDER_COLOR,clrGray); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"Sell",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"Sell",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"Sell",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"Sell",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Sell" in the object list ObjectSetInteger(0,"Sell",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"Sell",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////NextSellLot ObjectCreate(0,"NextSellLot",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"NextSellLot",OBJPROP_XDISTANCE,150); ObjectSetInteger(0,"NextSellLot",OBJPROP_YDISTANCE,40); //--- set button size ObjectSetInteger(0,"NextSellLot",OBJPROP_XSIZE,100); ObjectSetInteger(0,"NextSellLot",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"NextSellLot",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"NextSellLot",OBJPROP_TEXT,DoubleToString(SellLot,2)); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"NextSellLot",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"NextSellLot",OBJPROP_COLOR,clrBlack); //--- set background color ObjectSetInteger(0,"NextSellLot",OBJPROP_BGCOLOR,clrBeige); //--- set border color ObjectSetInteger(0,"NextSellLot",OBJPROP_BORDER_COLOR,clrGreen); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"NextSellLot",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"NextSellLot",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"NextSellLot",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"NextSellLot",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"NextSellLot",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"NextSellLot",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////NothingGreen ObjectCreate(0,"NothingGreen",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"NothingGreen",OBJPROP_XDISTANCE,250); ObjectSetInteger(0,"NothingGreen",OBJPROP_YDISTANCE,60); //--- set button size ObjectSetInteger(0,"NothingGreen",OBJPROP_XSIZE,20); ObjectSetInteger(0,"NothingGreen",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"NothingGreen",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"NothingGreen",OBJPROP_TEXT,""); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"NothingGreen",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"NothingGreen",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"NothingGreen",OBJPROP_BGCOLOR,clrGreen); //--- set border color ObjectSetInteger(0,"NothingGreen",OBJPROP_BORDER_COLOR,clrGreen); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"NothingGreen",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"NothingGreen",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"NothingGreen",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"NothingGreen",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"NothingGreen",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"NothingGreen",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////NothingBeige ObjectCreate(0,"NothingBeige",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"NothingBeige",OBJPROP_XDISTANCE,230); ObjectSetInteger(0,"NothingBeige",OBJPROP_YDISTANCE,60); //--- set button size ObjectSetInteger(0,"NothingBeige",OBJPROP_XSIZE,160); ObjectSetInteger(0,"NothingBeige",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"NothingBeige",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"NothingBeige",OBJPROP_TEXT,""); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"NothingBeige",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"NothingBeige",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"NothingBeige",OBJPROP_BGCOLOR,clrBeige); //--- set border color ObjectSetInteger(0,"NothingBeige",OBJPROP_BORDER_COLOR,clrGray); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"NothingBeige",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"NothingBeige",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"NothingBeige",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"NothingBeige",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"NothingBeige",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"NothingBeige",OBJPROP_ZORDER,0); //--- successful execution ///////////////////////////////////////////////////////////////////////////////////////////NothingRed ObjectCreate(0,"NothingRed",OBJ_BUTTON,0,0,0); //--- set button coordinates ObjectSetInteger(0,"NothingRed",OBJPROP_XDISTANCE,70); ObjectSetInteger(0,"NothingRed",OBJPROP_YDISTANCE,60); //--- set button size ObjectSetInteger(0,"NothingRed",OBJPROP_XSIZE,20); ObjectSetInteger(0,"NothingRed",OBJPROP_YSIZE,20); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"NothingRed",OBJPROP_CORNER,3); //--- set the text ObjectSetString(0,"NothingRed",OBJPROP_TEXT,""); //--- set text font // ObjectSetString(0,"Buy",OBJPROP_FONT,"); //--- set font size ObjectSetInteger(0,"NothingRed",OBJPROP_FONTSIZE,10); //--- set text color ObjectSetInteger(0,"NothingRed",OBJPROP_COLOR,clrWhite); //--- set background color ObjectSetInteger(0,"NothingRed",OBJPROP_BGCOLOR,clrRed); //--- set border color ObjectSetInteger(0,"NothingRed",OBJPROP_BORDER_COLOR,clrGray); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"NothingRed",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"NothingRed",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"NothingRed",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"NothingRed",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object "Buy" in the object list ObjectSetInteger(0,"NothingRed",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"NothingRed",OBJPROP_ZORDER,0); //--- successful execution return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Day() { MqlDateTime tm; TimeCurrent(tm); return(tm.day); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Hour() { MqlDateTime tm; TimeCurrent(tm); return(tm.hour); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Minute() { MqlDateTime tm; TimeCurrent(tm); return(tm.min); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Month() { MqlDateTime tm; TimeCurrent(tm); return(tm.mon); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Seconds() { MqlDateTime tm; TimeCurrent(tm); return(tm.sec); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Year() { MqlDateTime tm; TimeCurrent(tm); return(tm.year); }I will be thankful if you gave a a solution for that.
Here is my EA mql 5 code simplified, Iknow it will helps a lot of traders like me.
I will be thankful if you gave a a solution for that.Testing it, the problem is like stated above https://www.mql5.com/en/forum/384269#comment_26534093
How would it get here
////////////////////////////////////////////////////////////////Buy if(ObjectGetInteger(0,"Buy",OBJPROP_STATE)) { // The program is not getting to this stage, since it does know it is suppose to start the process with mouse click Trade.Buy(NormalizeDouble(BuyLot,2),NULL,Ask,0,0,""); a =0; ObjectSetInteger(0,"Buy",OBJPROP_STATE,false); } ////////////////////////////////////////////////////////////////Sell if(ObjectGetInteger(0,"Sell",OBJPROP_STATE)) { // Similarly, with the object clicked on the chart, it is not getting here as well Trade.Sell(NormalizeDouble(SellLot,2),NULL,Bid,0,0,""); ObjectSetInteger(0,"Sell",OBJPROP_STATE,false); }
I did not try it in tester mode
if you try it like this you would better understand why you need the onChartEvent, or you could think of what would start the object searching function
bool a = false; void OnTick() { //--- . . . a = false; ////////////////////////////////////////////////////////////////Buy while(a==false){ if(ObjectGetInteger(0,"Buy",OBJPROP_STATE)) { Trade.Buy(NormalizeDouble(BuyLot,2),NULL,Ask,0,0,""); ; ObjectSetInteger(0,"Buy",OBJPROP_STATE,false); a = true; } ////////////////////////////////////////////////////////////////Sell if(ObjectGetInteger(0,"Sell",OBJPROP_STATE)) { Trade.Sell(NormalizeDouble(SellLot,2),NULL,Bid,0,0,""); ObjectSetInteger(0,"Sell",OBJPROP_STATE,false); a = true; } }
Your output would looking like the below
- 2021.12.17
- www.mql5.com
Testing it, the problem is like stated above https://www.mql5.com/en/forum/384269#comment_26534093
How would it get here
I did not try it in tester mode
if you try it like this you would better understand why you need the onChartEvent, or you could think of what would start the object searching function
Your output would looking like the below
Thanks for the respond,
There is a lot of MANUAL BACKTESTING EAs that works well in mt5 testing mode, so logicaly there is a methode of doing it without calling the OnChartEvent which can't be used on testing mode;
I am just a beginer trader, don't know how to code correctly with understanding, I just try to applicat what I see in not many videos on youtube...
It is sad that mql5 programers don't share thier knowledge here,
I came up with a little solution here, it may work well on testing mode as on live mode.
Instead of using ObjectCreate function I will use the O.O.P as bellow:
#include<Controls\Button.mqh>
CButton Buy;
CButton Sell;
the Creation of objects
void Object() { Buy.Create(0,"Buy",0,250,40,200,80); Buy.Text("Buy"); Buy.FontSize(10); Buy.Color(clrWhite); Buy.ColorBackground(clrGreen); Buy.ColorBorder(clrGray); Buy.Activate(); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"Buy",OBJPROP_CORNER,3); Sell.Create(0,"Sell",0,00,40,-50,80); Sell.Text("Sell"); Sell.FontSize(10); Sell.Color(clrWhite); Sell.ColorBackground(clrRed); Sell.ColorBorder(clrGray); Sell.Activate(); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"NegatifBuy",OBJPROP_CORNER,3); }
and on the Ontick function I replaced the ObjectGetInteger check function with this
////////////////////////////////////////////////////////////////Buy if(Buy.Pressed()) { Trade.Buy(NormalizeDouble(BuyLot,2),NULL,Ask,0,0,""); Buy.Pressed(false); } ////////////////////////////////////////////////////////////////Sell if(Sell.Pressed()) { Trade.Sell(NormalizeDouble(SellLot,2),NULL,Bid,0,0,""); Sell.Pressed(false); }
It works Very well on the live mode but on the Testing mode I need to click on the lower right corner of the object , may be I need to adjust some object proprieties wich I don't know how to do it yet.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I use in my mql5 EA ;to avoid the OnChartEvent's call; the following code
But when i press the buton "Buy" the fuction does not work well, it might enter a trade but ofen not!!!( It seems thatthe buton can't be often bushed )
knowing that it works very well in mql4
is there any solution for that?