Login Page - Create Account

Support Board


Date/Time: Sat, 27 Jul 2024 02:04:42 +0000



Stop Order Not Working in ASCIL

View Count: 250

[2024-05-20 18:31:50]
PS - Posts: 19
Hello again -- I'm having some trouble with stop orders. Simply put, the order I'm entering isn't executing. I'm quite sure this is an error on my end -- I've gone through the documentation and sample strategies but can't find an implementation of what I'm trying to do. Below is my code:


s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = trade_quantity;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_DAY;
int Result = sc.SellEntry(NewOrder);

// Place stop order 2 points above end price
s_SCNewOrder StopOrder;
StopOrder.OrderQuantity = trade_quantity;
StopOrder.OrderType = SCT_ORDERTYPE_STOP;
StopOrder.Price1 = zone.end_price + 2;
StopOrder.TimeInForce = SCT_TIF_GTC;


The first mini block of code sends an entry order. This is working fine. The second mini block is meant to send a stop order. I've verified that the zone.end_price + 2 value is what it should be. But no exit order is ever triggered despite price hitting the stop value.

What am I doing wrong in this implementation?

Thank you in advance for your help.
[2024-05-20 20:35:10]
Sierra_Chart Engineering - Posts: 15584
You need to look in the Trade >> Trade Orders Window and see if the order is there and has an Open status and check the other parameters and see if everything is as expected.
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, use the Teton service:
Sierra Chart Teton Futures Order Routing
[2024-05-21 00:09:54]
ForgivingComputers.com - Posts: 905
You can also check the Trade Activity Log to see if the order was submitted.

Just be sure, you have:

int Result = sc.SellEntry(NewOrder);

For the Market Order, but I don't see one for the Stop Order.

Perhaps you left it out of the copied text, but that would explain your result.
[2024-05-21 15:34:59]
PS - Posts: 19
Thank you for your reply. To be clear, below is the full entry / stop logic I've written. This logic is for a sell entry + buy stop. It sits within an if block that checks for the conditions for trade entry.

I've checked the Trade Orders Window, and it is empty. No orders of any kind. Do you see a problem with this logic below? Thank you again in advance for your help.


SCString logMessage;
logMessage.Format("Sell conditions met: Start Price: %f, End Price: %f, Close Price: %f, Time: %s", zone.start_price, zone.end_price, close, sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars());
sc.AddMessageToLog(logMessage, 0);



s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = trade_quantity;
NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
NewOrder.TimeInForce = SCT_TIF_DAY;
int Result = sc.SellEntry(NewOrder);

// Draw a red arrow for sell entry
s_UseTool SellArrow;
SellArrow.Clear();
SellArrow.ChartNumber = sc.ChartNumber;
SellArrow.DrawingType = DRAWING_MARKER;
SellArrow.MarkerType = MARKER_ARROWDOWN;
SellArrow.MarkerSize = 8;
SellArrow.Color = RGB(255, 0, 0); // Red color
SellArrow.BeginIndex = sc.Index;
SellArrow.BeginValue = close;
sc.UseTool(SellArrow);


// Place stop order 2 points above end price
s_SCNewOrder StopOrder;
StopOrder.OrderQuantity = trade_quantity;
StopOrder.OrderType = SCT_ORDERTYPE_STOP;
StopOrder.Price1 = zone.end_price + 2;
StopOrder.TimeInForce = SCT_TIF_GTC;
int StopResult = sc.SellEntry(StopOrder);

SCString logMessagestop;
logMessagestop.Format("Stop order placed at %f", StopOrder.Price1);
sc.AddMessageToLog(logMessagestop, 0);

[2024-05-21 16:25:40]
User431178 - Posts: 460
What about the trade service log window, did you check that for error messages?


int Result = sc.SellEntry(NewOrder);

What is the value of result after you attempt order entry?


int StopResult = sc.SellEntry(StopOrder);

Similarly, what is the value of StopResult?


if (result < 0)
sc.AddMessageToTradeServiceLog(sc.GetTradingErrorTextMessage(result), 0, 1);

What are these variables set to?

sc.AllowOnlyOneTradePerBar
sc.AllowOppositeEntryWithOpposingPositionOrOrders
sc.AllowEntryWithWorkingOrders


Slightly off topic, but is there a particular reason you don't send the stop attached with the entry?
[2024-05-21 19:27:36]
PS - Posts: 19
To answer all your questions:
1. Trade service log shows that some actions are ignored because sc.AllowOnlyOneTradePerBar = TRUE. Should this be set to false?
2. Result value = 1
3. Stop result value = -8997 (I assume this is a problem?)
4. AllowOnlyOneTradePerBar = TRUE
5. I don't know where to find out the true/false value of the other 2 variables mentioned
6. Not off topic at all -- I initially tried to attach the stop order, but didn't find a way to do so in the documentation. I'd very much like to do that as it seems to be a more elegant solution. Could you point me to somewhere I can reference to do so?

Thanks again for your detailed questions and concern to help me resolve the issue.
[2024-05-21 20:11:46]
User431178 - Posts: 460
1. This is the reason, as you are, in theory, trying to enter two trades on the same bar.
2. Ok, so that works at least.
3. Yes, -8997 means skipped because only one trade per bar
4. This is ok, but not for the way you are sending orders (separately).
5. You set them yourself in the setdefaults block, read about them here - Automated Trading From an Advanced Custom Study: Advanced Custom Study Interface Variable Members Relevant to Trading
6. Ok, got it. All you need to do is set the relevant parameters when submitting the entry order, some links below.

Automated Trading From an Advanced Custom Study: [Type: char] s_SCNewOrder::AttachedOrderStop1Type
Automated Trading From an Advanced Custom Study: [Type: double] s_SCNewOrder::StopAllPrice
Automated Trading From an Advanced Custom Study: [Type: double] s_SCNewOrder::StopAllOffset
[2024-05-23 13:22:49]
PS - Posts: 19
This worked! Was able to attach stops and targets successfully. thank you for your help.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account