Login Page - Create Account

Support Board


Date/Time: Thu, 28 Mar 2024 17:30:23 +0000



sc.GetTradePosition() : from where does it get the data?

View Count: 319

[2023-03-07 15:41:12]
BenjFlame - Posts: 302
Hi Sierra,
I put...


s_SCPositionData PositionData;
int Result = sc.GetTradePosition(PositionData);
int Quantity = PositionData.PositionQuantity;
if (Quantity == 0)
return;


...in a trading ACSIL study top level right after SetDefaults block.
So, it gets triggered multiple times intrabar. Does it query the remote trading broker each time to get this info? Or is it local with some sort of local cache of that info? I guess it could cause a problem if it requests the data continuously from the broker so I'm wondering how it works.

Also, is it ok to have this code where I put it? Just after the default block and being called several times intrabar?
[2023-03-10 16:56:54]
BenjFlame - Posts: 302
Let me reformulate.
Each time this code is run:


s_SCPositionData PositionData;
int Result = sc.GetTradePosition(PositionData);
int Quantity = PositionData.PositionQuantity;

From where will it pull the PositionData information? From a local cache or from remote broker in the context of live trading?
Because if this code must run on each chart update and pull the data over the internet from the remote broker, it might significantly slow down operations. I'm testing on the simulator so I'm not sure how it behaves but need to know.
[2023-03-10 17:13:48]
Sierra_Chart Engineering - Posts: 13609
No absolutely not:

Does it query the remote trading broker each time to get this info?

This data comes from the data that you see in Trade >> Trade Positions Window for non-simulated trading, or from the internal Trades List in a chart in the case of simulated trading.



You can call the function frequently.
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
Date Time Of Last Edit: 2023-03-10 17:14:06
[2023-03-10 17:37:52]
User90125 - Posts: 715
Also review this page carefully: Automated Trading From an Advanced Custom Study: sc.GetTradePosition

The s_SCPositionData::PositionQuantity is updated when an order fill occurs in Trade Simulation Mode or is received from the external Trading service. Therefore, in the case of non-simulated trading, there is not an immediate update. Only when an order fill occurs.

Not sure if this is concurrent with what Engineering just posted above though.

In any event, you'll want to make sure that sc.MaintainTradeStatisticsAndTradesData is enabled in the SetDefaults block as well:

      
  if (sc.SetDefaults)
  {

    // Set the configuration and defaults

    ...

    //This should be set to true when a trading study uses trading functions.
    sc.MaintainTradeStatisticsAndTradesData = true;

    return;
  }

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

Login

Login Page - Create Account