Dynamic zons by zamansky and

#1
Hi friends
here is a metastock code which I was trying to convert into Amibroker formula.
Almost there but seems slightly on wrongside.
can the experts correct it please
best regards
ford

HTML:
//http://systems4trading.com/formula,487,metastock,dynamic-zones.html
/*
Zamansky & Stendahl's Dynamic Zones for MS6.5 (From the TASC July 1997 article). 
First, for the Lookback Periods plot a 9-day RSI along with StDev adjusted rolling 70-day SMAs; e.g., as can be seen in the article's S&P 500-example. Most indicators use a fixed zone for buy and sell signals.
Here's a concept based on zones that are responsive to past levelsof theindicator.
One approach to active investing employs the use of oscillatorsto exploittradable market trends.
This investing style follows a very simple form of logic: Enter themarket only when an oscillator 
has moved far above or below traditional tradinglevels.
However, these oscillator-driven systems lack the ability to evolvewith the market becausethey use 
fixed buy and sell zones. Traders typically use one set ofbuy andsell zones for a bull marketand 
substantially different zones for a bear market. And therein liestheproblem.

Once traders begin introducing their market opinions into trading equations,by changing the zones, 
they negate the system's mechanical nature. The objective is to havea systemautomatically defineits 
own buy and sell zones and thereby profitably trade in any market-- bullor bear.

Dynamic zones offer a solution to the problem of fixed buy and sellzones for any oscillator-driven system.

The algorithm for the dynamic zones is a series of steps. First, decidethe value of the lookback period t.
Next, decide the value of the probability Pbuy for buy zone and valueof the probability Psell for the sell zone.

The area above and below the dynamic zones constitute the upper andlower10% boundaries.
The zones appear to evolve with the market because they use a rolling70-day period of indicator
 values in their construction.
 



Dynamic Zones 
PR:=Input("Enter Periods for RSI",1,100,9);
PB:=Input("Enter Periods for BUY",1,100,70);
PS:=Input("Enter Periods for SELL",1,100,70);
UpZone:=Mov(RSI(PR),PS,S)+(1.3185 *StDev(RSI(PR),PS));
LwZone:=Mov(RSI(PR),PB,S)-(1.3185 *StDev(RSI(PR),PB));
UpZone;
LwZone;
*/
PR = 9;
PB = 70;
PS = 70;
UPZONE = MA(RSI(PR),70) + (1.3185*StDev(RSI(PR),70));
DNZONE = MA(RSI(PR),70) - (1.3185*StDev(RSI(PR),70));

Plot(RSI(9),"rsi-9",colorBlue,styleThick);
Plot(UPZONE,"UPZONE",colorRed,styleThick);
Plot(DNZONE,"DNZONE",colorBlack,styleThick);
 

extremist

Well-Known Member
#3
i just thoink u want this :

_SECTION_BEGIN("Unnamed 3");
PR = Param("RSI prd ",9,1,500,1);

PB = Param("Buy cut off ",30,0,100,1);

PS = Param("sell cut off ",70,0,100,1);

UPZONE = MA(RSI(PR),PS) + (1.3185*StDev(RSI(PR),PS));
DNZONE = MA(RSI(PR),PB) - (1.3185*StDev(RSI(PR),PB));

Plot(RSI(PR),"\nRSI :",colorBlue,styleThick);
Plot(UPZONE,"\nUPZONE :",colorRed,styleThick);
Plot(DNZONE,"\nDNZONE :",colorBlack,styleThick);

/************************************/

just changed buy ct off to 30 frm 70.

 
#4
hi extremist

I think you got my confusion point rightly.
I was not feeling the settiing should be same for buy cut off and sell cut off.
A minor change did it.

here is dynamic zones mq4 code-given by a friend- looks different. wonder which is better! this uses RSI 14 & Band period 20
regards

HTML:
//+------------------------------------------------------------------+
//|                                             Dynamic Zone RSI.mq4 |

//+------------------------------------------------------------------+

#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 SlateBlue
#property indicator_color3 Orange

#property indicator_separate_window

extern int RSIPeriod = 14;
extern int BandPeriod = 20;

double RSIBuf[],UpZone[],DnZone[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(0,RSIBuf);
   SetIndexBuffer(1,UpZone);
   SetIndexBuffer(2,DnZone);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double MA, RSI[];
   ArrayResize(RSI,BandPeriod);
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   for(int i=limit; i>=0; i--)
   {
      RSIBuf[i] = iRSI(NULL,0,RSIPeriod,PRICE_WEIGHTED,i);
      MA = 0;
      for(int j=i; j<i+BandPeriod; j++) {
         RSI[j-i] = RSIBuf[j];
         MA += RSIBuf[j]/BandPeriod;
      }
      UpZone[i] = MA + (1.3185 * StDev(RSI,BandPeriod));
      DnZone[i] = MA - (1.3185 * StDev(RSI,BandPeriod));  
   }
   
//----
   return(0);
  }
  
double StDev(double& Data[], int Per)
{
  return(MathSqrt(Variance(Data,Per)));
}

double Variance(double& Data[], int Per)
{
  double sum, ssum;
  for (int i=0; i<Per; i++)
  {
    sum += Data[i];
    ssum += MathPow(Data[i],2);
  }
  return((ssum*Per - sum*sum)/(Per*(Per-1)));
}
//+--------------------------------------------
 

KelvinHand

Well-Known Member
#6
Why the problem is
why the author of original code used 70 as cut off for both buy and sell is not looking so digestible.
thanks for asking
regards
Very simple. The author may not wrong.
You understand bollingerband then you should know that
The author using 70 to smooth the rsi to create a more flatten equivalence Upperband and Lowerband for Dynamic (Res and Supp) Zone.

But your mind is fixed to 30 and 70 rsi level, then how to dynamic.
You change to 30 and 70 outerband, there is possibility of less accurracy.

Put the different setting side by side or superimpose to do a proper study
 
Last edited:

KelvinHand

Well-Known Member
#7
hi extremist


wonder which is better! this uses RSI 14 & Band period 20
regards
When the rsi go lower, the tendency of hitting 30 and 70 is more often then rsi 14 and above.

rsi 14 had a higher probability of support at 40 and resistance at 60.
Once it cross beyond these two lines, possibility of no men land, fast and furious move in some case.
 

extremist

Well-Known Member
#8
even with mt4 code u will get the same chart.
if u want to get same chart in Ami then plz change the value of PR to 14 and
PB & PS to 20.

it is simply bollinger bands applied to RSI.


And on choice 70 of auther.

it might be suiting his trading style.
if u want to get better i suggest u to use following parameters

PR=9
PB=35
ps=65

reason for thse 35 & 65 levels is tht rsi take support and resistance at these levels most of the time.

but we can find our most conveniant values.
 
#9
Hi experts

Thanks for the hints.
I understood that to get a stable sup-res bands, it is better to have 70 period smoothing & a bit higher time frame like 30min or 60min or 240min or daily.

The lower the RSI periods and the lower the smoothing periods we tend to stay away from reliable support and resz.

regards and once again thanks to kelvin for unfolding the concept.
ford
 

Similar threads