Overlay Chart

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
I need to speed up normal backtesting (without Visualization).
OverlayChart[0] is the current value of the indicator which is around 1.2443.
If all I need current value of the indicator as shown in the chart,
how to modify the code to speed up the backtesting (without Visualization)?

Screen_Shot_2016_07_22_at_1_03_46_PM.png
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
The indicator uses 4 output buffers. I have no idea, which one of those your EA is writing into OverlayChart[] array. Anyway, for your purpose, you can remove all the parts of the indicator that deal with graphical objects. It will speed it up.
 

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
This is the code. Which one of the output buffer did I used?

MQL5:
double OverlayChart1[];
int OverlayChart_Handle = 0;
 
   ResetLastError();
   OverlayChart_Handle =  iCustom(
                          Symbol_1,
                          PERIOD_D1,
                          "Examples\OverlayChart",
                          Overlay_Symbol,         
                          false,
                          DRAW_COLOR_CANDLES,
                          clrBlack,
                          PRICE_CLOSE
                 );
   Print("OverlayChart_Handle =",OverlayChart_Handle,"  error =",GetLastError());
   ResetLastError();
 
ArraySetAsSeries(OverlayChart1, true);
   if (CopyBuffer(OverlayChart_Handle,0,0,100,OverlayChart1) < 0){Print("CopyBufferOverlayChart1 error =",GetLastError());}
 

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
What is the formula of getting current value of the indicator?
i.e.
When EURUSD is around 1.09726
and CHFJPY is around 107.262
How did the indicator overlay on chart of EURUSD at the value of around 1.12443?
And the indicator seems to work with any pairs.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
According to this, you are copying the buffer #0:
MQL5:
   if (CopyBuffer(OverlayChart_Handle,0,0,100,OverlayChart1) < 0){Print("CopyBufferOverlayChart1 error =",GetLastError());}
It's Open of the overlaid symbol's candle. This means that you can remove any calculations not related to calculation of O[] from the indicator if you want to speed it up.

How did the indicator overlay on chart of EURUSD at the value of around 1.12443?
It just scales the values according to the current symbol's high/low on the current window. That's why I just don't understand who in their sane mind would use it in expert advisor for trading.

The main formula is this:
MQL5:
_PipsRatio = (_CurRangeHigh - _CurRangeLow) / (_SubRangeHigh - _SubRangeLow);

It calculates the ratio to convert overlaid symbol's quote to current symbol's price range.
 

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
i.e.
I realized that OverlayChart[0] is taking the value of CHFJPY which is around 107.262
instead of the indicator's value of around 1.12443 when overlaid on the EURUSD chart.
Do you know how to get the indicator's value of around 1.12443.
Thank you!
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
You would need to use the whole code starting from the beginning of the OnCalculate() function through _PipsRatio calculation and then also add all the necessary functions to get current OHLC timeseries because you do not have in MT5 in EAs (unlike indicators). It probably would be easier to "lighten up" the indicator instead of adding the code to an EA. But I would not bother with this folly at all.
 

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
OverlayChart[0] is getting the Open value of CHFJPY which is around 107.262
instead of the indicator's value of around 1.12443 when overlaid on the EURUSD chart.
 

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
I got error "array out of range" error for this line:

_CurRangeHigh = High[ArrayMaximum(High, _LastBar, _BarsCount)];

How to correct it?
 

johnnybegoode

Trader
Jul 19, 2016
56
0
22
47
Error was from the strategy tester when I tried to call the value of O[0] or _PipsRatio.
Anyway that is irrelevant now as I believe that more external buffers are needed for the calculated values.

In order to get the value of O[0] that I wanted, there has to be some sort of External Buffer for that calculated value other than the original O, H, L, and C whose value can be obtained without using the indicator in the first place.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
Error was from the strategy tester when I tried to call the value of O[0] or _PipsRatio.
Probably because ChartGetInteger(0, CHART_VISIBLE_BARS) and ChartGetInteger(0, CHART_FIRST_VISIBLE_BAR) do not work in tester.

In order to get the value of O[0] that I wanted, there has to be some sort of External Buffer for that calculated value other than the original O, H, L, and C whose value can be obtained without using the indicator in the first place.

O[] is an external buffer. ExtBuffer is just another way to name the variable. You can rename O, H, L, and C to ExtBuffer1, ExtBuffer2, ExtBuffer3, and ExtBuffer4 if it will make you feel better.