Support Board
Date/Time: Sat, 12 Jul 2025 08:57:27 +0000
[Programming Help] - Reversal Order in ACSIL not getting created with Attached Orders
View Count: 146
[2025-07-09 04:41:47] |
rajeshh - Posts: 14 |
Update 7/11/2025 - Hello, I have renamed the original thread because that issue was due to a bug, and I did not want folks to get confused by the title. The initial posts below are about fixing that bug. Please jump to Reversal Order in ACSIL not getting created with Attached Orders | Post: 420860 to see the issue relevant to the current title. Hello - I have coded a sample trading strategy in the attached cpp file to demo my problem that when run hangs Sierra Chart fairly quickly. The idea is that if one is long, and encounters a bear bar and wants to scale-in at the close of the bear bar, but also submit an opposite short order at the low of the bear bar, I am not able to get this to work without Sierra Chart hanging. In the attached cpp file, the strategy initiates a long position above a bull bar (and has attached PT, and SL at 1x average bar size, and 2x barsize respectively), and scales in at the close of every bull bar thereafter. When it encounters a bear bar, it updates the stop loss of the long position to below the low of the bear bar, initiates a scale-in long ( in case, the stop is never triggered), but also submits a pending short order below the low of the bar in case the market does go below the bear bar. Once a short position is opened, the same idea repeats until the market goes above a bull bar. Note I am not using Reversals functionality of ACSIL. All the actions are happening when the bar has closed, which is when its meaningful, so as to also avoid overhead. Sierra Chart starts fine, but within a few bars will hang around 10 seconds before the close of a bar. It doesn't necessarily hang on the same bar. When it hangs, the whole app becomes unresponsive, and I have to end the Task in Windows 11 Task Manager. Another weirdness I see is the green open positions line disappears intermittently. At times, I also see that the open position quantity has increased, but the attached orders don't increment accordingly. So I have an open position of quantity 3, but attached orders are quantity 2. If I only pursue the long side of the strategy, it seems to go longer (as long as bull bars exist), but hangs around 10 secs time of the CountDown timer of a bear bar closing. I have tested this on a Windows 11 Alienware AMD laptop with 32 GB ram using SPY 5 min chart. Can you please try reproducing this on your side? p.s: When I add this study to a chart, I have to click on Settings, and scale Same as Region for Region 1, for the bars of the chart to show. Date Time Of Last Edit: 2025-07-11 20:51:35
|
![]() |
[2025-07-09 15:04:20] |
rajeshh - Posts: 14 |
Hello Sierra Chart Support team, I understand your stance on not providing support for complex trading scenarios. The code I attached is an attempt to minimize the complexity to demonstrate the problem I am having. If you don't want to look at the attached file, can I ask for sample code from your side for the correct way to do the following - Assume I am long, and the current bar is a bear bar - How can I scale in to the long position at the close of the bear bar, and also submit an opposite order to go short below the low of the bear bar? I found a code sample from you on scale-in order back from 2016 Simple ACSIL example to scale in to a trade so would appreciate something similar for the above. Thanks |
[2025-07-09 16:13:35] |
User431178 - Posts: 739 |
Did you review / debug your code before posting? There are two while loops in your code where you do not increment the orderIndex variable >>> infinite loop >>> application hang. Unrelated to the hang, but you do not need to recalculate the barSize for every bar in the array on each chart update. You can just change the below code from this // Calculate bar sizes: abs(high - low)
for (int i = 0; i < sc.ArraySize; ++i) { barSize[i] = std::fabs(sc.High[i] - sc.Low[i]); } to this barSize[sc.Index] = std::fabs(sc.High[sc.Index] - sc.Low[sc.Index]);
p.s: When I add this study to a chart, I have to click on Settings, and scale Same as Region for Region 1, for the bars of the chart to show.
The reason is that your subgraph Subgraph_AvgBarSize contains very small values compared to the main chart.In setdefaults add the below. sc.ScaleRangeType = SCALE_SAMEASREGION;
|
[2025-07-09 16:29:15] |
rajeshh - Posts: 14 |
First off, thanks for your response. I have reviewed and debugged, but could have missed things. where you do not increment the orderIndex variable
Curious why you say that when I have ++orderIndex; inside the while loop.barSize[sc.Index] = std::fabs(sc.High[sc.Index] - sc.Low[sc.Index]); Understand that I don't need to do that for every bar in the chart, but likely I need to do it for the last n bars whose average I want correct. Just your change will not be sufficient unless barSize is a persistent variable, correct? Or I store it as another subgraph array. Thanks for the change on the ScaleRange. |
[2025-07-09 16:38:08] |
rajeshh - Posts: 14 |
There are two while loops in your code where you do not increment the orderIndex variable >>> infinite loop >>> application hang.
NM. My bad. I see them now. Thanks for catching. |
[2025-07-09 16:42:49] |
User431178 - Posts: 739 |
I was just writing a reply telling you where to find them, but good, you saw it now. Understand that I don't need to do that for every bar in the chart, but likely I need to do it for the last n bars whose average I want correct. Just your change will not be sufficient unless barSize is a persistent variable, correct? Or I store it as another subgraph array.
When you use sc.AutoLoop = true, as you are here, the study is called for every bar on the chart during recalculation, so by using the suggested code (along with your where you compute the average) you will already have the correct values for bar range and average bar range without any need to loop or use persist vars. |
[2025-07-09 23:10:19] |
rajeshh - Posts: 14 |
Thanks to User431178 pointing out the infinite while loop, the Sierra Chart hanging issue is resolved. Now I am having issues with the opposite parent order not having its attached orders, and instead acting almost like a scaleout order. See https://www.sierrachart.com/image.php?Image=1752101744763.png , where there are qty 4 long position, after 3 bull bars, and scaling in on the close of the bear bar. The opposite sell order at the low of the bear bar shows up in the Attached Stop Order as TQ 5. I would like this to appear as its own order with an attached buy limit and buy stop order above. I have included the snippet of the code below, which creates the long scale-in order at the close of the bear bar, and then sets TradingScaleOut to false, and submits the opposite order. I have also attached a version of the cpp file with changes. Thanks //Next create a scale in Long Order
int Result; s_SCNewOrder scaleInOrder; scaleInOrder.OrderQuantity = 1; scaleInOrder.OrderType = SCT_ORDERTYPE_STOP; //scaleInOrder.TimeInForce = TIF_GOOD_TILL_DATE_TIME; scaleInOrder.Price1 = sc.Close[n]; //SCDateTime barDuration = sc.BaseDateTimeIn[n] - sc.BaseDateTimeIn[n - 1]; //scaleInOrder.GoodTillDateTime = sc.BaseDateTimeIn[n+1] + barDuration; msg.Format("index=%u,Long Position Scalein: Price = %f, Prior Quantity = %f", n,scaleInOrder.Price1, PositionData.PositionQuantity); sc.AddMessageToLog(msg, 1); Result = static_cast<int>(sc.BuyEntry(scaleInOrder)); //Adding the below to see if it would make the new Opposite order have its own attached orders, and not scale out. sc.SupportTradingScaleOut = false; //Next create a new Short Order, below thw low of the bear bar. // Create an s_SCNewOrder object. s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_STOP; //NewOrder.TimeInForce = TIF_GOOD_TILL_DATE_TIME; //SCDateTime barDuration = sc.BaseDateTimeIn[n] - sc.BaseDateTimeIn[n - 1]; //NewOrder.GoodTillDateTime = sc.BaseDateTimeIn[n+1] + barDuration; NewOrder.Price1 = sc.Low[n] - sc.TickSize; //In this case, simplifying this to be a buy Stop order above the high of the bar. NewOrder.Target1Price =NewOrder.Price1 - RoundToMinTick(avgBarSize) ; NewOrder.Stop1Price = sc.High[n] + RoundToMinTick(2*avgBarSize); msg.Format("index=%u,Opposite Short Order: Price = %f, Prior Quantity = %f", n,NewOrder.Price1 , PositionData.PositionQuantity); sc.AddMessageToLog(msg, 1); Result = static_cast<int>(sc.SellEntry(NewOrder)); Date Time Of Last Edit: 2025-07-09 23:11:10
|
![]() |
[2025-07-11 20:58:01] |
rajeshh - Posts: 14 |
Hello - Any Takers? I have renamed the thread because the original hang issue in the title of the thread was due to my bug, and I felt the title is misleading. The current issue may still be due to a bug, but I have taken a hard look at the code, and cannot spot anything. So in short, I need to create a reversal order with attached orders at the same price where I have the stoploss for my current position. So if I am long 4 qty, I want to create a sell order of qty 1 with its own attached orders at the same price as the attached stop order of the long position. With the code in the attached file, it is creating the new reversal order, but not the attached orders. I have manually tried this in Sierra Chart, and it works as expected. I need help getting my ACSIL to do the same. Thanks |
To post a message in this thread, you need to log in with your Sierra Chart account: