Can't get Double Stochastic to work in Multi Time frame (RANGE BARS)

Hi. The following code DOES work using MINUTE bars, but doesn’t come up with the right values using RANGE bars. I am not sure what I am doing incorrectly - can someone please have a look and advise. ?

Thanks

_SECTION_BEGIN("MJF_DS");

{  	// parameters  Param( ''name'', defaultval, min, max, step, sincr = 0 )
	// grab the interval from the screen
	 if( Interval() == 86400 ) {
		STFTypeDefault = 1;
		STFInputValDefault = 1;
	 } else {
		STFTypeDefault = 0;
		STFInputValDefault = Interval() / 60;
	 }


	DSperiods 		= Param( "DSPeriods", 10, 2, 200, 1 );							// Double Stochastic periods
	DSKSmoothing 	= Param( "K Smoothing", 3, 2, 20, 1 );							// Double Stochastic K Smoothing
	DSDSmoothing 	= Param( "D Smoothing", 3, 2, 20, 1 );							// Double Stochastic D Smoothing
	DSOb 			= Param( "DS OverBought", 85, 2, 100, 1 );						// Double Stochastic OverBought line
	DSOs 			= Param( "DS OverSold", 15, 2, 100, 1 );						// Double Stochastic OverSold line
	STFType 		= ParamList("Short TF Type", "MIN|DAILY|WEEKLY|RANGE", STFTypeDefault ); 
	STFInputVal		= Param("ShortTF Value",STFInputValDefault,1,60,1);
}

	{ 	// Setup the Short Time Frame 
		{	// parse the input parameters
			switch(STFType)					
			{
				case("MIN"):
					STFMode=0;
					STF=in1Minute*STFInputVal;
					break;
				case("DAILY"):
					STFMode=0;
					STF=inDaily;
					break;
				case("WEEKLY"):
					STFMode=0;
					STF=inWeekly;
					break;
				case("RANGE"):
					STFMode=4;
					STF=STFInputVal;
					break;
			}
		}

		{	// Set the short time frame and calculate the indicators
		
			TimeFrameMode( STFMode ); 
			TimeFrameSet( STF ); 
			
			div = HHV(H, DSperiods)-LLV(L, DSperiods);
			// replace zero values with 0.0001
			div = IIf( div == 0, 0.0001, div ); 

			FSK = 100*(C-LLV(L, DSperiods))/(div); 												// FASTSTOCHK
			FLSK = EMA( FSK, DSKSmoothing ); 															// FULLSTOCHK

			div = HHV(FLSK, DSperiods)-LLV(FLSK, DSperiods);	
			// replace zero values with 0.0001
			div = IIf( div == 0, 0.0001, div ); 

			DSK = ((FLSK-LLV(FLSK, DSperiods))/(div)) * 100;
			KArray = EMA( DSK, DSDSmoothing ); 	
			DArray = MA( KArray, 3); 
			
		}
		TimeFrameRestore(); 									// restore time frame to original for plotting
	}
	
	tempk = TimeFrameExpand(KArray, STF, mode=expandFirst);
	tempd = TimeFrameExpand(DArray, STF, mode=expandFirst);

Plot( tempk, "DSK", ParamColor( "ColorK", colorRed ),styleLine);
Plot( tempd, "DSD", ParamColor( "ColorD", colorBlue ), StyleLine);
Plot(DSOb,"Overbought Level",colorGrey40, styleNoTitle |styleDashed );
Plot(DSOs,"Oversold Level",colorGrey40, styleNoTitle |styleDashed );
_SECTION_END();

http://www.amibroker.com/guide/h_timeframe.html

You can’t mix time-based bars with non-time-based bars (range bars are NOT based on time).

Hi Tomasz. I am not mixing them.

I run this code on say 15 min bars and it works ok.

When I switch to a RANGE bar 30, it doesn't come up with the right values.

What I am comparing against is:

  1. Running the same code, but without the time frame expansion
    compared against
  2. doing the time frame expansion code

here is the code without the timeframe stuff

_SECTION_BEGIN("MJF_DS");

