Wednesday, December 26, 2007

One more thing . . .

Ok, so I quickly wanted to test a three bar pullback pattern as referenced in Active Trader, October 2007. I coded up the following. Notice that it seems that the LeadBar property set for the Backtest seems to not work, hence the additional if statement. For beginners, also note that I'm using a very simply additional function that returns true if the bar passed to it was a 'down' bar.


using System;
using System.Drawing;
using System.Collections.Generic;
using RightEdge.Common;
using RightEdge.Indicators;

public class SystemMain : SystemBase
{
public override void Startup()
{
// Perform initialization or set system wide options here
PositionManager.PositionTimeOut = 7;
PositionManager.ProfitTarget = 0.03;
}

public override void NewSymbolBar(Symbol symbol, BarData bar)
{
// This line of code runs the actions you have set up in in the Project Form
IList bars = Bars[symbol];
int t = bars.Count-1;
// Should not be necessary but apparently LeadBars Property is ignored
if (bars.Count > 12)
{
if (bars[t-1].High < bars[t-2].High && bars[t-2].High < bars[t-3].High)
{
if(bars[t].High > bars[t-1].High)
{
if (DownBar(bars[t-1]) && DownBar(bars[t-2]) && DownBar(bars[t-3]))
OpenPosition(symbol, PositionType.Long, OrderType.MarketOnOpen);
}
}
}
Actions.RunActions(symbol);
}
private bool DownBar(BarData bar)
{
return (bar.Close < bar.Open);
}
}


... and if someone could tell me how to force blogger to indent code properly, I'd be most grateful.

No comments: