How can I run the function with a button without waiting for a tick change for OnCalculate to work? [MT5]
- How do I create a function to process each millisecond?
- Questions from Beginners MQL5 MT5 MetaTrader 5
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
void OnChartEvent(const int id, const long & lparam, const double & dparam, const string & sparam) { if(id == CHARTEVENT_OBJECT_CLICK) { if(sparam == "Button") { datetime time[]; double open[],high[],low[],close[]; long tick_volume[],volume[]; int spread[]; CopyTime(NULL,0,0,Bars,time); ArraySetAsSeries(time,true); CopyOpen(NULL,0,0,Bars,open); ArraySetAsSeries(open,true); CopyHigh(NULL,0,0,Bars,high); ArraySetAsSeries(high,true); CopyLow(NULL,0,0,Bars,low); ArraySetAsSeries(low,true); CopyClose(NULL,0,0,Bars,close); ArraySetAsSeries(close,true); CopyTickVolume(NULL,0,0,Bars,tick_volume); ArraySetAsSeries(tick_volume,true); CopyRealVolume(NULL,0,0,Bars,volume); ArraySetAsSeries(volume,true); CopySpread(NULL,0,0,Bars,spread); ArraySetAsSeries(spread,true); OnCalculate(Bars,0/*else 1*/,time,open,high,low,close,tick_volume,volume,spread); } } }
Why don't you create the button in OnInit and run the timeseries copy functions in OnCalculate and have the OnChartEvent do only the action that is called when the button is clicked?
I was tired and sleepless while opening the topic, it never occurred to me. :) And then I rearranged it as you wrote. Thank you :)
Edit: Of course, when I did this, my reason for opening the subject did'nt completely disappear. For example, when the market is closed on the weekend, there will be no tick data. The function I want to run only when I press the button will not work even if I click the button. Because I want the function to run only when I click the button, not when prev_calculate is equal to zero.
The button click triggers a chart event. OnCalculate and prev_calculate are irrelevant.
Perhaps you should read the manual.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use