{  	// parameters  Param( ''name'', defaultval, min, max, step, sincr = 0 )
DSperiods 		= Param( "DSPeriods", 10, 2, 200, 1 );							// Double Stochastic periods
DSKSmoothing 	= Param( "K Smoothing", 3, 2, 20, 1 );							// Double Stochastic K Smoothing
DSDSmoothing 	= Param( "D Smoothing", 3, 2, 20, 1 );							// Double Stochastic D Smoothing
DSOb 			= Param( "DS OverBought", 85, 2, 100, 1 );						// Double Stochastic OverBought line
DSOs 			= Param( "DS OverSold", 15, 2, 100, 1 );						// Double Stochastic OverSold line
}

KArray = Close; 	

			div = HHV(H, DSperiods)-LLV(L, DSperiods);
			// replace zero values with 0.0001
			div = IIf( div == 0, 0.0001, div ); 

			FSK = 100*(C-LLV(L, DSperiods))/(div); 												// FASTSTOCHK
			FLSK = EMA( FSK, DSKSmoothing ); 															// FULLSTOCHK

			div = HHV(FLSK, DSperiods)-LLV(FLSK, DSperiods);	
			// replace zero values with 0.0001
			div = IIf( div == 0, 0.0001, div ); 

			DSK = ((FLSK-LLV(FLSK, DSperiods))/(div)) * 100;
			KArray = EMA( DSK, DSDSmoothing ); 	
			DArray = MA( KArray, 3); 
			

Plot( KArray, "DSK", ParamColor( "ColorK", colorRed ),styleLine);
Plot( DArray, "DSD", ParamColor( "ColorD", colorBlue ), StyleLine);
Plot(DSOb,"Overbought Level",colorGrey40, styleNoTitle |styleDashed );
Plot(DSOs,"Oversold Level",colorGrey40, styleNoTitle |styleDashed );
_SECTION_END();

And the above code in the first post is the Time frame code.

Here is what the out put looks like: The top indicator is the NON time frame one, the bottom is using the same time frame as the price is at.

The 2 indicators SHOULD look identical, or very close.... (If I do the same thing with CCI, they are identical charts).

image

No idea what I am doing wrong.

Just a supplemental observation to my post…

How do you set RANGE BAR 30? Is it …

TimeFrameMode( 4 );
TimeFrameSet( 30 );

Because this gives me the picture above in my second post.

if I use:

TimeFrameMode( 4 );
TimeFrameSet( 1 );

Then I get a matching indicator - but I have no idea if this is correct…

On a further note:
My database is setup for 1 minute resolution, NOT TICK… I have since changed it to TICK. Would this give me the results that I am seeing?

You are mixing them. Re-read and re-think what I wrote. As I wrote you can mix time based bars with range bars.

These two are different. Range bars don't use time. You can't mix them with time. You can't apply time compression to range-compressed bars and vice versa. You can only compress TICK->RANGE, TICK->VOLUME and TICK->any time-based bar and any x-UNIT time based -> N* x-UNIT time-based bars. This is explained in manual http://www.amibroker.com/guide/h_timeframe.html

image

Where input is the data interval your formula is fed with. It is what you selected in "Interval" combo for chart or "Periodicity" setting in the Analysis.

Hi Tomasz, first thanks for your post, but I am just not getting what I am doing wrong.

Lets look at this code - I have stripped out all the unnecessary stuff and I am using the standard StochK/D indicators. I was expecting that this would generate the same chart.

  1. This is a standard RANGE bar 30 chart.
  2. I added the standard Stochastic K/D (15,3,3) as a comparison indicator.
  3. I then used this code to plot the same indicator in Multi Time Frame - using RANGE 30 and expected to get the same chart. I did NOT and I don't know why.
_SECTION_BEGIN("MJF-DS-MTF");

STFMode=4;						// this sets it to RANGE BARS
STF=30;							// Tomasz, what value am I supposed to use if I want a RANGE bar of 30?

TimeFrameMode( STFMode ); 
TimeFrameSet( STF ); 

KArray = StochK( periods = 15, ksmooth=3 ) ;			
DArray = StochD( periods = 15, Ksmooth=3, Dsmooth=3 ) ;			
			
