Having said that the study "Whs EUR/USD High Noon" works perfectly in real time, you can not say the same for backtesting.
In fact, sometime it happens that the direction of a signal of the Metasentimentor in real trading, change to the opposite direction in the fallowing days.
The cause of this discrepancy is the aggregation, let me explain:
Using the default values as example, the study is based on the crossing of the moving average convergence and divergence with its signal line on a 2 hours time frame, 12 period aggregation, so 24 hours, with market entry at 14:00.
The backtesting would replicate faithfully the past if the closing of the twelfth period coincided with the entry on position, but in practice this rarely occurs, firstly because any database serie may only be uploaded from midnight on, and secondly because during some U.S. holiday the CME reduces the trading hours, with the effect of postponing the aggregation.
But above all, the values assumed in calculation of MACD are future values, that return more optimistic results. For example a typical situation is this:
It's 14:00, the SL is above MACD, not much above but above, so we go long. The twelfth period falls at 12:00. Future Station Nano calculates the MACD with reference to the close of 12:00, but not on that day, but on the next day, 22 hours after the real market situation.
Let assume that at 16:00 major economic data or speeches of governors of the FED or the BCE were released with a negative impact on the EURO that significantly reduced the exchange ratio in such a way that the SL moves below the MACD.
So, in optimizations, on that day, the metasentimentor provides a short trade in profit, but in reality we went long suffering a loss.
So we know that the MACD is calculated on two exponential moving average based on the following formula:
Exponential Moving Average
Computation:
EMA[t] = EMA[t-1] + (SF * (Ct - EMA[t-1]))
with
SF = 2/(span + 1)
Parameter:
Span: number of periods for computing SF..
So in this case you can bypass the problem by taking MACD into TimeEntry with aggregate close up to penultimate period (in this case up to the eleventh) and by calculating close disaggregated for the final period, as in the formula above mentioned.
So I took the liberty to change the code of MACDone:
Code: Select all
EXPRESS MACDone
VARS
Series
fastMA, slowMA, SLone,
slow, fast, smooth,
MACDone, Zeroline(0);
Input
$slowEMA(1, 200, 26),
$fastEMA(1, 200, 12),
$smooth(1, 200, 9);
CALCULATION
slow = $slowEMA;
fast = $fastEMA;
smooth = $smooth;
If IsFirstbar() then begin
ExpMovingAverage(c, fastMA, $fastEMA);
ExpMovingAverage(c, slowMA, $slowEMA);
end
MACDone = fastMA - slowMA;
If IsFinalBar() then begin
SetYscaleFormat("%6.5f");
ExpMovingAverage(MACDone, SLone, $smooth);
end
INTERPRETATION
BEGIN
END
plot (MACDone, lightmagenta, 1);
plot (SLone, darkblue, 1);
plot (zeroline, grey, 1);
Code: Select all
EXPRESS TimeEntry
VARS
Numeric
diffMinutes;
Series
senti(50),
MACDone(MACDoneExpress.MACDone),
SLone(MACDoneExpress.SLone),
FastMA(MACDoneExpress.FastMA),
SlowMA(MACDoneExpress.SlowMA),
slow(MACDoneExpress.Slow),
fast(MACDoneExpress.fast),
smooth(MACDoneExpress.smooth),
unAggFastMA,
unAggSlowMA,
unAggMACDone,
unAggSLone;
Input
$EnterAT(000,2359,1200),
$MaxDelayMinutes(0,1440,120);
CALCULATION
if IsFirstBar() then begin
CalculateAtEveryTick(true); // or false
SetYSCaleFormat("%6.5f");
end
diffMinutes = (Duration(date[1], date) + Duration(time[1], time))/60;
If (time >= NumericToTime($EnterAT)) AND ((time[1] < NumericToTime($EnterAT)) OR IsNewDay()) AND (diffMinutes <= $MaxDelayMinutes) then begin
senti = 100;
Highlight("slot","grey");
end
unAggFastMA = (close - FastMA[1]) * (2 / (fast + 1)) + FastMA[1];
unAggSlowMA = (close - SlowMA[1]) * (2 / (slow + 1)) + SlowMA[1];
unAggMACDone = unAggFastMA - unAggSlowMA;
unAggSLone = (unAggMACDone - SLone[1]) * (2 / (smooth + 1)) + SLone[1];
{****************************************************************************************}
ShowTip("MACDone = " + NumericToString(MACDone, "%6.5f") + "\n" +
"unaggMACDone = " + NumericToString(unaggMACDone, "%6.5f") + "\n" +
"SLone = " + NumericToString(SLone, "%6.5f") + "\n" +
"unaggSLone = " + NumericToString(unaggSLone, "%6.5f"));
{*****************************************************************************************}
INTERPRETATION
BEGIN
if Senti = 100 then begin
if (unAggMACDone > unAggSLone) then Sentiment = 100;
if (unAggMACDone < unAggSLone) then Sentiment = 0;
end
END
plot(unAggMACDone, magenta, 2);
plot(unAggSLone, blu, 2);
And the MACD(26,12,9) equity line changes from this:
to this
with a significant difference.
In my humble opinion, most of these differences could be reduced if in Future Station Nano there was the possibility to consider non-trading days, as holiday and weekend, as empty records.
Best regards