MACD Value Discrepancy
Forums › ProRealTime English forum › ProOrder support › MACD Value Discrepancy
- This topic has 15 replies, 3 voices, and was last updated 3 months ago by druby.
-
-
07/11/2024 at 10:30 AM #235060
Hi all,
I am trying to backtest a strategy that relies on the precise values of the MACD line and signal. However, the ProBacktest values always seem to be slightly different to the indicator (sometimes the difference is quite severe and the actual histogram is wrong).
I’ve attached a screenshot of what this looks like. For this example, I’ve simply graphed the MACD line and signal values at each current bar to see what exactly is going on.
MACD Reference12345678910line1 = MACDLine[12, 26, 9](Close)line2 = MACDLine[12, 26, 9](Close)[1]signal1 = MACDSignal[12, 26, 9](Close)signal2 = MACDSignal[12, 26, 9](Close)[1]graph line1 as "line1"graph signal1 as "signal1"//<Order Logic Below>I’ve tried playing around with Preloadbars and the number of units to no avail. This is also run on a single TF.
If anyone can shed some light on this, that would be very much appreciated.
Thank you.
07/11/2024 at 12:50 PM #23507707/11/2024 at 1:56 PM #235086Yes, only dealing with Forex at the moment (I should have mentioned that in the original post).
You are correct, even when previous values of MACD are referenced ([1], [2], etc) the difference is present. It simply spits out the value that it calculated previously, still with a big difference.
07/11/2024 at 2:06 PM #23508707/11/2024 at 3:03 PM #235095It doesn’t quite matter what the strategy is as you will never get the correct MACD values anyway. Take this very basic example that tries to capture the movement of a water line cross.
ProBacktest Example1234567891011121314151617181920212223242526272829303132333435DEFPARAM CumulateOrders = FalseDEFPARAM Preloadbars = 10000line0 = MACDLine[12, 26, 9](Close)line1 = MACDLine[12, 26, 9](Close)[1]line2 = MACDLine[12, 26, 9](Close)[2]signal0 = MACDSignal[12, 26, 9](Close)signal1 = MACDSignal[12, 26, 9](Close)[1]signal2 = MACDSignal[12, 26, 9](Close)[2]hist0 = MACD[12, 26, 9](Close)hist1 = MACD[12, 26, 9](Close)[1]hist2 = MACD[12, 26, 9](Close)[2]if (hist0 < 0 AND hist1 < 0 AND hist2 < 0 AND line0 < 0 AND signal0 < 0 AND line1 < 0 AND signal1 > 0AND line2 > 0 AND signal2 > 0) thenentry = Close[0]stopLevel = High[0]stopUnits = stopLevel - entryrisk = 500.0 / ((stopUnits) * 10000.0)SELLSHORT risk SHARES AT MARKETSET STOP LOSS stopUnitsendifif(OnMarket AND hist0 > 0) thenBUY AT MARKETendifgraph line0 as "line0"graph signal0 as "signal0"graph hist0 as "hist0"The discrepancies are enough to provide false entries. Compare this to an identical indicator in ProBuilder without the order placement.
Indicator Example12345678910111213141516171819line0 = MACDLine[12, 26, 9](Close)line1 = MACDLine[12, 26, 9](Close)[1]line2 = MACDLine[12, 26, 9](Close)[2]signal0 = MACDSignal[12, 26, 9](Close)signal1 = MACDSignal[12, 26, 9](Close)[1]signal2 = MACDSignal[12, 26, 9](Close)[2]hist0 = MACD[12, 26, 9](Close)hist1 = MACD[12, 26, 9](Close)[1]hist2 = MACD[12, 26, 9](Close)[2]enter = 0if (hist0 < 0 AND hist1 < 0 AND hist2 < 0 AND line0 < 0 AND signal0 < 0 AND line1 < 0 AND signal1 > 0AND line2 > 0 AND signal2 > 0) thenenter = 1endifreturn enterI hope someone can clarify this strange behaviour.
07/11/2024 at 3:36 PM #23510007/11/2024 at 3:58 PM #235103I get areas that are relatively close and some that are not. Are yours the same?
In theory, shouldn’t they be exactly the same? I still don’t want to accept best case scenario as they are “close enough” as this is quite annoying for what I am trying to do.
07/11/2024 at 4:13 PM #23510407/11/2024 at 4:29 PM #235105You can use this mathematical function in your strategy, to adjust the decimal places (e.g. 2 decimal places) …
07/11/2024 at 4:43 PM #235113The stock, custom and custom indicator called from another file all align up.
However, results from the backtest versions do slightly deviate.
Can’t shed any further light on that.
On a different observation, you can write the code this way as well. Because most variables store its value for each bar, you can use the [‘n’] to get previous values. This way you only have to repeatedly call external code for one since there all got the same settings.
12345678910iMacd = MACDLine[12, 26, 9](Close)iSignal = MACDSignal[12, 26, 9](Close)iHist = MACD[12, 26, 9](Close)enter = 0if (iHist < 0 AND iHist[1] < 0 AND iHist[2] < 0 AND iMacd < 0 AND iSignal < 0 AND iMacd[1] < 0 AND iSignal[1] > 0 AND iMacd[2] > 0 AND iSignal[2] > 0) thenenter = 100endifreturn enter1 user thanked author for this post.
07/11/2024 at 5:10 PM #235115This is quite a shame as I do need exact values since some instruments have MACD values only beginning at the 4th decimal (in some cases 5th). So it’s not an option for me to round.
Is it possible to get an official confirmation as to why this is happening, or a workaround?
Thanks for your help so far guys.
07/11/2024 at 8:31 PM #235118It seems that the BackTest module calculates with a maximum of 5 decimal places, while an Indicator calculates with 6 decimal places…
5 decimal places should be enough for Forex, because here, with most pairs, 5 decimal places are also used (tick size = 0.00001) …
07/11/2024 at 9:33 PM #23512307/11/2024 at 9:43 PM #23512507/12/2024 at 3:46 AM #235128Glad we were able to get to the bottom of this. This discrepancy in decimal precision surely affects other indicators as well, and not just MACD.
I’ve checked both the IG and PRT Trading platforms and this looks like a fundamental issue that impacts the accuracy of all calculations.
Accurate indicators are the backbone of any reliable strategy, so it is legitimately beyond me why this is something we have to discuss and “deal with” in the first place.
-
AuthorPosts
Find exclusive trading pro-tools on