Need help with moving average distance calculations looks liek a Bug - page 2

 
nadiawicket:

all I get is a weird 2123412.34 value, which ive included in the Screenshot (more wine glitch or not.png).

The value 2147483647 (shown in your screenshot) is EMPTY_VALUE.

Y‌ou are getting it because there are no buffers in average.mq4, so you can't use iCustom.

Given that the correct values are shown in your comment, it suggests the problem is with your code not with Wine.

 
//+------------------------------------------------------------------+
//|                                                      average.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
double average1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
IndicatorBuffers(1);
SetIndexBuffer(1, average1);
SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,2);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   average1[1] =iMA(_Symbol,1,2,0,MODE_LWMA,PRICE_CLOSE,0);
   Comment(DoubleToString(average1[1] ,_Digits));

//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Any idea why its not displaying the correct value in the buffer field? Attached screenshot of missing value in buffer field
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
nadiawicket:
Any idea why its not displaying the correct value in the buffer field? Attached screenshot of missing value in buffer field


As you do more MQL coding, you'll find it invaluable to use the Experts log in the Terminal.

Your code has an "array out of range" error.

//+------------------------------------------------------------------+
//|                                                      average.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
double average1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
IndicatorBuffers(1);
SetIndexBuffer(0, average1);
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   average1[0] =iMA(_Symbol,1,2,0,MODE_LWMA,PRICE_CLOSE,0);
   Comment(DoubleToString(average1[0] ,_Digits));

//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+  

 

Can't thank you enough for your help. Ill have to use the forums more, this is priceless.‌

‌Issue completely resolved.

 
nadiawicket:
Can't thank you enough for your help.


I'm glad you got it sorted.

Now that it is working, there really is no need to use iCustom and a separate indicator.

J‌ust splice that code directly into your EA.

 
Excellent.