[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Code for Stochastic Classic D% in multi-bars ...



PureBytes Links

Trading Reference Links

Hi,

Here is some Easy Lanquage code that can calculate %D as on 5 minute
bars by using 1 minute bars. Idea is to get values for the indicator
as if you are working with 5 minute bars, but with opportunity to
make entry before normal 5 minute bar would be closed (like in
discretionary trading). As well, one can see the history of the values
that indicator had inside 5 minute bar.

Best regards,
Dejan


{ iStchsticClsicMB.v1.00.b									    }

{ Description :	This indicator is similar to normal Stochastic Classic %D.
Only difference is that  }
{               the indicator is calculated by using multi-bars. Multi-bars
are created from a	    }
{               choosen number of single-bars. Intention is to somewhat
experiment with making      }
{		entries on unfinished multi-bar, like in discretionary trading. As well,
this       }
{               concept gives the intermediate values for indicator from the
opening to the closing }
{ 		of the multi bar. And, it enables overlaping of several 'wavelengths' of
the indi-  }
{		cator, by using only one set of single-bars. 																				}

{		Single-bars are usually one minute bars, while multi-bars can, for
example, be five }
{		minute bars.																																				}

{ Warning:      Missing bars, that are quite often in single bar sets create
discrepance between    }
{               this indicator and one on the real multi-bars, because
multi-bars engulf these gaps.}
{               Because virtual multi-bars are stored in arrays, using these
functions can be       }
{		increasingly computationaly heavy when large calculation lengths are
used. Thus,    }
{		these version of indicator is good for system searching, but it might be
very comp- }
{		utationaly demanding on real-time data feeds with tens of ticks per
seconnd.	    }

{ v1.00    .a - Initial version.								    }
{          .b - Version working both on time and tick bars.					    }

{ Input variables :																																									}

{ Length      - Number of multi-bars for calculating average in the
stochastics.		    }
{ KDAdjust    - Number of multi-bars for wave grabbing in the
s.		    	    }
{	ti    - Nuber of one single bars used to create each
		    	    }

Inputs: Length(5), KDAdjust(3), ti(5);

Variables: tOpening(0), BarsSinceOpen(0), MntsSncLstWhlBar(0);
Variables: i(0), j(0), UncmpltBarsBack(0), CmpltBarVolume(0),
UncmpltBarVolume(0);

Variables: mbOpen(0), mbHigh(0), mbLow(0), mbClose(0), mbVol(0), mbVolUp(0),
mbVolDn(0);

Variables: LowestLow(10000000), HighestHigh(0);
Variables: StochasticKClassic(0), StochasticDClassic(0);
Variables: SlowKClassic_(0), SlowDClassic_(0), FastDClassic_(0), FastK_(0);

Variables: dBugON(False), dBugDate(1010910), dBugTStart(1635),
dBugTEnd(1640), dBugPerformance(False);

{	0. INITIALISATION
____________________________________________________________________________
___ }

{ 0.1. - Calculation the position of the one-minute-bar in the current
multi-bar.										}

MntsSncLstWhlBar = Mod(BarNumber, ti);

If MntsSncLstWhlBar = 0 Then
	UncmpltBarsBack = ti
Else
	UncmpltBarsBack = MntsSncLstWhlBar;

{	0.2. - Calculation of the OHLC for the current
											}

mbOpen = Open[UncmpltBarsBack - 1];
mbHigh = Highest(High, UncmpltBarsBack);
mbLow = Lowest(Low, UncmpltBarsBack);
mbClose = Close[0];

For i = 0 To (UncmpltBarsBack - 1)
	Begin
		mbVol = Sign(i) * mbVol + Volume[i];
		mbVolUp = Sign(i) * mbVolUp + UpTicks[i]; mbVolDn = Sign(i) * mbVolDn +
DownTicks[i];
	End;

{	1. ANALYSIS
____________________________________________________________________________
_________	}

{ 1.0. - Calculation of the price extremes using [KDAdjust] number of
multi-bars back. Only 			}
{        multibars are considered, and 1n-bars are
									}

LowestLow = mbLow; HighestHigh = mbHigh;
For i = 0 To (KDAdjust - 1)
	Begin

		If i = 0 Then j = 0 Else j = ti * (i - 1) + UncmpltBarsBack;

	  If mbLow[j] < LowestLow  Then
			LowestLow = mbLow[j];
		If HighestHigh < mbHigh[j] Then
			HighestHigh = mbHigh[j];


{	1.1. - Calculation of the stochastic components: FastK, as used by the
both K% and D%.						 }

If (HighestHigh - LowestLow) = 0 Then
	FastK_ = 0
Else
	FastK_ = (Close - LowestLow) / (HighestHigh - LowestLow) * 100;

SlowKClassic_ = 0;
For i = 0 To (Length - 1)
	Begin
		If i = 0 Then
			SlowKClassic_ = FastK_
		Else
		  SlowKClassic_ = SlowKClassic_ + FastK_[ti * (i - 1) + UncmpltBarsBack];
	End;
SlowKClassic_ = SlowKClassic_ / Length;

{ 1.2. - Calculation of the FastDClassic and
														}

FastDClassic_ = (FastK_ + FastK_[ti + UncmpltBarsBack] + FastK_[2 * ti +
UncmpltBarsBack]) / 3;

SlowDClassic_ = 0;
For i = 0 To (Length - 1)
	Begin
		If i = 0 Then
			SlowDClassic_ = FastDClassic_
		Else
		  SlowDClassic_ = SlowDClassic_ + FastDClassic_[ti * (i - 1) +
UncmpltBarsBack];
	End;
SlowDClassic_ = SlowDClassic_ / Length;

{	1.3. - Plot the graphs to the screen.																															}

Plot1(SlowKClassic_, "%K mb");
Plot2(SlowDClassic_, "%D mb");
If 0 < (SlowKClassic_-SlowDClassic_) Then
	Plot3((SlowKClassic_-SlowDClassic_), "%K-%D", Blue)
Else
	Plot3((SlowKClassic_-SlowDClassic_), "%K-%D", Red);



Attachment: Description: "iStchsticClsicMB v100b.els"