Indicators: Price prediction by Nearest Neighbor found by a weighted correlation coefficient - page 3

 
Amos Tsopotsa #:

this code needs slight improvements but  okayjustask your idea does make sense 

I made very slight improvements to the code by:

  • Adding a variable on the global scope for b, and
  • Adding a lastPatternStartTime variable, a condition that compares it to a new pattern start time, and calls ChartRedraw() if they're not the same.
(From what I was able to discern in a few hours of testing, the vertical line chaos appeared when a new pattern was found).
 

A couple more slight improvements:

  • Changed OnInit() from a void to an int, so it returns INIT_SUCCEEDED now,
  • Added a terminal-wide GlobalVariable (GV) that stores the first future price value of the indicator (CopyBuffer() doesn't work in an EA with "future indicator Buffer values"), and
  • Added OnDeinit() wherein the GV is automatically deleted from the terminal.

The purpose of those changes is to make the indicator more suitable for automated trading. If you need more future price values for your purposes, just loop through bars 0 to 48 at the end of the code and update the GV value.

 
Ryan L Johnson #:


  • Added a terminal-wide GlobalVariable (GV) that stores the first future price value of the indicator (CopyBuffer() doesn't work in an EA with "future indicator Buffer values"),

The purpose of those changes is to make the indicator more suitable for automated trading. If you need more future price values for your purposes, just loop through bars 0 to 48 at the end of the code and update the GV value.

Why is that? You can access any values from indicator buffers even from the future.
MQL5 Book: Getting timeseries data from an indicator: CopyBuffer / Creating application programs
MQL5 Book: Getting timeseries data from an indicator: CopyBuffer / Creating application programs
  • www.mql5.com
An MQL program can read data from the indicator's public buffers by its handle. Recall that in custom indicators, such buffers are arrays specified...
 
Stanislav Korotky #:
Why is that? You can access any values from indicator buffers even from the future.

I've been able to do that in indicators but not in EA's. Do you have another example/Article that does so in an EA, please?

 
Ryan L Johnson #:

I've been able to do that in indicators but not in EA's. Do you have another example/Article that does so in an EA, please?

Please disregard my Post #24. I suspect that I've been using the wrong form of Copybuffer() in an EA. The correct one appears to be:

"[I]n the parameters CopyBuffer (first form) one must give offset equal to (- N)..."

int CopyBuffer(int handle, int buffer, int offset, int count, double &array[])