You are on page 1of 2

_SECTION_BEGIN("Ocean Theory");

//Natural Moving Average of Ocean Theory by Jim Sloman


//Basic value set to 75 as there are 75 5 minute candles in NSE Equities
NMA_period
Show_SD
NMA_SD_len
NMA_SD_up
NMA_SD_dn

= Param("NMA Period",75,40,375);
=ParamToggle("Show SD Bands","Yes|No",0);
= round(NMA_period*30/40);
= 2;
= 2;

FastNMA_period
= NMA_Period;
FastNMA_LB_min
= round(NMA_Period*8/40);
FastNMA_SD_len
= round(NMA_Period*20/40);
FastNMA_SD_up
= 1.5;
FastNMA_SD_dn
= 1.5;
NMA[NMA_period]=Close[NMA_Period];
FastNMA[FastNMA_period]=Close[FastNMA_period];
ratio = 0;
NSum = (ln(Close) - ln(Ref(Close,-1))) + (ln(Ref(Close,-1)) - ln(Ref(Close,2))) * (sqrt(2)-1);
for(i = 2; i< NMA_period; i++)
NSum =NSum+ (ln(Ref(Close,-i)) - ln(Ref(Close,-i-1))) * (sqrt(i+1) - sqrt(i)
);
abssum = abs(NSum);
NSum = 0;
for(i = 0; i < NMA_period; i++)
NSum =Nsum+ abs(ln(Ref(Close,-i)) - ln(Ref(Close,-i-1)));
ratio = abssum / NSum;

for (i=NMA_period+1;i<BarCount;i++)
NMA[i]=NMA[i-1]+(Close[i]-NMA[i-1])*ratio[i];
NMA_SDup = NMA + NMA_SD_up * StDev(Close,NMA_SD_len);
NMA_SDdn= NMA - NMA_SD_dn * StDev(Close, NMA_SD_len);
Plot(NMA, "NMA Reg",ParamColor("NMA Reg Color",Colorcycle),styleLine) ;
maxnmm = 0;
ratio = 0;
for(i = 1; i < FastNMA_period+1; i++)
{
nmmnum = (ln(Close)- ln(Ref(Close,-i))) / sqrt(i);
if(abs(nmmnum[i]) > maxnmm[i])
{ maxnmm = abs(nmmnum);
NMA_LB_max = i; }
}
if(NMA_LB_max < FastNMA_LB_min) NMA_LB_max = FastNMA_LB_min;
NSum = (ln(Close) - ln(Ref(Close,-i))) + (ln(Ref(Close,-i)) - ln(Ref(Close,2))) * (sqrt(2)-1);
for(i = 2; i < NMA_LB_max; i++)
NSum =NSum+ (ln(Ref(Close,-i)) - ln(Ref(Close,-i-1))) * (sqrt(i+1) - sqrt(i)
);
abssum = abs(NSum);

NSum = 0;
for(i = 0; i< NMA_LB_max; i++)
NSum =NSUM+ abs(ln(Ref(Close,-i)) - ln(Ref(Close,-i-1)));
ratio = abssum / NSum;
for (i=FASTNMA_period+1;i<BarCount;i++)
FastNMA[i] = FastNMA[i-1] + (Close[i] - FastNMA[i-1]) * ratio[i];
FastNMA_SDup = FastNMA + FastNMA_SD_up * StDev(Close,FastNMA_SD_len);
FastNMA_SDdn= FastNMA - FastNMA_SD_dn * StDev(Close, FastNMA_SD_len);
Plot(FastNMA, "Fast NMA",ParamColor("NMA fast Color",Colorcycle),styleLine) ;
if (Show_SD==0)
{
Plot(NMA_SDUp, "",ParamColor("NMA Reg Color",Colorcycle),styleDashed) ;
Plot(NMA_SDDn, "",ParamColor("NMA Reg Color",Colorcycle),styleDashed) ;
Plot(FastNMA_SDUp, "NMA Reg",ParamColor("NMA fast Color",Colorcycle),styleDashed
) ;
Plot(FastNMA_SDDn, "NMA Reg",ParamColor("NMA fast Color",Colorcycle),styleDashed
) ;
}
_SECTION_END();

You might also like