Support Board
Date/Time: Wed, 10 Sep 2025 00:48:29 +0000
Post From: LifeCycle of sc.SupportTradingScaleOut in a study?
[2025-07-28 23:02:17] |
rajeshh - Posts: 25 |
Thanks for your post @sstfrederik. I am now doing something even more straightforward. I initially open a position with a long market order at the close of bar (bar 1 let's say), and at the close of the next bar (bar 2), open an opposite order with ScaleOut = 0, but it does not work, even though ScaleOut is logged as 0 in the log message. It does work on the order opened at the close of bar 3. So it's almost as if the setting is bar late. SCSFExport scsf_ScaleInOutDemo3(SCStudyInterfaceRef sc)
{ if (sc.SetDefaults) { sc.GraphName = "ScaleInOut Demo 3"; sc.AutoLoop = 0; sc.GraphRegion = 0; sc.MaximumPositionAllowed = 10; sc.AllowMultipleEntriesInSameDirection = true; sc.SupportAttachedOrdersForTrading = true; sc.UseGUIAttachedOrderSetting = false; // Only 1 trade for each Order Action type is allowed per bar. sc.AllowOnlyOneTradePerBar = false; sc.AllowEntryWithWorkingOrders = true; sc.AllowOppositeEntryWithOpposingPositionOrOrders = true; // This is false by default. Orders will go to the simulation system always. sc.SendOrdersToTradeService = false; sc.FreeDLL = 1; return; } SCString msg; // Only run study at close of bar. have tried combinations of BAR_HAS_NOT_CLOSED etc but does not change outcome if (sc.GetBarHasClosedStatus(sc.Index) != BHCS_BAR_HAS_CLOSED) return; sc.SupportTradingScaleIn = 1; s_SCPositionData PositionData; sc.GetTradePosition(PositionData); if ( PositionData.PositionQuantity ==0 ){ sc.SupportTradingScaleOut = 1; // Example: Buy Market Order with attached orders s_SCNewOrder order; order.OrderType = SCT_ORDERTYPE_MARKET; order.OrderQuantity = 3; order.Target1Offset = .50; // 50 ticks above order.Stop1Offset = -.50; // 50 ticks below order.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP; order.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT; order.OCOGroup1Quantity=3; // Submit first buy order int result = sc.BuyEntry(order); if ( result > 0) { msg.Format("index=%u,1st Orderid = %u, sc.SupportTradingScaleOut = %u, sc.ArraySize-1 =%u ", sc.Index, order.InternalOrderID, sc.SupportTradingScaleOut, sc.ArraySize-1); sc.AddMessageToLog(msg, 1); } } else if ( PositionData.PositionQuantity >0 ){ // Disable scale-out for next order sc.SupportTradingScaleOut = 0; if (sc.SupportTradingScaleOut == 0){ s_SCNewOrder order2; // Submit new sell order with attached orders order2.Target1Offset = -.10; // 10 ticks below entry order2.Stop1Offset = .10; // 10 ticks above entry order2.OrderType = SCT_ORDERTYPE_STOP; order2.Price1 = sc.Low[sc.Index] -sc.TickSize; order2.OrderQuantity = 1; order2.OCOGroup1Quantity=1; sc.SellEntry(order2); // This should be treated as a new parent order, with attached orders. Except it isnt. msg.Format("index=%u,Reversal Orderid = %u, sc.SupportTradingScaleOut = %u, sc.ArraySize-1=%u", sc.Index, order2.InternalOrderID, sc.SupportTradingScaleOut,sc.ArraySize-1); sc.AddMessageToLog(msg, 1); } } } Date Time Of Last Edit: 2025-07-28 23:07:08
|