Forum on trading, automated trading systems and testing trading strategies
Learning to code. Need help with this.
Vladimir Karputov, 2020.08.20 15:39
You are making a gross mistake: in MQL5, the work with receiving indicator data is divided into two steps. Step 1: create the HANDL of the indicator (THIS IS DONE ONLY ONCE - In OnInit !!!). Step 2: get the data (as a rule, this is done in OnTick ().
And by the way, the CTrade trading class is the easiest way. Nothing is easier!
Correct the errors and I'll show you the lightweight code.int didi = iCustom(_Symbol, _MA_Fast.Period(), "/Indicators/Market/Didi Index", _MA_Fast.MaPeriod(), _MA_Medium.MaPeriod(), _MA_Slow.MaPeriod(), _MA_Fast.MaMethod(), _MA_Fast.Applied());
Check your return codes, and report your errors. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- 2020.08.20
- www.mql5.com
Hi,
I just found the issue.
To help debug first I changed my code to:
int didi = iCustom(_Symbol, _MA_Fast.Period(), "/Indicators/Market/Didi Index", _MA_Fast.MaPeriod(), _MA_Medium.MaPeriod(), _MA_Slow.MaPeriod(), _MA_Fast.MaMethod(), _MA_Fast.Applied()); if (didi == INVALID_HANDLE) { Print("Failed to create indicator DIDI"); } else { Print("Trying to add handle for didi"); if (!ChartIndicatorAdd(chart_id, windows, didi)) { Print("Failed to add indicator didi - "+string(GetLastError()) + "("+string(chart_id)+","+string(windows)+")"); } } if (_MA_Fast.Handle() == INVALID_HANDLE) { Print("Failed to create handle _MA_Fast"); } else { Print("Trying to add handle for _MA_Fast"); if (!ChartIndicatorAdd(chart_id, windows-1, _MA_Fast.Handle())) { Print("Failed to add indicator _MA_Fast - "+string(GetLastError()) + "("+string(chart_id)+","+string(windows)+")"); } } if (_MA_Medium.Handle() == INVALID_HANDLE) { Print("Failed to create handle _MA_Medium"); } else { Print("Trying to add handle for _MA_Medium"); if (!ChartIndicatorAdd(chart_id, windows-1, _MA_Medium.Handle())) { Print("Failed to add indicator _MA_Medium - "+string(GetLastError()) + "("+string(chart_id)+","+string(windows)+")"); } } if (_MA_Slow.Handle() == INVALID_HANDLE) { Print("Failed to create handle _MA_Slow"); } else { Print("Trying to add handle for _MA_Slow"); if (!ChartIndicatorAdd(chart_id, windows-1, _MA_Slow.Handle())) { Print("Failed to add indicator _MA_Slow - "+string(GetLastError()) + "("+string(chart_id)+","+string(windows)+")"); } } ChartRedraw(chart_id);
Which then produces the logs:
The chart id there is Bizarre, did not notice the error code 4101 before.
I just replaced ChartId() with a static 0 and it started working again.
For me this is sufficient and now my indicators are appearing nicely again! :)
ChartId() was returning "972554837" rather than 0. I was casting it to (int) rather than (long). Silly mistake.
Thanks very much for your time, regardless. Your comments made me realise this.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
I have an EA that makes usage of some moving averages and a custom indicator. The moving averages are actively used on my algorithms and they work fine, but when I try to add them to my charts they do not appear. The custom indicator I add is not actively used on my algorithms, but it greatly helps understand the functioning of my EA, and it also does not show up.
It's odd because some time ago it used to appear intermitently, but now my indicators usually do not appear.
This is the routine I use to add my indicators to my chart:
The code above is redacted to show only the relevant bits.
Is there any reason this would not work to show these indicators after I drag my EA to a symbol chart? Sometimes these intermitently work on strategy tester visualizations, which is curious.
Thanks,
Fernando