Login Page - Create Account

Support Board


Date/Time: Tue, 07 May 2024 14:20:50 +0000



[Programming Help] - PositionData returns zero values

View Count: 743

[2018-03-24 17:31:13]
User257964 - Posts: 6
Dear SC support, for some reason PositionData structure contains and returns zero values after opening any long/short position in any of my scripts. Even when trying the sample script scsf_TradingExample from the tradingsystem.cpp:

  if (TradingAllowed && sc.CrossOver(Last, SimpMovAvgSubgraph) == CROSS_FROM_BOTTOM && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
  {
    Result = (int)sc.BuyEntry(NewOrder);
    //Result = sc.BuyOrder(NewOrder);
    //If there has been a successful order entry, then draw an arrow at the low of the bar.
    if (Result > 0)
    {
      r_BuyEntryInternalOrderID = NewOrder.InternalOrderID;
      SCString InternalOrderIDNumberString;
      InternalOrderIDNumberString.Format("BuyEntry Internal Order ID: %d", r_BuyEntryInternalOrderID);
      sc.AddMessageToLog(InternalOrderIDNumberString, 0);

      BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index];
    }
  }


  // When there is a long position AND the Last price is less than the price the Buy Entry was filled at minus Stop Value, OR there is a long position AND the Last price is greater than the price the Buy Entry was filled at plus the Target Value.
  else if (PositionData.PositionQuantity > 0
    && (LastTradePrice <= PositionData.AveragePrice - StopValue.GetFloat() ||
      LastTradePrice >= PositionData.AveragePrice + TargetValue.GetFloat()))
  {
    Result = (int)sc.BuyExit(NewOrder);

    //If there has been a successful order entry, then draw an arrow at the high of the bar.
    if (Result > 0)
    {
      BuyExitSubgraph[sc.Index] = sc.High[sc.Index];
    }
  }

which I copy and paste, the output is the same.
sc.MaintainTradeStatisticsAndTradesData set on true.

Please advise.
Thank you
[2018-03-24 21:11:20]
Sierra Chart Engineering - Posts: 104368
Is this during live trading trading and what order type are you using?
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-03-24 21:12:38
[2018-03-25 12:15:17]
User257964 - Posts: 6
It is sim and order type SCT_ORDERTYPE_MARKET.
[2018-03-26 22:11:46]
Sierra Chart Engineering - Posts: 104368
Make sure you call this function after the order has been submitted and filled:
Automated Trading From an Advanced Custom Study: sc.GetTradePosition
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, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-03-27 14:40:23]
User257964 - Posts: 6
Well, I copy & paste the sample script scsf_TradingExample from the tradingsystem.cpp and get zero values. Should there be any adjustments done?

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

Login

Login Page - Create Account