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[])
 

@Stanislav Korotky, Thank you for directing me to the documentation. The "first form" is highly useful for copying future buffer values─especially on custom charts.

@Vladimir, Thank you, albeit belatedly, for posting your source code of this indicator. I had no idea how valid such price patterns from decades ago could be today. I used it to catch 2 winning trades right out of the gate. One was circa 1999, and the other was circa 2005.

Here is the indicator code that I am using now (with the GV removed):

 

It's conceivable that a new price pattern having the same start time but a different end time as the current pattern could emerge, so I added pattern end time to the conditional ChartRedraw() function─attached. Either a start time difference or an end time difference will call ChartRedraw().

 

This indicator can be tested

It is necessary to add two vertical lines to the indicator - the beginning of calculation and the end of calculation

And you can immediately see where the red line will be and how the chart was formed, i.e. is the forecast workable?

 
Renat Akhtyamov #:

This indicator can be tested

It is necessary to add two vertical lines to the indicator - the beginning of calculation and the end of calculation

And you can immediately see where the red line will be and how the chart was formed, i.e. is the forecast workable?

That is the purpose of the blue line that draws open prices of the historic pattern as an overlay.
 
Here's a "stupid simple" bar open price indicator to go apples-to-apples, if you will, with the historic blue line.