ACSIL: working with time and sales data - Sierra Chart Programming | futures io social day trading
futures io futures trading


ACSIL: working with time and sales data
Updated: Views / Replies:8,233 / 44
Created: by yonatan Attachments:17

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 17  
 
Thread Tools Search this Thread
 

ACSIL: working with time and sales data

  #21 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

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

Reply With Quote
 
  #22 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,220 received

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

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #23 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received


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

Reply With Quote
 
  #24 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

@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


Last edited by Nicolas11; August 12th, 2012 at 07:00 AM.
Reply With Quote
 
  #25 (permalink)
Elite Member
Haifa Israel
 
Futures Experience: Beginner
Platform: sierra chart
Broker/Data: Optimus Trading Group/Rithmic
Favorite Futures: es
 
Posts: 90 since Apr 2012
Thanks: 49 given, 65 received

@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
Register to download File Type: cpp my_TnS_practice.cpp (702 Bytes, 29 views)
Reply With Quote
The following user says Thank You to yonatan for this post:
 
  #26 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

@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


Last edited by Nicolas11; August 12th, 2012 at 06:33 PM.
Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #27 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #28 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

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

Reply With Quote
 
  #29 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

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!

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Nicolas

 
Code
// Nicolas11 @ futures.io (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];
}


Last edited by Nicolas11; August 13th, 2012 at 03:21 AM.
Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #30 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received


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).

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Nicolas

 
Code
// Nicolas11 @ futures.io (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];
		}
	}
}


Last edited by Nicolas11; August 13th, 2012 at 02:50 AM.
Reply With Quote
The following user says Thank You to Nicolas11 for this post:

Reply



futures io > > > > > ACSIL: working with time and sales data

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Time and Sales - Level I - Level II - tick data trendisyourfriend Traders Hideout 4 August 28th, 2014 01:14 AM
ACSIL: How do I get the time value of a Vertical line that I have drawn on the chart yonatan Sierra Chart Programming 7 June 25th, 2012 08:20 AM
Austerity Isn't Working; It's Time for a Plan B Quick Summary News and Current Events 0 June 6th, 2011 07:40 AM
Time and Sales help traderTX The Elite Circle 3 May 3rd, 2011 11:14 AM
Is it possible to get "historical" Time and Sales data? adaseb Reviews of Brokers and Data Feeds 2 September 8th, 2010 12:18 PM


All times are GMT -4. The time now is 01:50 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-13 in 0.16 seconds with 20 queries on phoenix via your IP 54.92.201.232