It 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.
DEFPARAM CumulateOrders = False
DEFPARAM Preloadbars = 10000
line0 = 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) then
entry = Close[0]
stopLevel = High[0]
stopUnits = stopLevel - entry
risk = 500.0 / ((stopUnits) * 10000.0)
SELLSHORT risk SHARES AT MARKET
SET STOP LOSS stopUnits
endif
if(OnMarket AND hist0 > 0) then
BUY AT MARKET
endif
graph 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.
line0 = 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 = 0
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) then
enter = 1
endif
return enter
I hope someone can clarify this strange behaviour.