NexusFi: Find Your Edge


Home Menu

 





ACSIL: working with time and sales data


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one Nicolas11 with 31 posts (22 thanks)
    2. looks_two yonatan with 6 posts (5 thanks)
    3. looks_3 mkruss with 3 posts (0 thanks)
    4. looks_4 ozunainc with 3 posts (0 thanks)
    1. trending_up 19,876 views
    2. thumb_up 28 thanks given
    3. group 12 followers
    1. forum 47 posts
    2. attach_file 17 attachments




 
Search this Thread

ACSIL: working with time and sales data

  #21 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

Thanks @Jolew

I agree with you, and as said above, this parameter could me modified in Global Settings >> Data/Trade Service Settings.

But even 50,000 or 500,000 trades is nothing for instruments as ES (a few minutes, one day, ...)
And it would be always far less than the data definitively embedded in a 1-tick chart.
I have the feeling the purpose of GetTimeAndSales is to have access to the more recent T&S, and then forget it when the newer arrive.
Or do you manage to use SC T&S information in a more historical way?

Nicolas

Visit my NexusFi Trade Journal Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #22 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537

You can directly attach .cpp code without changing to .txt.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #23 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769


Thanks @Big Mike,

Actually, it was because there were other things in the .cpp not relevant for this thread. So I have copy/pasted the relevant parts in the .txt
Next time, I will make a clean .cpp: will be better!

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #24 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

@yonatan,

At this stage, I would like to clarify something because I have perhaps mixed too much your initial question and my own needs. And it could be time to wrap things up.

We both want to access to the T&S information within a bar.

For me, the crucial question is: only in real-time or also historically?

If only real-time... GetTimeAndSales() is the solution. It gives access the most recent 2,000 trades (or more as defined by the user).
It shall not be too difficult to emulate SC's pullback column by finding the most recent High or Low within the T&S and examining all the trades that took place between this High/Low and now.

If historical... GetTimeAndSales() cannot be used.
I see no other way than using a secondary 1-tick chart (and this is also what is suggested by SC documentation).
The challenge is to make the correspondence tick by tick between the main chart (for instance: 2-min) and the 1-tick chart.
At least 2 solutions:
1) the one I proposed above which "synchronizes" the main chart and the 1-tick chart based on the progress of volume
2) overlay-based solution, which is not precise to the tick.

After 1-night sleep, I think that my solution 1), even it seems to work very well and to the tick, is too "heavy". Even for me, it could be too dangerous to use this code for my research. In 2 months, I will have forgotten the logic behind.
So, I am going to explore a solution with overlay. It would not be precise to the tick, but it would be more robust (since based on SC built-in feature) and the differences will only occur at the limit between two bars when trades took place in the same second. Should be OK. More on this later.

Once more, @yonatan, I am aware that this is not your current working subject. Do not feel forced to answer. This message was more for the record, and to clarify things.

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #25 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71

@Nicolas11,

I am grateful for all the stuff that you brought here even some of it doesn't directly relate to my need. I learned and will learn a lot from the codes that you attached.

Like you said, the GetTimeAndSales() will probably be good enough for me because at this point I am mostly interested in the recent TnS entries.

Once the market opens I will run the attached very simple code just to make sure that the values that I get from:

TSIndex = TimeSales.GetArraySize()-1;
LastBid = TimeSales[TSIndex].BidSize;
LastAsk = TimeSales[TSIndex].AskSize;


are really identical to the very last enteries of the Time and Sales window. (The GetTimeAndSales() will be useless on a replay mode so I wll have to wait for the market to open). If this code works I will go on from there.

Again, this was very helpful for me and I really enjoyed following your progress

Attached Files
Elite Membership required to download: my_TnS_practice.cpp
Started this thread Reply With Quote
Thanked by:
  #26 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

@yonatan,

You have probably already seen them, but you can also run built-in studies:
  • Time and Sales AskSize
  • Time and Sales Bid&Ask
  • Time and Sales BidSize
  • Time and Sales Price
  • Time and Sales Time
  • Time and Sales Volume

I am mentioning them because their code is accessible within studies.cpp
These codes use GetTimeAndSales, and could be considered as a good practice (since written by SC developers).
It could give you ideas for your own codes.

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #27 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

This message is more "for the record"...

In the above spirit, I have tried to make simple correspondence between a main chart (here: 15-second chart) and a 1-tick chart.

I have renounced to make a correspondence "to the tick" and I'm OK to use timestamp as SC does with its overlay mechanism.

In this example, I focus on 21:46:30 bar. Next bar is at 21:46:45.

I have used 3 methods. Each of the 3 methods gives a different correspondence between main chart and 1-tick chart. To avoid any misunderstanding... I do not say that it is a "bug" of SC. Not at all. Everything is explained by the overlay mechanism.

Method 1: Overlay of 15s chart on 1-tick chart.

On the 15s chart, I have plotted the Bar Number with a very simple study ( sc.Subgraph[0][sc.Index] = (float) sc.Index; ).
And I have overlaid this 15s Bar Number on the 1-tick chart.
It allows seeing all the ticks associated with 21:46:30:
- the first is the last tick before 21:46:30
- the last is the tick before the last tick with 21:46:45 timestamp



Method 2: overlay of 1-tick chart on 15s chart

On the 1-tick chart, I have plotted the Bar Number with a very simple study ( sc.Subgraph[0][sc.Index] = (float) sc.Index; ).
And I have overlaid this 1-tick Bar Number on the 15-s chart.
The unique tick associated with 21:46:30 is the last tick before 21:46:45



Method 3: use of SC built-in functions

On the 15s chart, I have used the functions sc.GetNearestMatchForDateTimeIndex and sc.GetContainingIndexForDateTimeIndex to know the corresponding bar on the 1-tick chart.
The tick associated with 21:46:30 is the first tick with 21:46:30 timestamp

I will probably use one of three methods to have access historically to T&S within any bar. More on this later...

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #28 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

Don't worry... this message and the 3 following ones are probably the last of the series!

Reminder: we want to access to the T&S information within a bar.
- GetTimeAndSales() cannot be used historically;
- I have proposed above a code which "synchronizes" the main chart and a secondary 1-tick chart based on the progress of volume; if no mistake, this allows an access to all ticks within the bar to the tick but the code is rather complicated.

I am now exploring the last idea: make an easy correspondence between the main chart and a secondary 1-tick chart using timestamps.

It could be done with (i) overlays or (ii) SC built-in function as "sc.GetNearestMatchForDateTimeIndex".
Both are very similar (use of timestamp). The exact differences have been illustrated in the previous message. I have chosen to use the SC built-in function since it is the easiest way (no overlay to perform).

In the two following messages, I will use this method to:
1) emulate the volume of each bar by adding the volume of all ticks identified as belonging to the bar;
2) emulate SC's footprint (Numbers Bars)

As we know (and in consistency with SC documentation), overlays and sc.GetNearestMatchForDateTimeIndex are not precise to the tick, since there could be several ticks with the same timestamp (= several trades in the same second).
To evaluate whether this is a problem or not, we will compare emulated and built-in results in the 2 above-mentioned emulations.

Let's have fun!

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #29 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

Example 1: emulation of the volume of each bar

At each bar, by using sc.GetNearestMatchForDateTimeIndex, the study identifies the ticks of the secondary 1-tick chart which belong to the bar (not taking into account the well-known timestamp issue).
Then the study adds the volume of all these ticks.
And compares it to the "normal" volume of the bar.
Quite close!



(Just tested on historical data. No test on replay or real-time.)

Nicolas

 
Code
// Nicolas11 @ nexusfi.com (formerly BMT)
// v1
// August 12th, 2012
SCSFExport scsf_Emulated_Volume_With_GetNearestMatchForDateTimeIndex(SCStudyGraphRef sc) {

	// Reference to input:
	SCInputRef OneTickChart = sc.Input[0];

	// Reference to outputs:
	SCSubgraphRef EmulatedVolume = sc.Subgraph[0];
	SCSubgraphRef BuiltInVolume = sc.Subgraph[1];

	if (sc.SetDefaults) {
		
		sc.GraphName = "Emulated Volume (with sc.GetNearestMatchForDateTimeIndex)";
		sc.StudyDescription = "Emulated Volume (with sc.GetNearestMatchForDateTimeIndex)";

		// Input:
		OneTickChart.Name = "1-tick chart";
		OneTickChart.SetChartNumber(1);

		// Outputs:
		EmulatedVolume.Name = "Emulated Volume";
		EmulatedVolume.DrawStyle = DRAWSTYLE_POINT;
		BuiltInVolume.Name = "Built-in Volume";
		BuiltInVolume.DrawStyle = DRAWSTYLE_DASH;

		sc.FreeDLL = 1;
		sc.AutoLoop = 1;
		return;
	}

	// Reference to one-tick data:
	SCGraphData OneTickGraphData;
	sc.GetChartBaseData(OneTickChart.GetChartNumber(), OneTickGraphData);

	// What are the ticks on the 1-tick chart which correspond to the current bar of the main chart?
	int FirstTickBarNumber = sc.GetNearestMatchForDateTimeIndex(OneTickChart.GetChartNumber(), sc.Index);
	int LastTickBarNumber;
	if ( sc.Index == sc.ArraySize-1 ) { // last bar on the main chart
		LastTickBarNumber = OneTickGraphData[0].GetArraySize()-1;
	} else { // not the last bar on the main chart
		LastTickBarNumber = sc.GetNearestMatchForDateTimeIndex(OneTickChart.GetChartNumber(), sc.Index+1) - 1;
	}

	// Let's iterate on these ticks to emulate volume:
	EmulatedVolume[sc.Index] = 0.0f;
	for ( int i = FirstTickBarNumber; i <= LastTickBarNumber ; i++ ) {
		EmulatedVolume[sc.Index] += OneTickGraphData[SC_VOLUME][i];
	}
	
	// Let's also plot the "normal" volume:
	BuiltInVolume[sc.Index] = sc.Volume[sc.Index];
}

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #30 (permalink)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769


Example 2: emulation of SC's footprint

We are not going to emulate the whole footprint, but only the ask volume of the highest price of the bar. The code can very easily be adapted for any other information of the footprint.

At each bar, by using sc.GetNearestMatchForDateTimeIndex, the study identifies the ticks of the secondary 1-tick chart which belong to the bar (not taking into account the well-known timestamp issue).

Then the study adds the volume of these ticks... but only if the trade was at the ask and the trade took place at the highest price of the bar.

And compares it to the "normal" information given by the footprint.

Quite close, even if there are some discrepancies (due to the timestamp effect).



(Just tested on historical data. No test on replay or real-time.)

Nicolas

 
Code
// Nicolas11 @ nexusfi.com (formerly BMT)
// v1
// August 12th, 2012
SCSFExport scsf_Emulated_Footprint_With_GetNearestMatchForDateTimeIndex(SCStudyGraphRef sc) {

	// Reference to input:
	SCInputRef OneTickChart = sc.Input[0];

	// Reference to outputs:
	SCSubgraphRef EmulatedAskVolumeOnHighestPrice = sc.Subgraph[0];
	SCSubgraphRef BuiltInAskVolumeOnHighestPrice = sc.Subgraph[1];

	if (sc.SetDefaults) {
		
		sc.GraphName = "Emulation of Footprint (with sc.GetNearestMatchForDateTimeIndex)";
		sc.StudyDescription = "Emulation of Footprint (with sc.GetNearestMatchForDateTimeIndex)";

		// Input:
		OneTickChart.Name = "1-tick chart";
		OneTickChart.SetChartNumber(1);

		// Outputs:
		EmulatedAskVolumeOnHighestPrice.Name = "Emulated Ask Volume on Highest Price";
		EmulatedAskVolumeOnHighestPrice.DrawStyle = DRAWSTYLE_POINT;
		BuiltInAskVolumeOnHighestPrice.Name = "Built-in Ask Volume on Highest Price";
		BuiltInAskVolumeOnHighestPrice.DrawStyle = DRAWSTYLE_DASH;

		sc.FreeDLL = 1;
		sc.AutoLoop = 1;
		sc.MaintainVolumeAtPriceData = 1; // ***
		return;
	}

	// Reference to one-tick data:
	SCGraphData OneTickGraphData;
	sc.GetChartBaseData(OneTickChart.GetChartNumber(), OneTickGraphData);

	// 1. Built-in Ask Volume on Highest Price

	// The below code retrieves the information from the footprint
	// Source: studies7.cpp

	if ((int)sc.VolumeAtPriceForBars->GetNumberOfBars() >= sc.ArraySize) {

		unsigned int askOfHighestPrice = 0;
		unsigned int bidOfLowestPrice = 0;
		s_VolumeAtPriceV2 *p_VolumeAtPriceAtIndex;

		int Count = sc.VolumeAtPriceForBars-> GetSizeAtBarIndex(sc.Index);
		
		sc.VolumeAtPriceForBars->GetVAPElementAtIndex(sc.Index, Count-1, &p_VolumeAtPriceAtIndex);
		if (p_VolumeAtPriceAtIndex) {
			BuiltInAskVolumeOnHighestPrice[sc.Index] = (float) p_VolumeAtPriceAtIndex->AskVolume;
		}
	}

	// 2. Emulated Ask Volume on Highest Price

	// What are the ticks on the 1-tick chart which correspond to the current bar of the main chart?
	int FirstTickBarNumber = sc.GetNearestMatchForDateTimeIndex(OneTickChart.GetChartNumber(), sc.Index);
	int LastTickBarNumber;
	if ( sc.Index == sc.ArraySize-1 ) { // last bar on the main chart
		LastTickBarNumber = OneTickGraphData[0].GetArraySize()-1;
	} else { // not the last bar on the main chart
		LastTickBarNumber = sc.GetNearestMatchForDateTimeIndex(OneTickChart.GetChartNumber(), sc.Index+1) - 1;
	}

	// Let's iterate on these ticks
	// and find all the trades at the ask AND at the highest price of the bar
	EmulatedAskVolumeOnHighestPrice[sc.Index] = 0.0f;
	for ( int i = FirstTickBarNumber; i  0
				&& sc.FormattedEvaluate(OneTickGraphData[SC_LAST][i], sc.BaseGraphValueFormat, EQUAL_OPERATOR, sc.High[sc.Index], sc.BaseGraphValueFormat) ) {
			EmulatedAskVolumeOnHighestPrice[sc.Index] += OneTickGraphData[SC_VOLUME][i];
		}
	}
}

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on November 9, 2019


© 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