NexusFi: Find Your Edge


Home Menu

 





Time and sales coding in ACSIL


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one Trembling Hand with 34 posts (15 thanks)
    2. looks_two liboro with 28 posts (2 thanks)
    3. looks_3 bobwest with 2 posts (1 thanks)
    4. looks_4 trendisyourfriend with 1 posts (0 thanks)
      Best Posters
    1. looks_one Big Mike with 1 thanks per post
    2. looks_two bobwest with 0.5 thanks per post
    3. looks_3 Trembling Hand with 0.4 thanks per post
    4. looks_4 liboro with 0.1 thanks per post
    1. trending_up 10,759 views
    2. thumb_up 19 thanks given
    3. group 5 followers
    1. forum 64 posts
    2. attach_file 11 attachments




 
Search this Thread

Time and sales coding in ACSIL

  #31 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360

And this study will mark the price/tick level where highest combined bid/ask volume occurs for each bar. And will work with historical as well as live.


2021-02-14 16_56_39-Window



 
Code
SCSFExport scsf_HighsetBidAskLevels(SCStudyInterfaceRef sc)
{

	SCSubgraphRef BidHighVol = sc.Subgraph[0];
	SCSubgraphRef AskHighVol = sc.Subgraph[1];


	if (sc.SetDefaults)
	{
		// Set the configuration and defaults

		sc.GraphName = "Highset Bid Ask Levels";
		sc.StudyDescription = "Marks on each bar wher the higest price level bid/ask volume occurs";
		sc.AutoLoop = 1;
		sc.MaintainVolumeAtPriceData = 1;  // true

		BidHighVol.Name = "Bid High Vol";
		BidHighVol.DrawStyle = DRAWSTYLE_TRIANGLE_RIGHT;
		BidHighVol.DrawZeros = 0;
		BidHighVol.PrimaryColor = RGB(255, 147, 147);
		BidHighVol.LineWidth = 4;

		AskHighVol.Name = "AskHighVol";
		AskHighVol.DrawStyle = DRAWSTYLE_TRIANGLE_LEFT;
		AskHighVol.DrawZeros = 0;
		AskHighVol.PrimaryColor = RGB(128, 255, 128);
		AskHighVol.LineWidth = 4;


		return;
	}

	SCString DataString;
	int& HigestBidVol = sc.GetPersistentInt(1);
	int& HigestAskVol = sc.GetPersistentInt(2);
	int& PriorArraySize = sc.GetPersistentInt(3);

	float& HigestBidVolPrice = sc.GetPersistentFloat(1);
	float& HigestAskVolPrice = sc.GetPersistentFloat(2);

	if ((int)sc.VolumeAtPriceForBars->GetNumberOfBars() < sc.ArraySize)
		return;

	// reset higest levels on new bar
	if (sc.Index > PriorArraySize || sc.IsFullRecalculation)
	{
		HigestBidVol = 0;
		HigestAskVol = 0;
		PriorArraySize = sc.Index;

		HigestBidVolPrice = 0.0;
		HigestAskVolPrice = 0.0;
	}

	// Get the sum of the volumes from all of the prices at this bar
	unsigned int TotalVolume = 0;

	const s_VolumeAtPriceV2* p_VolumeAtPrice = NULL;
	int VAPSizeAtBarIndex = sc.VolumeAtPriceForBars->GetSizeAtBarIndex(sc.Index);
	for (int VAPIndex = 0; VAPIndex < VAPSizeAtBarIndex; VAPIndex++)
	{
		if (!sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, VAPIndex, &p_VolumeAtPrice))
			break;

		TotalVolume += p_VolumeAtPrice->Volume;

		//Calculate the price.  This requires multiplying p_VolumeAtPrice->PriceInTicks by the tick size
		float Price = p_VolumeAtPrice->PriceInTicks * sc.TickSize;

		//Other members available:
		unsigned int AskVolume = p_VolumeAtPrice->AskVolume;
		unsigned int BidVolume = p_VolumeAtPrice->BidVolume;
		unsigned int NumberOfTrades = p_VolumeAtPrice->NumberOfTrades;

		//DataString.Format("Index: %d,  Price: %f, AskVolume: %d, BidVolume: %d, NumberOfTrades: %d", sc.Index, Price, AskVolume, BidVolume, NumberOfTrades);
		//sc.AddMessageToLog(DataString, 0);

		if (AskVolume > HigestAskVol)
		{
			HigestAskVol = AskVolume;
			HigestAskVolPrice = Price;
		}
		if (BidVolume > HigestBidVol)
		{
			HigestBidVol = BidVolume;
			HigestBidVolPrice = Price;
		}


		BidHighVol[sc.Index] = HigestBidVolPrice;
		AskHighVol[sc.Index] = HigestAskVolPrice;


	}



}

Follow me on Twitter Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
 
  #32 (permalink)
liboro
Prague
 
Posts: 28 since Nov 2016
Thanks Given: 8
Thanks Received: 2

Great, I think we are getting forward, thank you.

This code is the way.

I will try on this describe what I am looking for.

Now we have these:

HigestAskVol = Vol;
HigestAskVolPrice = Price;
HigestBidVol = Vol;
HigestBidVolPrice = Price;

And now I need not only "Higest" volume, but volume for all prices in the bar. So I believe it is the work with the arrays or variables where I am lost.

And the second thing you need to sum a/b volume on these prices, because you get more than TS entries on one price.



Trembling Hand View Post
Because I like banging my head against a wall....


2021-02-14 15_48_55-Window


Here is an example code that will mark on each bar where the largest volume bid and ask trade occur. Not the greatest of studies nor the most efficient but just an example of using T&S data on a chart. And remember sc.GetTimeAndSales() only works on live connections & replay.


 
Code

SCSFExport scsf_TimeNSales(SCStudyGraphRef sc) {

    SCSubgraphRef BidHighVol = sc.Subgraph[0];
    SCSubgraphRef AskHighVol = sc.Subgraph[1];


    if (sc.SetDefaults) {

        sc.GraphName = "Highest_Bid_ASk_Vol";
        sc.StudyDescription = "Mark on each bar the highest bid & ask trade";
        sc.GraphRegion = 0;
        sc.AutoLoop=0; //Use manual looping

        BidHighVol.Name = "Bid High Vol";
        BidHighVol.DrawStyle = DRAWSTYLE_TRIANGLE_RIGHT;
        BidHighVol.DrawZeros = 0;
        BidHighVol.PrimaryColor = RGB(255, 147, 147);
        BidHighVol.LineWidth = 4;

        AskHighVol.Name = "AskHighVol";
        AskHighVol.DrawStyle = DRAWSTYLE_TRIANGLE_LEFT;
        AskHighVol.DrawZeros = 0;
        AskHighVol.PrimaryColor = RGB(128, 255, 128);
        AskHighVol.LineWidth = 4;

    }


    int& HigestBidVol = sc.GetPersistentInt(1);
    int& HigestAskVol = sc.GetPersistentInt(2);
    int& PriorArraySize = sc.GetPersistentInt(3);

    float& HigestBidVolPrice = sc.GetPersistentFloat(1);    
    float& HigestAskVolPrice = sc.GetPersistentFloat(2);     

    int64_t& LastProcessedSequence = sc.GetPersistentInt64(1);

    //This code depends upon manual looping being set
    for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++)
    {
        if (Index == 0)
        {
            PriorArraySize = sc.ArraySize;
        }
        // If there are new bars added
        if (PriorArraySize < Index)
        {
            HigestAskVol = 0;
            HigestAskVolPrice = 0.0;
            HigestBidVol = 0;
            HigestBidVolPrice = 0.0;
           // sc.AddMessageToLog("********    NEW BAR *******************************************************************", 0);
            PriorArraySize = Index;
        }
                

        //reset the sequence number on a full recalculation so we start fresh for each full recalculation.
        if (sc.IsFullRecalculation && sc.UpdateStartIndex == 0) {

            BidHighVol[Index] = 0.0;
            AskHighVol[Index] = 0.0;
            LastProcessedSequence = 0;
        }
            

        // Get the Time and Sales
        c_SCTimeAndSalesArray TimeSales;
        sc.GetTimeAndSales(TimeSales);
        if (TimeSales.Size() == 0)
            return;  // No Time and Sales data available for the symbol

        //Set the initial sequence number
        if (LastProcessedSequence == 0)
            LastProcessedSequence = TimeSales[TimeSales.Size() - 1].Sequence;

        // Loop through the Time and Sales.
        for (int TSIndex = 0; TSIndex < TimeSales.Size(); ++TSIndex)
        {
            //do not reprocess previously processed sequence numbers.
            if (TimeSales[TSIndex].Sequence <= LastProcessedSequence)
                continue;

            //only interested in trade records
            if (TimeSales[TSIndex].Type == SC_TS_BID || TimeSales[TSIndex].Type == SC_TS_ASK)
            {

                /*int AskVol = TimeSales[TSIndex].AskSize;
                //int TotalAsks = TimeSales[TSIndex].TotalAskDepth;
                //int BidVol = TimeSales[TSIndex].BidSize;
                //int TotalBids = TimeSales[TSIndex].TotalBidDepth;
                float BidPrice = TimeSales[TSIndex].Bid;
                float AskPrice = TimeSales[TSIndex].Ask;

                SCDateTime RecordAdjustedDateTime = TimeSales[TSIndex].DateTime;
                // Apply the time zone offset for the chart. This will result in the actual date-time of the record in the charts time zone.
                RecordAdjustedDateTime += sc.TimeScaleAdjustment;*/

                float Price = TimeSales[TSIndex].Price;
                int Vol = TimeSales[TSIndex].Volume;
                int TradeType = TimeSales[TSIndex].Type; // at bid or ask

                // if last trade volume is the higest for current bar
                if (TimeSales[TSIndex].Type == SC_TS_BID && Vol > HigestBidVol) {
                    HigestBidVol = Vol;
                    HigestBidVolPrice = Price;
                }
                if (TimeSales[TSIndex].Type == SC_TS_ASK && Vol > HigestAskVol) {
                    HigestAskVol = Vol;
                    HigestAskVolPrice = Price;
                }

                

                /*SCString LargevolString;
                LargevolString.Format("LastProcessedSequence: %d, BarIndex: %d, TSIndex: %d, Largest Bid Vol: %d Price: %0.2f", LastProcessedSequence, sc.Index, TSIndex, HigestBidVol, HigestBidVolPrice);
                sc.AddMessageToLog(LargevolString, 0);*/


                LastProcessedSequence = TimeSales[TimeSales.Size() - 1].Sequence;
            }
        }

        BidHighVol[Index] = HigestBidVolPrice;
        AskHighVol[Index] = HigestAskVolPrice;
    }

}


Reply With Quote
  #33 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360


Unless you can write out some pseudo code or t&s data from one bar showing what you want done with it I'm lost as to any further action.

Follow me on Twitter Reply With Quote
  #34 (permalink)
liboro
Prague
 
Posts: 28 since Nov 2016
Thanks Given: 8
Thanks Received: 2

Ok, understand.

This is what I trying to solve - assign TS volume on relevant prices and add volume if there is a new volume entries on the price.

Hope it is clear now.

 
Code
        for (int TSIndex = 0; TSIndex < TimeSales.Size(); ++TSIndex)
        {

	if (TimeSales[TSIndex].Type == SC_TS_BID || TimeSales[TSIndex].Type == SC_TS_ASK)
		{
			float Price = TimeSales[TSIndex].Price;
			sc.Subgraph[Price][sc.Index] += TimeSales[TSIndex].Volume;
		}
         }



Trembling Hand View Post
Unless you can write out some pseudo code or t&s data from one bar showing what you want done with it I'm lost as to any further action.


Reply With Quote
  #35 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360


liboro View Post
Ok, understand.

This is what I trying to solve - assign TS volume on relevant prices and add volume if there is a new volume entries on the price.

Hope it is clear now.

 
Code
        for (int TSIndex = 0; TSIndex < TimeSales.Size(); ++TSIndex)
        {

	if (TimeSales[TSIndex].Type == SC_TS_BID || TimeSales[TSIndex].Type == SC_TS_ASK)
		{
			float Price = TimeSales[TSIndex].Price;
			sc.Subgraph[Price][sc.Index] += TimeSales[TSIndex].Volume;
		}
         }

That won't work. You are assigning volume to a subgraph bar index using a float price variable. There is no subgraph for a Time and Sales prices. Does that even compile? If for example you price is 72.6 your adding volume to bar subgraph 72.6!

Chart subgraphs are equal and the same number bars as in a chart.

Follow me on Twitter Reply With Quote
  #36 (permalink)
liboro
Prague
 
Posts: 28 since Nov 2016
Thanks Given: 8
Thanks Received: 2

No, it cant be compiled, there is an error.

Do you have any idea how to code it?



Trembling Hand View Post
That won't work. You are assigning volume to a subgraph bar index using a float price variable. There is no subgraph for a Time and Sales prices. Does that even compile?

Chart subgraphs are equal and the same number bars as in a chart.


Reply With Quote
  #37 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360


liboro View Post
No, it cant be compiled, there is an error.

Do you have any idea how to code it?

Mate this is like pulling teeth.... but more painful!

After 37 posts you still haven't clearly explained what you are trying to do!

I'm sure it can be coded it's just some sort of vol at price study but the lack of a full explanation or example has me done.

Follow me on Twitter Reply With Quote
  #38 (permalink)
liboro
Prague
 
Posts: 28 since Nov 2016
Thanks Given: 8
Thanks Received: 2

Actually, I do not understand what is not clear about that.

You post me a code that reads the tape, sequence by sequence.

Your code shows only one trade, the biggest in the bar.
But there could be more than one trade (sequence) on one price in the bar:

sequence price volume
1 49.80 15
2 49.80 20
3 49.80 7
4 49.90 10

sum for 49.80 is 42
sum for 49.90 is 10

I am trying to find a solution how to sum all trades on every price level in the bar - see above.

I believe it cant be more clearly described.




Trembling Hand View Post
Mate this is like pulling teeth.... but more painful!

After 37 posts you still haven't clearly explained what you are trying to do!

I'm sure it can be coded it's just some sort of vol at price study but the lack of a full explanation or example has me done.


Reply With Quote
  #39 (permalink)
 Trembling Hand 
Melbourne, Land of Oz
 
Experience: Advanced
Platform: Sierra Chart, CQG
Broker: CQG
Trading: HSI
Posts: 246 since Jun 2011
Thanks Given: 28
Thanks Received: 360


liboro View Post
sequence price volume
1 49.80 15
2 49.80 20
3 49.80 7
4 49.90 10

sum for 49.80 is 42
sum for 49.90 is 10

I am trying to find a solution how to sum all trades on every price level in the bar - see above.

I believe it cant be more clearly described.

OMG!!!!!!!

You cannot be serious?

THAT'S WHAT THE CODE IN POST 6 DOES!

Follow me on Twitter Reply With Quote
  #40 (permalink)
liboro
Prague
 
Posts: 28 since Nov 2016
Thanks Given: 8
Thanks Received: 2


Code in post 6 do it based on VAP,
but not based od Time And Sales data.

Thats why I metioned Large Volume Trade Indicator as example,
filtering orders by order size.

YOU CANNOT DO THAT BY VAP.




Trembling Hand View Post
OMG!!!!!!!

You cannot be serious?

THAT'S WHAT THE CODE IN POST 6 DOES!


Reply With Quote




Last Updated on February 21, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts