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 Big Mike with 1 posts (1 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,792 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

  #21 (permalink)
liboro
Prague
 
Posts: 28 since Nov 2016
Thanks Given: 8
Thanks Received: 2

Could you build Large Volume Trade Indicator based on VAP function?

I do not think so and this is the reason why I am trying to do this.




Trembling Hand View Post
I think you have a fundamental misunderstanding of what is going on here.

TS data is not a different data set from "other" data.

Could you explain why you think it is? Where does it come from?


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
What broker to use for trading palladium futures
Commodities
Trade idea based off three indicators.
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #22 (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
Could you build Large Volume Trade Indicator based on VAP function?

Yes. But as your details of exactly what you want are missing or confusing we are going in circles.

For example my post at #4 and yours at #17 are the same thing.

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


Ok, could you please share with me how achieve filtering orders by their size in VAP?

I dont think that we are in the circles, maybe it is my fault that I wrongly assumed that I
cant filter order size in VAP. Sorry for that.



Trembling Hand View Post
Yes. But as your details of exactly what you want are missing or confusing we are going in circles.

For example my post at #4 and yours at #17 are the same thing.


Reply With Quote
  #24 (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, could you please share with me how achieve filtering orders by their size in VAP?

I dont think that we are in the circles, maybe it is my fault that I wrongly assumed that I
cant filter order size in VAP. Sorry for that.

Firstly that's not what my post at 4 and yours at #17 is asking to do but rather break down ask/bid volume.

But
Filter order size by what? A threshold amount? A descending/ascending amount?

It may help if you can say what the SC large volume Trader study doesn't do what you want it to do.

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

Here is my post #1:
I need a code for Sierra Chart which is based on Time Sales data. The code would put ask/bid values on the relevant prices. The very same as volume at price, but based on TS. Only part of the code or help would be enough for me.

So your post #4 is relevant to describe and understand price levels. The same is the #17, I always mentioned that volume on this levels should be from the TS, not VAP.

Filter order by threshold amount, that means for example only orders bigger than 5.



Trembling Hand View Post
Firstly that's not what my post at 4 and yours at #17 is asking to do but rather break down ask/bid volume.

But
Filter order size by what? A threshold amount? A descending/ascending amount?

It may help if you can say what the SC large volume Trader study doesn't do what you want it to do.


Reply With Quote
  #26 (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
Here is my post #1:
I need a code for Sierra Chart which is based on Time Sales data. The code would put ask/bid values on the relevant prices. The very same as volume at price, but based on TS. Only part of the code or help would be enough for me.

So your post #4 is relevant to describe and understand price levels. The same is the #17, I always mentioned that volume on this levels should be from the TS, not VAP.

Filter order by threshold amount, that means for example only orders bigger than 5.

LOL!!

So back to my code at #12 all you have to do is decide how you want to represent that on the chart rather than save to txt

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

In this code I do not see any part which assign Ask/Bid volume to the prices.

In my opinion it is only the tape, trade by trade.

The crucial thing how to sum all ask/bid volume on the relevant prices,
think about it like you have reversal chart, price ticks one up, one down
and you need to sum all A/B volume on the concrete levels.


 
Code
SCSFExport scsf_Save_TimeNSales(SCStudyGraphRef sc) {

    SCInputRef OutputFile = sc.Input[0];


    if (sc.SetDefaults) {

        // https://www.sierrachart.com/SupportBoard.php?ThreadID=36979

        sc.GraphName = "Save_TimeNSales";
        sc.StudyDescription = "Save Time and sales to file";
        sc.GraphRegion = 0;
        //sc.AutoLoop=true; 
        sc.FreeDLL = 1;

        OutputFile.Name = "The storage link";
        SCString OutputFileDefaultName;
        OutputFileDefaultName.Format("C:\\SierraChart\\Data\\1_%s.txt", sc.Symbol.GetSubString(2, 0).GetChars());
        OutputFile.SetString(OutputFileDefaultName);

    }

    std::ofstream file(OutputFile.GetString(), std::ios_base::app);

    if (!file) {

        SCString Buffer;
        Buffer.Format("Unable to open file %s", OutputFile.GetString());
        sc.AddMessageToLog(Buffer, 1);
        //return; 

    }



    if (sc.Index == sc.ArraySize - 1)
    {

        __int64& LastProcessedSequence = sc.GetPersistentInt64(1);
        c_SCTimeAndSalesArray TimeSales;
        sc.GetTimeAndSales(TimeSales);
        if (TimeSales.Size() == 0)
            return;


        if (LastProcessedSequence != 0)
        {
            for (int TSIndex = 0; TSIndex < TimeSales.Size(); ++TSIndex)
            {
                if (TimeSales[TSIndex].Sequence < LastProcessedSequence)
                    continue;

                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 Price = TimeSales[TSIndex].Price;
                    int Vol = TimeSales[TSIndex].Volume;
                    int TradeType = TimeSales[TSIndex].Type; // at bid or ask



                    int ValueFormat = sc.BaseGraphValueFormat;
                    SCString formatString = " %i/%02i/%02i  %02i:%02i:%02i: %03i , Index: %i, Price: %0.4f, Vol: %i BidAsk: %i";
                    SCDateTime TradeDateTime = TimeSales[TSIndex].DateTime;
                    TradeDateTime += sc.TimeScaleAdjustment;
                    int Year, Month, Day, Hour, Minute, Second, MilliSecond;
                    TradeDateTime.GetDateTimeYMDHMS_MS(Year, Month, Day, Hour, Minute, Second, MilliSecond);


                    SCString BarDataString;
                    BarDataString.Format(formatString, Year, Month, Day, Hour, Minute, Second, MilliSecond, TSIndex, Price, Vol, TradeType);
                    file << BarDataString << std::endl;

                }

            }

        }

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

    }



}



Trembling Hand View Post
LOL!!

So back to my code at #12 all you have to do is decide how you want to represent that on the chart rather than save to txt


Reply With Quote
  #28 (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
In this code I do not see any part which assign Ask/Bid volume to the prices.

Mate I think you are lost here! This is the code that identifies the trade at bid or ask,

 
Code
int TradeType = TimeSales[TSIndex].Type; // at bid or ask
This is the code that identifies the price for that trade.
 
Code
float Price = TimeSales[TSIndex].Price;


liboro View Post
In my opinion it is only the tape, trade by trade.

The crucial thing how to sum all ask/bid volume on the relevant prices,
think about it like you have reversal chart, price ticks one up, one down
and you need to sum all A/B volume on the concrete levels.

Its up to you to either make it clearer what magic you want to happen with it. You are now talking about what I did in the first study code!!

Follow me on Twitter Reply With Quote
  #29 (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

I'll give it one more shot to figure out what you are trying to do here.

Can I have an picture of a chart well annotated with what data/subgraphs/etc you want from what data. Use data like this and draw it on a chart,


liboro View Post
PRICE 69.60 AV (from TS) = XY, BV (from TS) = XY
PRICE 69.61 AV (from TS) = XY, BV (from TS) = XY
PRICE 69.62 AV (from TS) = XY, BV (from TS) = XY
PRICE 69.63 AV (from TS) = XY, BV (from TS) = XY


Follow me on Twitter Reply With Quote
  #30 (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


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;
    }

}

Follow me on Twitter 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