Custom Indicator Not showing correct Values of the Trendline

 

Hi All,

So I have this simple code that Alerts the Value of DEMA.

However when you look at the chart the trendline doesn't seem to hit the correct value of DEMA.

Here's the simple code:

#property copyright "Copyright 2020, Arcee P. Palabrica"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

 extern int DEMAPeriod = 20;

void OnTick()
  {
  if(isNewCandle())
    {
     double valueofDEMA = iCustom(NULL, 0, "DEMA", DEMAPeriod, 0, 0);
     Alert("DEMA @ ", Time[0], " is ", valueofDEMA);
    }
     
  
  }

  
  bool isNewCandle()
  {
   static datetime saved_candle_time;
   
   if(Time[0] ==  saved_candle_time)
     {
      return false;
     }
   else
     {
      saved_candle_time = Time[0];
      return true;
     }
  
  }

But this is how it's shown in the chart. (please see attached screen shot)


At 2019.01.02 00:00:00 the trendline should be 1.27189266216272. But it sits around 30 pips lower that where it should be.

Thanks in advance.

 
Arcee Palabrica:

Hi All,

So I have this simple code that Alerts the Value of DEMA.

However when you look at the chart the trendline doesn't seem to hit the correct value of DEMA.

Here's the simple code:

But this is how it's shown in the chart. (please see attached screen shot)


At 2019.01.02 00:00:00 the trendline should be 1.27189266216272. But it sits around 30 pips lower that where it should be.

Thanks in advance.

double valueofDEMA = iCustom(NULL, 0, "DEMA", DEMAPeriod, 0, 1);
valueofDEMA = NormalizeDouble(valueofDEMA, _Digits);

try setting the value to 1 bar

 
double valueofDEMA = iCustom(NULL, 0, "DEMA", DEMAPeriod, 0, 0);

You are passing one parameter. We have no idea which DEMA you are using. This one, for example has price first then length.
          'Double Smooothed EMA' indicator by 'mladen' for MetaTrader 5 in the MQL5 Code Base

 
Pavel Shutovskiy:

try setting the value to 1 bar

Thanks so much. And I've also learned normalize. Thanks for that as well
 
William Roeder:

You are passing one parameter. We have no idea which DEMA you are using. This one, for example has price first then length.
          'Double Smooothed EMA' indicator by 'mladen' for MetaTrader 5 in the MQL5 Code Base

This indicator looks promising. I'll make another ea using this one. Thank you 
 
Arcee Palabrica:

In future please post in the correct section.

I will move this to the MQL4 and MT4 section

Reason: