Login Page - Create Account

Support Board


Date/Time: Wed, 10 Sep 2025 00:51:37 +0000



Post From: LifeCycle of sc.SupportTradingScaleOut in a study?

[2025-07-28 23:57:35]
@sstfrederik - Posts: 410
The ScaleIn and ScaleOut settings are valid for the calculation cycle it is called in. In other words if you change it it will only work in the next cycle. Your use case you can simply set a persistent variable to trigger the order on the next calculation cycle.

btw. the target and stop offset are price values not ticks.


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;



return;

}


int& setorder = sc.GetPersistentInt(0);


SCString msg;


if ( setorder == 1 ){

setorder = 0;

// Disable scale-out for next order



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);


sc.SupportTradingScaleOut = 1;
}
}

// 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;
//sc.SupportTradingScaleOut = 0;




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 ){

setorder = 1;
sc.SupportTradingScaleOut = 0;
return;
}




}