Different Indicator Data in EA versus main Chart

 

Hi All,


I am a new Metatrader user who has some experience of coding, and am having a problem

I have a custom indicator that calculates the daily pivot points (R3, R2, R1, PP, S1, S2, S3) for the currency pair I am looking at. I am currently looking at 5 minute data. I have manually verified the levels, and everything appears to display correctly on the main charts.

I am trying to use these values within an EA to help generate entry and exit signals. I am using icustom to pull in the relevant 7 buffers from the custom indicator.  For example:

double PP=iCustom(NULL,0,"PIVOT POINTS",0,3,0);  // Calls Daily Pivot Point

Buffers range from Buffer0 (R3) down to Buffer6 (S3)

Buffer 3 is the fourth Buffer, so it is correctly looking at the pivot point. The Indicator is correctly named, and there are no external variables that need to be passed through to the indicator.


When I run the EA in visual mode, the Pivot points plotted on the new chart are very different from those on the main chart, even though the prices used to calculate the pivots are the same on each chart. Strangely, the few days of data displayed before the start of the EA seem to match up. But as soon as the EA starts, the values start to move away. The EA is using these incorrect values for trading triggers, and so it returns useless results.

Does anyone have any idea why the values pulled through in the EA would be different to those plotted directly by the custom indicator?

 
HorizonT:

Hi All,


I am a new Metatrader user who has some experience of coding, and am having a problem

I have a custom indicator that calculates the daily pivot points (R3, R2, R1, PP, S1, S2, S3) for the currency pair I am looking at. I am currently looking at 5 minute data. I have manually verified the levels, and everything appears to display correctly on the main charts.

I am trying to use these values within an EA to help generate entry and exit signals. I am using icustom to pull in the relevant 7 buffers from the custom indicator.  For example:

double PP=iCustom(NULL,0,"PIVOT POINTS",0,3,0);  // Calls Daily Pivot Point

This is the value from your Indicator for buffer 3  for Bar 0 . . .  do you always have a pivot point on bar 0 ?  if you did you would have a pivot point on every single bar . . .   can you also confirm that your indicator only has one extern variable and you are happy to have it set to 0 ?
 
RaptorUK:
This is the value from your Indicator for buffer 3  for Bar 0 . . .  do you always have a pivot point on bar 0 ?  if you did you would have a pivot point on every single bar . . .   can you also confirm that your indicator only has one extern variable and you are happy to have it set to 0 ?

Hi Raptor,


Thanks for your swift reply.

The Indicator does indeed display the pivot point for each Bar, for all data periods shown in the chart - It shows the pivot point for every trading day. Although I previously said that there are no external variables, I can confirm that there is 1, but that the value should be zero, so this is correct.

 
I once downloaded a pp indicator which showed different results in testing than on the live chart. It was a while ago, and I forget the specifics. I think I traced the problem to the use of iBarShift though. I think it also had something to do with the small number of bars pre-loaded in the tester. Sorry I can't be more specific, but that might set you down the right path - especially if you happened to download the same one that I did.
 
clerin6:
I once downloaded a pp indicator which showed different results in testing than on the live chart. It was a while ago, and I forget the specifics. I think I traced the problem to the use of iBarShift though. I think it also had something to do with the small number of bars pre-loaded in the tester. Sorry I can't be more specific, but that might set you down the right path - especially if you happened to download the same one that I did.


Many thanks clerin, my PP indicator does include iBarShift, so will have a look at this . . .
 
HorizonT:

Hi Raptor,

Thanks for your swift reply.

The Indicator does indeed display the pivot point for each Bar, for all data periods shown in the chart - It shows the pivot point for every trading day. Although I previously said that there are no external variables, I can confirm that there is 1, but that the value should be zero, so this is correct.

So every bar has a Pivot Point value ?  and I guess the value for bar 0 repaints as the bar is being drawn ?  can you either show the code for the Indicator, tell me where I can download it if it's free, or tell me the pivot point values (buffer 3) from this indicator for bars 1,2,3 and 4 for any chart you care to place it on.
 

Hi Raptor,

sorry for the delay in replying. I have found a far simpler piece of code that generates the pivot points within the EA, rather than calling from outside, and this has solved all of the problems.

Reason: