Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated February 21, 2021
February 14th, 2021, 01:00 AM
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;
}
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
February 14th, 2021, 03:25 AM
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
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;
}
}
February 14th, 2021, 04:41 AM
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.
February 14th, 2021, 04:54 AM
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
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.
February 14th, 2021, 06:25 AM
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
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.
February 14th, 2021, 06:27 AM
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
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.
February 14th, 2021, 06:49 AM
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
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.
February 14th, 2021, 07:04 AM
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
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.
February 14th, 2021, 07:08 AM
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
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!
February 14th, 2021, 07:11 AM
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
OMG!!!!!!!
You cannot be serious?
THAT'S WHAT THE CODE IN POST 6 DOES!
Last Updated on February 21, 2021