Support Board
Date/Time: Fri, 10 Jan 2025 13:28:44 +0000
ACSIL - Unexpected reversal when using sc.SellOrder() and sc.BuyOrder() to flatten
View Count: 1097
[2016-09-15 08:04:39] |
William O - Posts: 16 |
When sc.SupportReversals is true and I'm flattening a position using sc.SellOrder() or sc.BuyOrder(), I unexpectedly get a reversal. When I run the study below and enter a long market position while connected to live streaming data, I get a reversal when I should be flat. Can you please let me know if this is a problem on my end or yours. Thanks in advance! SCSFExport scsf_UnexpectedReversal(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "X: Unexpected Reversal"; sc.StudyDescription = ""; sc.SupportReversals = true; sc.AutoLoop = true; sc.GraphRegion = 0; sc.FreeDLL = 0; return; } if (sc.ServerConnectionState == SCS_CONNECTED && sc.Index == (sc.ArraySize - 1) && !sc.DownloadingHistoricalData && !sc.IsFullRecalculation) { const char* TradeAccount = "Sim1"; s_SCPositionData OrigPositionData; int returnVal4 = sc.GetTradePosition(OrigPositionData); if (!OrigPositionData.WorkingOrdersExist && OrigPositionData.PositionQuantity > 0 ) { s_SCNewOrder o; o.OrderType = SCT_MARKET; o.Symbol = sc.Symbol; o.TimeInForce = SCT_TIF_DAY; o.TradeAccount = TradeAccount; o.OrderQuantity = OrigPositionData.PositionQuantity; int return0 = sc.SellOrder(o); if (return0 <= 0) sc.AddMessageToLog(sc.GetTradingErrorTextMessage(return0), 1); } } } |
[2016-09-15 17:32:42] |
Sierra Chart Engineering - Posts: 104368 |
Really you need to use sc.SellExit() or sc.BuyExit() instead. Or set sc.SupportReversals = 0 just before you use the function that you currently are. Also you really should not be setting either of these: o.Symbol = sc.Symbol; o.TradeAccount = TradeAccount; Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
[2016-09-16 05:56:19] |
William O - Posts: 16 |
Thanks for the reply. I discovered this issue when working with a larger more complicated example than shown above. In my case I can most easily work around this behaviour by setting SupportReversals to 0. However, I think this is a still a problem with unmanaged trading. I was hoping you'd be able to address this more thoroughly. If sc.BuyOrder is set to buy 1 contract and it buys 2, that certainly isn't correct. The only other thing I can add is that this does not happen when I'm flattening another symbol; It only happens when I'm flattening the same symbol as the chart. Whether o.Symbol or o.TradeAccount is set does not impact this problem. Thanks again for your support. |
[2016-09-16 05:58:15] |
Sierra Chart Engineering - Posts: 104368 |
Do not use SupportReversals. That is the mistake.
Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: