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

  #31 (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

Conclusion

1. To obtain T&S information in real-time from ACSIL: GetTimeAndSales()

2. To access to the T&S information within a bar historically from ACSIL:

- GetTimeAndSales() is not adapted

- There are some solutions to precisely identify to the tick all the individual ticks belonging to a given bar. For instance, I have proposed above a code which "synchronizes" the main chart and a secondary 1-tick chart based on the progress of volume. But these solutions are rather heavy and complicated.

- "sc.GetNearestMatchForDateTimeIndex" allows identifying the ticks of a secondary 1-tick chart belonging to a given bar, but there are some discrepancies due to the "timestamp effect". However, the 2 examples above show that the correspondence is not too bad.

- Overlays could also be used. This solution has not been tested, since similar to the previous (with respect to timestamp effect) and a little more complicated.

3. I am absolutely impressed by the possibilities of Sierra Chart.

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Deepmoney LLM
Elite Quantitative GenAI/LLM
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #32 (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

The next 4 messages will be related to @yonatan's original question: use in real-time of SC's Time & Sales information obtained by sc.GetTimeAndSales()

Visit my NexusFi Trade Journal Reply With Quote
  #33 (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


Tip: how to know the DateTime of a trade belonging to the T&S?

This is not straight-forward.
An example is given in studies.cpp

Let's suppose that TSArray contains the T&S:
 
Code
SCTimeAndSalesArray TSArray;
sc.GetTimeAndSales(TSArray);
Let's suppose that TSIndex is the index of the trade we are interested in.

The DateTime TradeDateTime of this trade could be obtained by:
 
Code
SCDateTime TradeDateTime = COMBINE_DATE_TIME(TSArray[TSIndex].Date, HMS_TIME(TSArray[TSIndex].Hour, TSArray[TSIndex].Minute, TSArray[TSIndex].Second));
TradeDateTime += sc.TimeScaleAdjustment;
Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #34 (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

In the next 2 messages, we will give 2 examples of use in real-time of SC's Time & Sales obtained by sc.GetTimeAndSales():
  • emulation of the volume of the bar ...from the trades provided by the T&S
  • emulation of the pullback column ...from the trades provided by the T&S

Nicolas

Visit my NexusFi Trade Journal Reply With Quote
  #35 (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 A: emulation of the volume of the bar by using the real-time information in SC's Time & Sales (obtained by sc.GetTimeAndSales())

The tricky part is to identify the first trade of the bar within the T&S.
I have simply checked the date/time of the T&S trades versus the date/time of the beginning of the bar.
It entails that the emulation is exact for time charts (for instance: 2-min chart), but there could be a discrepancy for other kinds of charts (timestamp effect). This discrepancy could not be greater than 1s.

The code only works in real-time.

Nicolas



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

	// Reference to output:
	SCSubgraphRef EmulatedVolume = sc.Subgraph[0];

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

		// Output:
		EmulatedVolume.Name = "Emulated Volume with GetTimeAndSales";
		EmulatedVolume.DrawStyle = DRAWSTYLE_BAR;
		EmulatedVolume.PrimaryColor = RGB(0, 0, 255); // blue
		EmulatedVolume.LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_VALUES_SCALE | LL_VALUE_ALIGN_CENTER;

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

	SCTimeAndSalesArray TSArray;
	sc.GetTimeAndSales(TSArray);
	if (TSArray.GetArraySize() == 0) return;

	EmulatedVolume[sc.Index] = 0.0f;

	// For each recent trade...
	for ( int TSIndex = TSArray.GetArraySize() - 1 ; TSIndex >= 0 ; TSIndex-- ) { 

		// What is the date-time of the trade? (inspiration: studies.cpp)
		SCDateTime TradeDateTime = COMBINE_DATE_TIME(TSArray[TSIndex].Date, HMS_TIME(TSArray[TSIndex].Hour, TSArray[TSIndex].Minute, TSArray[TSIndex].Second));
		TradeDateTime += sc.TimeScaleAdjustment; 

		// If the trade is prior the start of the current bar, stop the iteration:
		if ( TradeDateTime < sc.BaseDateTimeIn[sc.Index] ) break;

		// Take into account the volume of the trade:
		if ( TSArray[TSIndex].Level == SC_TS_BID || TSArray[TSIndex].Level == SC_TS_ASK ) { // real trade, not an update of bid-ask
			EmulatedVolume[sc.Index] += TSArray[TSIndex].Volume;
		}
	}
}

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #36 (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 B: emulation of the pullback column by using the real-time information in SC's Time & Sales (obtained by sc.GetTimeAndSales())

We are not going to emulate the whole pullback column, but only the total delta of the pullback. The same logic could be used to emulate any part of the pullback column.

As for the previous example, we have to identify the first trade of the bar within the T&S.
I have simply checked the date/time of the T&S trades versus the date/time of the beginning of the bar.
It entails that the emulation is exact for time charts (for instance: 2-min chart), but there could be a discrepancy for other kinds of charts (timestamp effect). This discrepancy could not be greater than 1s.

The code only works in real-time.

Nicolas



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

	// Reference to output:
	SCSubgraphRef EmulatedDeltaFromHigh = sc.Subgraph[0];
	SCSubgraphRef EmulatedDeltaFromLow = sc.Subgraph[1];

	if (sc.SetDefaults) {
		
		sc.GraphName = "Pullback Delta (emulated)";
		sc.StudyDescription = "Pullback Delta (emulated)";

		// Output:
		EmulatedDeltaFromHigh.Name = "Delta from High (emulated)";
		EmulatedDeltaFromHigh.DrawStyle = DRAWSTYLE_DASH;
		EmulatedDeltaFromHigh.PrimaryColor = RGB(255, 0, 0); // red
		EmulatedDeltaFromHigh.LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_VALUES_SCALE | LL_VALUE_ALIGN_CENTER;
		EmulatedDeltaFromLow.Name = "Delta from Low (emulated)";
		EmulatedDeltaFromLow.DrawStyle = DRAWSTYLE_DASH;
		EmulatedDeltaFromLow.PrimaryColor = RGB(0, 0, 255); // blue
		EmulatedDeltaFromLow.LineLabel = LL_DISPLAY_VALUE | LL_VALUE_ALIGN_VALUES_SCALE | LL_VALUE_ALIGN_CENTER;

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

	SCTimeAndSalesArray TSArray;
	sc.GetTimeAndSales(TSArray);
	if (TSArray.GetArraySize() == 0) {
		return; 
	}

	// Let's identify the first trade of the bar:
	int TSIndex = TSArray.GetArraySize()-1;
	while ( TSIndex >= 0 ) {
		// What is the date-time of the trade? (inspiration: studies.cpp)
		SCDateTime TradeDateTime = COMBINE_DATE_TIME(TSArray[TSIndex].Date, HMS_TIME(TSArray[TSIndex].Hour, TSArray[TSIndex].Minute, TSArray[TSIndex].Second));
		TradeDateTime += sc.TimeScaleAdjustment; 
		// If the trade is prior the start of the current bar, stop the iteration:
		if ( TradeDateTime < sc.BaseDateTimeIn[sc.Index] ) {
			TSIndex++;
			break;
		}
		TSIndex--;
	}
	int IndexOfFirstTradeOfTheBar = TSIndex;

	// Let's walk through the T&S from the first trade of the bar to the most recent trade
	// Each time we find a trade after the H/L of the bar (inclusive), let's take it into account for pullback calculations
	bool HighOfBarAlreadyReached = false;
	bool LowOfBarAlreadyReached = false;
	EmulatedDeltaFromHigh[sc.Index] = 0.0f;
	EmulatedDeltaFromLow[sc.Index] = 0.0f;
	for ( int TSIndex = IndexOfFirstTradeOfTheBar; TSIndex < TSArray.GetArraySize(); TSIndex++ ) {
		
		// if the trade is real (not an update of bid/ask) and is at the H or L of the bar...
		// let's change the flags
		if ( TSArray[TSIndex].Level == SC_TS_BID || TSArray[TSIndex].Level == SC_TS_ASK ) {
			if ( (!HighOfBarAlreadyReached) && sc.FormattedEvaluate(TSArray[TSIndex].Price, sc.BaseGraphValueFormat, EQUAL_OPERATOR, sc.High[sc.Index], sc.BaseGraphValueFormat) ) {
				HighOfBarAlreadyReached = true;
			}
			if ( (!LowOfBarAlreadyReached) && sc.FormattedEvaluate(TSArray[TSIndex].Price, sc.BaseGraphValueFormat, EQUAL_OPERATOR, sc.Low[sc.Index], sc.BaseGraphValueFormat) ) {
				LowOfBarAlreadyReached = true;
			}
		}

		// if the trade is real (not an update of bid/ask) AND if we are after the High of the bar (inclusive)...
		// let's take into account its delta for the pullback:
		if ( ( TSArray[TSIndex].Level == SC_TS_BID || TSArray[TSIndex].Level == SC_TS_ASK ) && HighOfBarAlreadyReached ) {
			if ( TSArray[TSIndex].Level == SC_TS_ASK ) {
				EmulatedDeltaFromHigh[sc.Index] += TSArray[TSIndex].Volume;
			} else {
				EmulatedDeltaFromHigh[sc.Index] -= TSArray[TSIndex].Volume;
			}
		}

		// if the trade is real (not an update of bid/ask) AND if we are after the Low of the bar (inclusive)...
		// let's take into account its delta for the pullback:
		if ( ( TSArray[TSIndex].Level == SC_TS_BID || TSArray[TSIndex].Level == SC_TS_ASK ) && LowOfBarAlreadyReached ) {
			if ( TSArray[TSIndex].Level == SC_TS_ASK ) {
				EmulatedDeltaFromLow[sc.Index] += TSArray[TSIndex].Volume;
			} else {
				EmulatedDeltaFromLow[sc.Index] -= TSArray[TSIndex].Volume;
			}
		}
	}
}

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #37 (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, this is more than perfect.

Started this thread Reply With Quote
Thanked by:
  #38 (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

One remark...

sc.GetTimeAndSales() gives access to the T&S, but also to the ever-changing first bid and ask levels of the DOM between actual trades.

I mean...

Of course, sc.GetTimeAndSales() gives access to the content of the T&S window, with all successive actual trades, their size, and their status (bid or ask).

But sc.GetTimeAndSales() also gives access to the changing values of best ask/best bid (1st bid and ask levels of the DOM) between the actual trades.

To have confirmation of it, you can plot built-in study "Times and Sales BidSize" (based on sc.GetTimeAndSales) and a 1-tick chart.
You will see that the value of this study changes even if no trade takes places (no new tick).
You can compare the value of this study with the DOM of your broker (no link with SC).
They are the same.

(So, when you use sc.GetTimeAndSales, it is important to distinguish between (i) actual trades and (ii) actualization of the DOM without trade. I have shown a way to do it in my above codes.)

Nicolas


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #39 (permalink)
mkruss
Wrocław/POLSka
 
Posts: 3 since Jan 2013
Thanks Given: 0
Thanks Received: 0

Hi Nicolas11
I wanted to Time and Sales Time studies. Add Ask Bid/Size Filter input settings. Available is only Volume Filter. Very need this to study spreadsheet.

Reply With Quote
  #40 (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


Hi @mkruss ,

If no mistake, I have released the source code of all my works. Feel free to adapt it to your own needs.

Nicolas

Visit my NexusFi Trade Journal Reply With Quote




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