I use a linear regression indicator (i-Regr) in my EA. Specifically, I use the slope of the linear regression.
I define the "slope" like this:
(where CurrentReg is the regression's value at the current bar's close price, and LastReg is the value of the previous bar's close price)
I made an expert advisor that prints a readout of slopes. The relevant statement looks like thiscode looks like this:
When run through the strategy tester on a specific time segment the following results are produced (MT4 console copy/paste):
I need to modify the indicator to let me to "bar shift" to any bar. For example, a "bar shift" of 1 should have 30.7395 as the last output instead of 30.2633.
Attempting to shift by incrementing the index shift property in the iCustom command does not do what I intend.
I tried to modify the i-Regr indicator to implement the type of "bar shift" that I require.
Here are the changes I made:
I tried calling the modified indicator like this:
(with shift = 1)
But I got inaccurate output when I tested it on the same timeframe.
I cannot understand why this happens, but I am guessing that it is because I missed something in the i-Regr code. What I want is for the final output to read as it did a bar back: 30.7395 . Instead it repeats an incorrect number twice.
If someone would please look at my modification and help me out with this, I would really appreciate it.
Attached is the original i-Regr indicator and my broken mod.
I define the "slope" like this:
Inserted Code
slope = MathAbs(1000000*(CurrentReg - LastReg)/Period());
I made an expert advisor that prints a readout of slopes. The relevant statement looks like thiscode looks like this:
Inserted Code
Print("Slope: ",MathAbs(1000000*( iCustom(Symbol(),0,"i-Regr",1,1,34,0,0,0)-iCustom(Symbol(),0,"i-Regr",1,1,34,0,0,1))/Period()));
When run through the strategy tester on a specific time segment the following results are produced (MT4 console copy/paste):
Inserted Code
2011.05.31 23:59 showslope EURUSD,M5: Slope: 30.2633 2011.05.31 23:55 showslope EURUSD,M5: Slope: 30.7395 2011.05.31 23:50 showslope EURUSD,M5: Slope: 30.2577 2011.05.31 23:45 showslope EURUSD,M5: Slope: 29.7591
I need to modify the indicator to let me to "bar shift" to any bar. For example, a "bar shift" of 1 should have 30.7395 as the last output instead of 30.2633.
Attempting to shift by incrementing the index shift property in the iCustom command does not do what I intend.
I tried to modify the i-Regr indicator to implement the type of "bar shift" that I require.
Here are the changes I made:
Inserted Code
1. Commented out SetIndexShift statements 2.... SetIndexDrawBegin(0, Bars-p-1[b][color="Red"]-shift[/color][/b][color="Red"][/color]); SetIndexDrawBegin(1, Bars-p-1[b][color="Red"]-shift[/color][/b][color="Red"][/color]); SetIndexDrawBegin(2, Bars-p-1[b][color="Red"]-shift[/color][/b][color="Red"][/color]); 3. Every instance of [b][color="Black"]Close[n][/color][/b][color="Black"][/color]) changed to: [b]Close[n[color="Red"]+shift[/color][/b][color="Red"][/color]])
I tried calling the modified indicator like this:
Inserted Code
Print("Slope: ",MathAbs(1000000*( iCustom(Symbol(),0,"i-Regr",1,1,34,[b][color="Red"]shift[/color][/b][color="Red"][/color],0,0)-iCustom(Symbol(),0,"i-Regr",1,1,34,[b][color="Red"]shift[/color][/b][color="Red"][/color],0,1))/Period()));
But I got inaccurate output when I tested it on the same timeframe.
Inserted Code
2011.05.31 23:59 showslope EURUSD,M5: Slope: 30.5434 2011.05.31 23:55 showslope EURUSD,M5: Slope: 30.5434 2011.05.31 23:50 showslope EURUSD,M5: Slope: 30.0448 2011.05.31 23:45 showslope EURUSD,M5: Slope: 29.8319
I cannot understand why this happens, but I am guessing that it is because I missed something in the i-Regr code. What I want is for the final output to read as it did a bar back: 30.7395 . Instead it repeats an incorrect number twice.
If someone would please look at my modification and help me out with this, I would really appreciate it.
Attached is the original i-Regr indicator and my broken mod.
Attached File(s)
i-Regr-ShiftBroken.mq4
5 KB
|
279 downloads
i-Regr.mq4
5 KB
|
287 downloads