I'm developing an MACD strategy for ES and have strange results.
When I did some printing for some how the MACD takes the numbers from the ES data.
Here is the code and the output window prints:
protected override void Initialize()
{
macd = MACD(fastLength, slowLength);
Add(macd);
CalculateOnBarClose = true;
SetProfitTarget(profitTarget);
SetStopLoss(stopLossTarget);
ClearOutputWindow();
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < SlowLength)
return;
//Calculate only once.
if (BarsInProgress != 0)
return;
//Output Printing
Print("Current Bar:" + CurrentBar.ToString());
Print("macd[2]: " + macd[2].ToString("0.00"));
Print("macd[1]: " + macd[1].ToString("0.00"));
Print("macd[0]: " + macd[0].ToString("0.00"));
Print("-------------------------");
//Enter Long position
if (Math.Abs(macd[2]) > Math.Abs(macd[1]) && Math.Abs(macd[0]) > Math.Abs(macd[1]))
{
EnterLong(1,"");
}
macd[2]: 2.60
macd[1]: 2.72
macd[0]: 2.74
-------------------------
Current Bar:44
macd[2]: 2.72
macd[1]: 2.74
macd[0]: 1220.25
-------------------------
Current Bar:45
macd[2]: 2.74
macd[1]: 1220.25
macd[0]: 1220.50
-------------------------
Do you know what I'm doing wrong? this bug killing me for hours :-(
Thanks in advance for any suggestions!

Comment