Please run this code and show the result.
//+------------------------------------------------------------------+ //| Test MA200.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.000" //--- input parameters input int Inp_MA_ma_period = 200; // MA: averaging period input int Inp_MA_ma_shift = 5; // MA: horizontal shift input ENUM_MA_METHOD Inp_MA_ma_method = MODE_SMA; // MA: smoothing type input ENUM_APPLIED_PRICE Inp_MA_applied_price = PRICE_CLOSE; // MA: type of price //--- int handle_iMA; // variable for storing the handle of the iMA indicator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create handle of the indicator iMA handle_iMA=iMA(Symbol(),Period(),Inp_MA_ma_period,Inp_MA_ma_shift, Inp_MA_ma_method,Inp_MA_applied_price); //--- if the handle is not created if(handle_iMA==INVALID_HANDLE) { int bars=Bars(Symbol(),Period()); //--- tell about the failure and output the error code PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d, all bars %d, 'MA: averaging period' %d", Symbol(), EnumToString(Period()), GetLastError(), bars, Inp_MA_ma_period); //--- the indicator is stopped early return(INIT_FAILED); } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- int a=BarsCalculated(handle_iMA); if(a<0) { int bars=Bars(Symbol(),Period()); PrintFormat("BarsCalculated return '-1', all bars %d, 'MA: averaging period' %d",bars,Inp_MA_ma_period); } else Print("BarsCalculated: ",a); } //+------------------------------------------------------------------+
Also show the chart parameters:
Please run this code and show the result.
Also show the chart parameters:
This is what I have received from the logs, I have attached the log file but I had to delete some of it, but it was the same thing all the way to the end.
Thanks for your help.
This is what I have received from the logs, I have attached the log file but I had to delete some of it, but it was the same thing all the way to the end.
Thanks for your help.
How do you want to calculate a MA200 when you have 102/103 bars on your chart ?
As I said I had to shorten the logs because it doesnt let me post the whole file, this is the EOF:
As I said I had to shorten the logs because it doesnt let me post the whole file, this is the EOF:
This is what I have received from the logs, I have attached the log file but I had to delete some of it, but it was the same thing all the way to the end.
Thanks for your help.
You have no bars.
Here is the line:
GR 0 09:03:11.518 Core 1 2017.09.20 01:00:00 BarsCalculated return '-1', all bars 102, 'MA: averaging period' 200
Increase the number of bars that are displayed on the chart.
The number of bars is important at the time of creating the indicator handle: at the time of creation of iMA (200) you have only 100 bars.
Add the error number to the log.
Did you restart the terminal after changing the settings?
- 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 guys,
I have a problem as on my computer this is not working but on other friend's computer it is working, any idea?
Please help, as I need MA200 for one of my strategies but it doesnt work.
barsCalculated is always show -1 for any MA more than 100 .
I have tested this with different brokers, different time frames and different instruments but still the same thing.