TimeFrameRestore(); 						// restore time frame to original for plotting
	
tempk = TimeFrameExpand(KArray, STF, mode=expandFirst);				// this is set to 30 here too
tempd = TimeFrameExpand(DArray, STF, mode=expandFirst);				// this is set to 30 here too

Plot( tempk, "DSK", ParamColor( "ColorK", colorRed ),styleLine);
Plot( tempd, "DSD", ParamColor( "ColorD", colorBlue ), StyleLine);
Plot(85,"Overbought Level",colorGrey40, styleNoTitle |styleDashed );
Plot(15,"Oversold Level",colorGrey40, styleNoTitle |styleDashed );
_SECTION_END();

image

@DaFish
Hi and Sorry. If I go in the middle of this conversation but in this foto that you send, You have TYPE 30R into Interval combo right?
So you compress you AFL twice?
One time in the Interval combo, and ONE MORE time inside the AFL? Why?
Do you think that makes sense?

Hi. I am using the examples from the manual for how to use Multi Time frame.

NOTE: This works EXACTLY as it should if I use TIME BASED charts. Please see this screen shot. I get exactly the same chart.

I do NOT know what I am doing incorrectly with RANGE bar charts. I think only Tomasz can guide me on this one.

Here is the code change I made

_SECTION_BEGIN("MJF-DS-MTF");

//STFMode=4;						// this sets it to RANGE BARS
//STF=30;							// Tomasz, what value am I supposed to use if I want a RANGE bar of 30?

STFMode=0;
STF=in1Minute*15;

TimeFrameMode( STFMode ); 
TimeFrameSet( STF ); 

KArray = StochK( periods = 15, ksmooth=3 ) ;			
DArray = StochD( periods = 15, Ksmooth=3, Dsmooth=3 ) ;			
			
TimeFrameRestore(); 						// restore time frame to original for plotting
	
tempk = TimeFrameExpand(KArray, STF, mode=expandFirst);				// this is set to 30 here too
tempd = TimeFrameExpand(DArray, STF, mode=expandFirst);				// this is set to 30 here too

Plot( tempk, "DSK", ParamColor( "ColorK", colorRed ),styleLine);
Plot( tempd, "DSD", ParamColor( "ColorD", colorBlue ), StyleLine);
Plot(85,"Overbought Level",colorGrey40, styleNoTitle |styleDashed );
Plot(15,"Oversold Level",colorGrey40, styleNoTitle |styleDashed );
_SECTION_END();

image

@Tomasz already explained you twice that you can not mix time-based bars with range bars. Did you look at the table from last @Tomasz 's post ? It clearly says “No” when you pick minute bar input and N-range output.

Kuba, thanks for your post, and I read, and re-read the manual, and Tomasz’s posts…

I have no idea how I am using time based bars. You are saying, Tomasz is saying it… but what I actually need help on is:

  1. HOW do I change this to RANGE bars on the Visual chart ? I thought I was using RANGE 30 (and the chart does show what looks to me as a range bar chart…

  2. How do I change my attached AFL to use RANGE bars? (the manual doesn’t explain this too well, or at all…)

STFMode=4;						// this sets it to RANGE BARS
STF=30;							// Tomasz, what value am I supposed to use if I want a RANGE bar of 30?

TimeFrameMode( STFMode ); 
TimeFrameSet( STF ); 
  1. I set the database to TICK, I am assuming this is all I need to do there.

Please don’t tell me to read the manual again, please tell me what I need to change.

Thanks

Mark

Hi @DaFish

My English vocabulary is limited to nothing, but I am happy as I learn Latin :smiley:

In this post here i will try to go In plain English and few steps

  1. Open two MDI – Please read about MDI (multiple document interface) tabs
  2. In left tab, insert the normal indicator. In Interval combo type 30R
  3. In Right tab, insert the AFL file that is compressed in Range Bars. In Interval combo type 1t (that is One tick)
  4. Job done, if your afl code has the same range period as LEFT chart MDI

I just wake up I need a coffee, I hope I wrote al above steps correct

1 Like