Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 02:31:50 +0000



Post From: ACSIL, How to get prices of entry, stop, and target?

[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;
}

}