Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 00:42:29 +0000



[Programming Help] - ACSIL, How to get prices of entry, stop, and target?

View Count: 553

[2023-10-02 00:04:36]
j4ytr4der_ - Posts: 938
I thought this would be fairly simple but I'm hitting nothing but brick walls as I don't really know what I'm doing.

I could really use a helper study that returns 3 subgraphs, that contain:

1. The current open order entry price level, or position entry price if in a position
2. The current attached target price level
3. The current attached stop price level

I've been scouring the forum, the docs, and the included ACSIL example files but have gotten pretty much nowhere. Any pointers on how one would accomplish this (seemingly) relatively simple task?
[2023-10-02 21:15:36]
ForgivingComputers.com - Posts: 960
Modified from the AvgFillPrice example here: Automated Trading From an Advanced Custom Study: [Type: double] AvgFillPrice



// Enter a new order as a Buy Entry order.
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 1;

NewOrder.OrderType = SCT_MARKET;
int ReturnValue;
ReturnValue = sc.BuyEntry(NewOrder);

// Remember the internal order ids as persistent variables
int& ParentOrderID = sc.GetPersistentInt(0);
int& StopOrderID = sc.GetPersistentInt(1);
int& TargetOrderID = sc.GetPersistentInt(2);

if (ReturnValue > 0 && NewOrder.InternalOrderID != 0)
{
ParentOrderID = NewOrder.InternalOrderID;
TargetOrderID = NewOrder.Target1InternalOrderID;
StopOrderID = NewOrder.Stop1InternalOrderID;
}

// Once the order fills, after submitting the order, we can
// determine the actual fill price with the following code. Keep in
// mind that we may not obtain the fill price at this moment, but
// on a subsequent call into the study function.

// Get the available order data for the submitted order by using
// the InternalOrderID that was assigned after calling the Order
// Action function sc.BuyEntry.

if (OrderID != 0)
{
s_SCTradeOrder TradeOrderData;

int Result = sc.GetOrderByOrderID(ParentOrderID, TradeOrderData);

if (Result != SCTRADING_ORDER_ERROR)
{
double FillPrice = TradeOrderData.AvgFillPrice;
}

// Get the Stop Price in a similar way with the Stop Order ID and Price1
Result = sc.GetOrderByOrderID(StopOrderID, TradeOrderData);

if (Result != SCTRADING_ORDER_ERROR)
{
double StopPrice = TradeOrderData.Price1;
}

// Get the Target Price in a similar way with the Target Order ID and Price1

Result = sc.GetOrderByOrderID(TargetOrderID, TradeOrderData);

if (Result != SCTRADING_ORDER_ERROR)
{
double TargetPrice = TradeOrderData.Price1;
}

}

[2023-10-02 21:23:58]
j4ytr4der_ - Posts: 938
Thanks, I can't get this to compile however. Tried wrapping it in the standard stuff but I get:

error: 'SCT_MARKET' was not declared in this scope; did you mean 'SC_TS_MARKER'?
15 | NewOrder.OrderType = SCT_MARKET;
| ^~~~~~~~~~
| SC_TS_MARKER

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

Login

Login Page - Create Account