Login Page - Create Account

Support Board


Date/Time: Thu, 28 Nov 2024 17:51:11 +0000



[Programming Help] - [ACSIL] - Get current position data

View Count: 960

[2023-04-14 00:31:53]
backinblack - Posts: 35
Hi,

Problem:
I am currently using Trailing Stop losses with my entries. At times I have observed that even through my targets have been hit, an orphan trailing stop loss order is still there. The issue it is causing is, SC doesn't open new trade entries because it thinks there is a position already open and opening another will cause the max position size breach (Which works as expected). At this point I would usually press cancel all button to get rid off the Trailing SL so SC can open new positions. This is happening on SC version 2491 + Rithmic Paper trading feed.

Any idea what could be going wrong here?

Tactical Solution - A tactical solution I have thought about is to code a simple study that will call sc.FlattenAndCancelAllOrders() on close of each candle if the current open position size is 0 (While there might still be orphan trailing loss orders). This would in theory get rid off the Trailing loss orders if no open positions exist.

I am trying this



s_SCPositionData PositionData;
    
    sc.GetTradePosition(PositionData);

    double PositionQuantity = PositionData.PositionQuantity;
    double PositionQuantityWithAllWorkingOrders = PositionData.PositionQuantityWithAllWorkingOrders;

    double OpenProfitLoss = PositionData.OpenProfitLoss;
    double CumulativeProfitLoss = PositionData.CumulativeProfitLoss;
    int WinTrades = PositionData.WinTrades;
    int LoseTrades = PositionData.LoseTrades;
    int TotalTrades = PositionData.TotalTrades;

    int workingOrderExists = PositionData.WorkingOrdersExist;
    int nonAttachedWorkingOrderExists = PositionData.NonAttachedWorkingOrdersExist;

    SCString Message1;
    Message1.AppendFormat("Position Print Current DateTime : %s, PositionQuantity: %d, OpenProfitLoss: %d, PositionQuantityWithAllWorkingOrders: %d, workingOrderExists: %i, nonAttachedWorkingOrderExists: %i", sc.FormatDateTime(sc.BaseDateTimeIn[sc.Index]).GetChars(), PositionQuantity, OpenProfitLoss, PositionQuantityWithAllWorkingOrders, workingOrderExists, nonAttachedWorkingOrderExists);
    sc.AddMessageToLog(Message1, 1);


But I constantly get position quantity = 0 even when there is an open position
Sample output:
Position Printer Current DateTime : 2023-04-14 01:27:06, PositionQuantity: 0, OpenProfitLoss: -125829120, PositionQuantityWithAllWorkingOrders: 0, workingOrderExists: 1, nonAttachedWorkingOrderExists: 0 | 2023-04-14 01:27:50.630 *


Am I missing something here in the code?

Thanks

J
[2023-04-14 04:28:47]
User431178 - Posts: 544
%d is not correct for double, use %f.
Both %d and %i are for integers.

https://cplusplus.com/reference/cstdio/printf/
[2023-04-14 08:16:32]
backinblack - Posts: 35
Ah! Rookie error! Thank you

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

Login

Login Page - Create Account