Login Page - Create Account

Support Board


Date/Time: Thu, 16 Jan 2025 04:56:05 +0000



[Programming Help] - Ascil Bars since entry.

View Count: 2359

[2017-09-27 22:00:52]
vectorTrader - Posts: 86
I am writing my first c++ code and wondering how to count bars since entry. I thought that this would work but apparently not.
First I created a persistant integer. I thought that this would work for exit but apparently its not counting at all. what am i doing wring to count the number of bars since the confirmed entry?

int& BarsSince=sc.GetPersistentInt(3);
  if (sc.Index == 0) {
cbHLC = 0;
   BarsSince=0;
  }
  //Count the number of bars since entry
  //int BarsSinceEntry=0
  
  
  s_SCPositionData PositionData;
  sc.GetTradePosition(PositionData);
  if(PositionData.PositionQuantity != 0)
  {
    if(BarsSince<50)
    {  
      BarsSince++;
    }
    return;
  }
  sc.Subgraph[7][sc.Index]=BarsSince;

  // Create an s_SCNewOrder object.
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = 1;
  NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

  //Specify a Target and a Stop with 8 tick offsets. We are specifying one Target and one Stop, additional targets and stops can be specified as well.
  //NewOrder.Target1Offset = 50*sc.TickSize;
  NewOrder.Stop1Offset = 50*sc.TickSize;
  NewOrder.OCOGroup1Quantity = 1; // If this is left at the default of 0, then it will be automatically set.

  
  //Optional: Check if within allowed time range. In this example we will use 10:00 through 14:00. This is according to the time zone of the chart.
  //int BarTime = sc.BaseDateTimeIn[sc.Index].GetTime();
  //bool TradingAllowed = BarTime >= HMS_TIME(10, 0, 0) && BarTime < HMS_TIME(14, 0, 0);

  //bool TradingAllowed = true;
  // Buy when the last price crosses the moving average from below.
  if (sc.Subgraph[4][sc.Index]> sc.Subgraph[4][sc.Index-5] &&
    sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
  {
    int Result = sc.BuyEntry(NewOrder);
    if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar.
    {
      BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index];
      //Remember the order IDs for subsequent modification and cancellation
      //Target1OrderID = NewOrder.Target1InternalOrderID;
      Stop1OrderID = NewOrder.Stop1InternalOrderID;
      BarsSince=0;
    }
  }

  else if (PositionData.PositionQuantity > 0 && BarsSince>=50)
  {
    int Result = 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];
    }  
  }

[2017-09-28 04:11:39]
Sierra Chart Engineering - Posts: 104368
We will create new functions part of ACSIL to calculate this.

This will be out in the next release.
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
[2017-10-02 20:11:39]
vectorTrader - Posts: 86
What will be the name of the function?
[2017-10-02 22:05:15]
Sierra Chart Engineering - Posts: 104368
These are the functions:
int sc.GetBarsSinceLastTradeOrderEntry()

int sc.GetBarsSinceLastTradeOrderExit()


They are in the latest prerelease 1617.
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
[2017-10-03 08:30:35]
binaryduke - Posts: 373
When entering at bar closure, which bar is used as the entry bar? The bar that has closed or the bar that has just opened?
[2017-10-03 09:19:23]
Sierra Chart Engineering - Posts: 104368
It is whatever bar contains the Date-Time of the order fill.

The source code for those functions is available. They are simply in-line functions in SierraChart.h. The logic of them is quite simple. Also they have not been tested but we would not expect a problem with them.
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

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

Login

Login Page - Create Account