EA indicator vs Chart value

 

If this is in the wrong place, please move, thanks.

I am using an indicator (Trend Direction and Force Index) which I downloaded from https://www.mql5.com/en/code/22976.

My problem is that when I see the values on the chart (and using a Script), they are not the same as when I run an EA.  Can someone please advise what the problem may be ?

Attached image of strategy test visualisation and source code.

TIA

Trend direction and force - DSEMA smoothed
Trend direction and force - DSEMA smoothed
  • www.mql5.com
Trend direction and force - double smoothed EMA smoothed
Files:
tdfi.jpg  158 kb
tdfi_test.mq5  2 kb
 

It is really annoying.  The chart is different than the data.   I saw this issue as well.  What I did was print the values I want to look at for each candle and than compare it to the chart value by putting my mouse pointer over the candle on the chart.    They are different.   I think this is a bug in MT5.

Does any one else have a comment?   I would love to hear a better explanation. 

Chris

 
ChesMT5:

If this is in the wrong place, please move, thanks.

I am using an indicator (Trend Direction and Force Index) which I downloaded from https://www.mql5.com/en/code/22976.

My problem is that when I see the values on the chart (and using a Script), they are not the same as when I run an EA.  Can someone please advise what the problem may be ?

Attached image of strategy test visualisation and source code.

TIA

The data window is showing the value at the bar where your cross hair is.

Edit - I realized you are running it in strategy tester.

You are having different values because you are copying value at the open of the new candle where as the indicator is showing value at the close of the candle

 
Navdeep Singh #:

The data window is showing the value at the bar where your cross hair is.

Edit - I realized you are running it in strategy tester.

You are having different values because you are copying value at the open of the new candle where as the indicator is showing value at the close of the candle

Thanks Navdeep Singh.  I tried [0], [1] and neither matches.  I posted my code - perhaps you could tell me how to change it please - I'll put it below as well ?


void OnTick() {

   if (!IsNewBar(true)) {

      tm=(datetime)SymbolInfoInteger(_Symbol,SYMBOL_TIME);

      return;   

   }

   ResetLastError();

   int cnt = CopyBuffer(tdfi_handle, 0, 0, 1, tdfi_Buffer);

   int error1 = GetLastError();

   ResetLastError();

   tdfi_Val = NormalizeDouble(tdfi_Buffer[0], 6);

   sdebug = "Error " + error1 + ", tdfi_Val " + tdfi_Val;

   Print(sdebug);


}


bool IsNewBar(bool first_call = false){


   static bool result = false;

   if (!first_call) return(result);

   

   static datetime previous_time = 0;

   datetime current_time = iTime(_Symbol, Period(), 0);

   result = false;

   if (previous_time != current_time){

      previous_time = current_time;

      result = true;

   }

   return (result);

}

 
ChesMT5 #:

Thanks Navdeep Singh.  I tried [0], [1] and neither matches.  I posted my code - perhaps you could tell me how to change it please - I'll put it below as well ?


void OnTick() {

   if (!IsNewBar(true)) {

      tm=(datetime)SymbolInfoInteger(_Symbol,SYMBOL_TIME);

      return;   

   }

   ResetLastError();

   int cnt = CopyBuffer(tdfi_handle, 0, 0, 1, tdfi_Buffer);

   int error1 = GetLastError();

   ResetLastError();

   tdfi_Val = NormalizeDouble(tdfi_Buffer[0], 6);

   sdebug = "Error " + error1 + ", tdfi_Val " + tdfi_Val;

   Print(sdebug);


}


bool IsNewBar(bool first_call = false){


   static bool result = false;

   if (!first_call) return(result);

   

   static datetime previous_time = 0;

   datetime current_time = iTime(_Symbol, Period(), 0);

   result = false;

   if (previous_time != current_time){

      previous_time = current_time;

      result = true;

   }

   return (result);

}

void OnTick() {

   if (!IsNewBar(true)) {

      tm=(datetime)SymbolInfoInteger(_Symbol,SYMBOL_TIME);

      return;   

   }

   ResetLastError();

   int cnt = CopyBuffer(tdfi_handle, 0, 1, 1, tdfi_Buffer); // Copy value for the closed bar

   int error1 = GetLastError();

   ResetLastError();

   tdfi_Val = NormalizeDouble(tdfi_Buffer[0], 6);

   sdebug = "Error " + error1 + ", tdfi_Val " + tdfi_Val;

   Print(sdebug);



}



bool IsNewBar(bool first_call = false){



   static bool result = false;

   if (!first_call) return(result);

   

   static datetime previous_time = 0;

   datetime current_time = iTime(_Symbol, Period(), 0);

   result = false;

   if (previous_time != current_time){

      previous_time = current_time;

      result = true;

   }

   return (result);

}

Use source button to enter source code properly

 
Navdeep Singh #:

Use source button to enter source code properly

OK, will do so if I post anything else.

Thank you - that must be the only thing I didn't try so I've spent a lot of time on this.

What a relief - you've saved what's left of my sanity !