Profile Picture

cover short and go long on same bar?

Posted By uaruss 6 Years Ago
Message
Posted Thursday December 08 2011
All - I have a scenario where I want to close a short position and go long a position on the same day. It appears my code is simply closing the short position and ignoring the opening of the long position. I have parameters set to invest 100% of the account and have a max of 1 position open at a time.

Can someone tell me how to get around this issue? Basically, it seems that doing a "pos.CloseAtMarket()" followed by a "OpenPosition(PositionType.Long, OrderType.Market)" command, during the same bar, doesn't appear to work? Should it or is there some better method?

A small piece of code is below. I can post more if it would help, but I write out each bar and several "parameters" to a CSV file to better analyze the action. so more may get confusing. Also the "My_Action" is a variable I set that captures what logic should be occuring (Buy/Sell/Cash)...

*****
ElseIf (OpenPositions.Count > 0 And My_Action = "BUY") Then

For Each pos As Position In OpenPositions

pos.CloseAtMarket()

Next

OtherSymbols("^IXIC").OpenPosition(PositionType.Long, OrderType.Market)
*****

Thanks!

Russell
Posted Thursday December 08 2011
Do you have the following code in your OrderCancelled method?

If Not order.CancelPending Then
OutputWarning("Unexpected order cancel: " & order.ToString() & " " & information)
End If

Look in the output window for these messages. It may be that the order isn't being filled because you don't have enough cash. You probably don't want to set it to use 100% of the account. When you tell it to open a position it calculates the position size based on the current price. By the time the order can be filled the price may have changed, so if it was trying to use 100% of the account there might not be enough cash for it to fill the order.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems