Price clusters

Posted By: danatrader

Price clusters - 07/17/20 19:14

On TFH it states detecting price clusters is easy.

How would an easy approach work in Lite-C?
Posted By: StefanCGN

Re: Price clusters - 07/31/20 15:28

Had the same question when I read this article....
Posted By: danatrader

Re: Price clusters - 08/01/20 19:25

@JCL would you give some hints please?
Posted By: Grat

Re: Price clusters - 08/02/20 14:22

what u mean "TFH"?
Posted By: AndrewAMD

Re: Price clusters - 08/02/20 18:52

Originally Posted by Grat
what u mean "TFH"?
"The Financial Hacker", I'm assuming.
Posted By: danatrader

Re: Price clusters - 08/03/20 03:53

Yes, the finacial hacker.

https://financial-hacker.com/build-better-strategies-part-2-model-based-systems/

Still, clusters in price curves are real and can be easily identified in a histogram similar to the cycles spectogram.

Question is, can they be easily identified during live session?
Posted By: jcl

Re: Price clusters - 08/03/20 10:04

Yes. Store the last N prices, then distribute them into several bins, each one with a fixed price range. The cluster is then the bin with the most prices.
Posted By: danatrader

Re: Price clusters - 08/17/20 19:47

Could anybody give a hint how to approach that (Lite-C only)?

I mean the buckets and counting?

I assume NumInRange(... is the easiest?
Posted By: danatrader

Re: Price clusters - 08/19/20 11:33

@JCL how much work would it be to have a sample code for that online in the manual?

My approach so far

vars Lows = series(priceLow());
vars Highs = series(priceHigh());
vars Maxs = series(priceHigh());
vars Mins = series(priceLow());



vars cls = series(NumInRange(Lows, Highs, Mins[0], Maxs[0], 24*7));
Posted By: ozgur

Re: Price clusters - 08/20/20 05:52

I am not sure NumInRange itself is suitable since it counts bars without considering their range.

Instead decide a bin width, let's say 10 pips. Make a loop and count bins by checking low and high of each bar. Now you have a histogram. Then you can check peaks, valleys or low count bins next to high count bins for SR zones. You need to quantify "low count" and "high count" for computer as well.
Posted By: danatrader

Re: Price clusters - 08/20/20 09:42

Would you be so kind to give some example for "Make a loop and count bins by checking low and high of each bar"?

That would be really great and I am sure others may benefit a lot from it too.
Posted By: ozgur

Re: Price clusters - 08/20/20 10:27

Sure.

Code
void run()
{
        int arrayHiLoLen = 1000;
        LookBack = 1000;

	var PIP10 = PIP * 10;
	
	var high = ceil(priceHigh(0) / PIP10) * PIP10;
	var low = ceil(priceLow(0) / PIP10) * PIP10;
	
	vars highs = series(high);
	vars lows = series(low);
	
	//
	if(!is(LOOKBACK)) {
		var highest = MaxVal(highs, arrayHiLoLen);
		var lowest = MinVal(lows, arrayHiLoLen);
		
		int arrLen = ((highest - lowest) / PIP10) + 1;
		
		int *binCount = zalloc(arrLen * sizeof(int));
		
		
		//
		int i;
		for (i = 0; i < arrayHiLoLen; i++) {
			int enIdx = (highs[i] - lowest) / PIP10;
			int stIdx = (lows[i] - lowest) / PIP10;
			
			int j;
			for (j = stIdx; j <= enIdx; j++) {
				binCount[j]++;
			}
		}
	

	        if(is(EXITRUN)) {
		    printf("\n");
		
		    int i;
		    for (i = 0; i < arrLen; i++) {
		        printf("%i ", binCount[i]);
		    }
		
		    printf("\n %f %f %i %f \n\n", lowest, highest, arrLen, PIP10);
	        }
        }
}


x-axis starts from "lowest" and increments in 10 pips to "highest". Bins are in binCount array e.g lowest count is in binCount[0], Highest in binCount[arrLen - 1]
Posted By: danatrader

Re: Price clusters - 08/20/20 10:36

AWESOME, I will check it tonight, thank you so much.
© 2024 lite-C Forums