|
boston, ma
Experience: Intermediate
Platform: NT7
Broker: amp/zenfire
Trading: es
Posts: 10 since Feb 2010
Thanks Given: 3
Thanks Received: 0
|
So im trying to write a simple strategy that makes a market based on bollinger bands. It's very basic so far and I have it to a point where I can offer or bid at the price I want. What im trying to do is cancel the sitting orders if price crosses the mid point of the bollingers. The strategy so far places an order based on price in relation to the 20 period ma for a bollinger. I'm either offering or bidding at the extreme bands, if price is above the 20 period ma im offering, below and im bidding. What I need to do is cancel the previous order if price doesnt fill me and moves above or below the ma. Heres the code I have so far. It will place a singal order but wont remove it and place a new one if price crosses the middle band. Any help would be greatly appreciated. I've looked at the help for strategies and it doesn't help me much.
protected override void Initialize()
{
Add(Bollinger(2.3, 20));
SetProfitTarget("", CalculationMode.Ticks, 21);
SetStopLoss("", CalculationMode.Ticks, 12, false);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (GetCurrentBid() < Bollinger(2.3, 20).Middle[0])
{
entryOrder = EnterLongLimit(DefaultQuantity, Bollinger(2.3, 20).Lower[0] + -1 * TickSize, "Long");
}
if (entryOrder != null && GetCurrentBid() > Bollinger(2.3, 20).Middle[0])
{
CancelOrder(entryOrder);
}
// Condition set 2
if (GetCurrentAsk() > Bollinger(2.3, 20).Middle[0])
{
entryOrder = EnterShortLimit(DefaultQuantity, Bollinger(2.3, 20).Upper[0] + 1 * TickSize, "Short");
}
if (entryOrder != null && GetCurrentBid() < Bollinger(2.3, 20).Middle[0])
{
CancelOrder(entryOrder);
}
|