Hi All,
I've been trying to open a chart and then plot a moving average from inside a script.
This is my simple code:
But .... no joy.
What have I missed?
Cheers
@Graham from Brisbane, @Graham Webber
It is against the rules to have multiple MQL5 Community Accounts. You can only have one account.
Please close down the extra account(s). You can contact the Service Desk and request that the it be deleted so that only one remains.
Terms of Use of MQL5 community12.11. The User shall use only one unique MQL5 ID on the www.mql5.com website. In case additional/repeated User accounts are detected, all of them shall be closed. MetaQuotes Ltd also reserves the right to invalidate all payment transactions made from additional/repeated accounts.
Sorry about that. I've had the Graham from Brisbane account for years. Today is the first time I've seen the Graham Webber account. Very confusing. I think it happened as a result of signing in via Gmail. Anyhow, I don't want two accounts, either, it's too confusing. I'll delete that account as soon as I can.
Meanwhile, I've seen heaps of posts from you, perhaps you could give me a clue as to how to solve my problem. Wow, MQL4 to MQL5 isn't easy for a guy my age ..... :)
Problems in your code:
- Not checking return values
- Not checking for error codes
- Using different symbol for chart and indicator
Sample code (compiled and tested) ...
void OnStart() { string sSymbol = "EURUSD"; ENUM_TIMEFRAMES eTimeFrame = PERIOD_H1; ResetLastError(); long nChartID = ChartOpen( sSymbol, eTimeFrame ); if( nChartID > 0 ) { ResetLastError(); int hMA = iMA( sSymbol, eTimeFrame, 21, 0, MODE_SMA, PRICE_CLOSE ); if( hMA != INVALID_HANDLE ) { ResetLastError(); if( ChartIndicatorAdd( nChartID, 0, hMA ) ) { // do something } else Print( "Unable to add indicator handle with error: ", _LastError ); } else Print( "Unable to obtain indicator handle with error: ", _LastError ); } else Print( "Unable to open chart with error: ", _LastError ); };
Thanks for the help, I've just learned a few new things.
BTW, 76 next February, but still trying hard ... :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I've been trying to open a chart and then plot a moving average from inside a script.
This is my simple code:
But .... no joy.
What have I missed?
Cheers