Per the Managed Orders documentation I should just be able to call the reversing order method and it should generate two orders, the first to close the existing position
and the second to open the position in the opposite direction. Like this:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
if(CurrentBar < BarsRequiredToTrade)
return;
// Set 1
if(//logic for going up here) //going up
{
if(Position.MarketPosition == MarketPosition.Flat)
{
//this works perfect the first pass through
SetStopLoss(@"LongEntry", CalculationMode.Ticks, 12, false);
SetProfitTarget(@"LongEntry", CalculationMode.Ticks, 6);
EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentAsk(0), @"LongEntry");
return;
}
else if(Position.MarketPosition == MarketPosition.Short)
{
//I know for a fact that I have been short and this fails to reverse my position
SetStopLoss(@"LongEntry", CalculationMode.Ticks, 12, false);
SetProfitTarget(@"LongEntry", CalculationMode.Ticks, 6);
EnterLongLimit(Convert.ToInt32(DefaultQuantity), GetCurrentAsk(0), @"LongEntry");
return;
}
}
// Set 2
if(//logic for going down here) //going down
{
if(Position.MarketPosition == MarketPosition.Flat)
{
//this works perfect the first pass through
SetStopLoss(@"ShortEntry", CalculationMode.Ticks, 8, false);
SetProfitTarget(@"ShortEntry", CalculationMode.Ticks, 20);
EnterShortLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid(0), @"ShortEntry");
return;
}
else if (Position.MarketPosition == MarketPosition.Long);
{
//I know for a fact that I have been long and this fails to reverse my position
SetStopLoss(@"ShortEntry", CalculationMode.Ticks, 8, false);
SetProfitTarget(@"ShortEntry", CalculationMode.Ticks, 20);
EnterShortLimit(Convert.ToInt32(DefaultQuantity), GetCurrentBid(0), @"ShortEntry");
return;
}
}
}
What am I doing wrong?

Comment