//+------------------------------------------------------------------+
//| dynamic zone smoothed rsi |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "[email protected]"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 LimeGreen
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_minimum 0
#property indicator_maximum 100
//
//
//
//
//
extern int RsiLength = 9;
extern int RsiPrice = PRICE_CLOSE;
extern int DzLookBackBars = 70;
extern double DzStartBuyProbability = 0.10;
extern double DzStartSellProbability = 0.10;
//
//
//
//
//
double rsi[];
double bli[];
double sli[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
SetIndexBuffer(0,rsi);
SetIndexBuffer(1,bli);
SetIndexBuffer(2,sli);
//
//
//
//
//
string PriceType;
switch(RsiPrice)
{
case PRICE_CLOSE: PriceType = "Close"; break; // 0
case PRICE_OPEN: PriceType = "Open"; break; // 1
case PRICE_HIGH: PriceType = "High"; break; // 2
case PRICE_LOW: PriceType = "Low"; break; // 3
case PRICE_MEDIAN: PriceType = "Median"; break; // 4
case PRICE_TYPICAL: PriceType = "Typical"; break; // 5
case PRICE_WEIGHTED: PriceType = "Weighted"; break; // 6
}
//
//
//
//
//
RsiLength = MathMax(RsiLength ,1);
IndicatorShortName ("Dynamic zone RSI ("+RsiLength+","+PriceType+","+DzLookBackBars+","+DoubleToStr(DzStartBuyProbability,3)+","+DoubleToStr(DzStartSellProbability,3)+")");
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMin(Bars-counted_bars,Bars-1);
//
//
//
//
//
//
for(i=limit; i >= 0; i--)
{
rsi[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
bli[i] = dzBuy (i, rsi, DzStartBuyProbability, DzLookBackBars);
sli[i] = dzSell(i, rsi, DzStartSellProbability, DzLookBackBars);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double dzBuy(int i, double& array[], double initValue, int lookBackBars)
{
double left = -10000;
double right = 10000;
if ((Bars-i)<lookBackBars) return(EMPTY_VALUE);
//
//
//
//
//
double eps = 0.001;
double yval = (left+right)/2.0;
double delta = yval-left;
int maxSteps = 0;
while (delta>0.005 && maxSteps<50)
{
maxSteps++;
double count = 0;
for (int k=0; k<lookBackBars;k++) if (array[i+k]<yval) count++;
double prob = count/lookBackBars;
if (prob>(initValue+eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
delta=yval-left;
}
return(yval);
}
//
//
//
//
//
double dzSell(int i, double& array[], double initValue, int lookBackBars)
{
double left = -10000;
double right = 10000;
if ((Bars-i)<lookBackBars) return(EMPTY_VALUE);
//
//
//
//
//
double eps = 0.001;
double yval = (left+right)/2.0;
double delta = yval-left;
int maxSteps = 0;
while (delta>0.005 && maxSteps<50)
{
maxSteps++;
double count = 0;
for (int k=0; k<lookBackBars;k++) if (array[i+k]>yval) count++;
double prob = count/lookBackBars;
if (prob>(initValue+eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
delta=yval-left;
}
return(yval);
}
function dzBuy(arrey,initValue,lookBackBars)
{
left = -10000;
right = 10000;
eps = 0.001;
yval = (left+right)/2.0;
delta = yval-left;
maxSteps = 0;
while (delta>0.005 AND maxSteps<50)
{
maxSteps++;
count = 0;
for (k=0; k<lookBackBars ;k++)
if (arrey[k]<yval)
count++;
prob = count/lookBackBars;
if (prob>(initValue+eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
delta=yval-left;
}
return(yval);
}
Plot( dzBuy(RSI(),0.1,70),"",colorGreen,styleLine);
//+------------------------------------------------------------------+
//| dynamic zone smoothed rsi |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "[email protected]"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 LimeGreen
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_minimum 0
#property indicator_maximum 100
//
//
//
//
//
extern int RsiLength = 9;
extern int RsiPrice = PRICE_CLOSE;
extern int DzLookBackBars = 70;
extern double DzStartBuyProbability = 0.10;
extern double DzStartSellProbability = 0.10;
//
//
//
//
//
double rsi[];
double bli[];
double sli[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
SetIndexBuffer(0,rsi);
SetIndexBuffer(1,bli);
SetIndexBuffer(2,sli);
//
//
//
//
//
string PriceType;
switch(RsiPrice)
{
case PRICE_CLOSE: PriceType = "Close"; break; // 0
case PRICE_OPEN: PriceType = "Open"; break; // 1
case PRICE_HIGH: PriceType = "High"; break; // 2
case PRICE_LOW: PriceType = "Low"; break; // 3
case PRICE_MEDIAN: PriceType = "Median"; break; // 4
case PRICE_TYPICAL: PriceType = "Typical"; break; // 5
case PRICE_WEIGHTED: PriceType = "Weighted"; break; // 6
}
//
//
//
//
//
RsiLength = MathMax(RsiLength ,1);
IndicatorShortName ("Dynamic zone RSI ("+RsiLength+","+PriceType+","+DzLookBackBars+","+DoubleToStr(DzStartBuyProbability,3)+","+DoubleToStr(DzStartSellProbability,3)+")");
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMin(Bars-counted_bars,Bars-1);
//
//
//
//
//
//
for(i=limit; i >= 0; i--)
{
rsi[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
bli[i] = dzBuy (i, rsi, DzStartBuyProbability, DzLookBackBars);
sli[i] = dzSell(i, rsi, DzStartSellProbability, DzLookBackBars);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double dzBuy(int i, double& array[], double initValue, int lookBackBars)
{
double left = -10000;
double right = 10000;
if ((Bars-i)<lookBackBars) return(EMPTY_VALUE);
//
//
//
//
//
double eps = 0.001;
double yval = (left+right)/2.0;
double delta = yval-left;
int maxSteps = 0;
while (delta>0.005 && maxSteps<50)
{
maxSteps++;
double count = 0;
for (int k=0; k<lookBackBars;k++) if (array[i+k]<yval) count++;
double prob = count/lookBackBars;
if (prob>(initValue+eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
delta=yval-left;
}
return(yval);
}
//
//
//
//
//
double dzSell(int i, double& array[], double initValue, int lookBackBars)
{
double left = -10000;
double right = 10000;
if ((Bars-i)<lookBackBars) return(EMPTY_VALUE);
//
//
//
//
//
double eps = 0.001;
double yval = (left+right)/2.0;
double delta = yval-left;
int maxSteps = 0;
while (delta>0.005 && maxSteps<50)
{
maxSteps++;
double count = 0;
for (int k=0; k<lookBackBars;k++) if (array[i+k]>yval) count++;
double prob = count/lookBackBars;
if (prob>(initValue+eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
delta=yval-left;
}
return(yval);
}
function dzBuy(arrey,initValue,lookBackBars)
{
left = -10000;
right = 10000;
eps = 0.001;
yval = (left+right)/2.0;
delta = yval-left;
maxSteps = 0;
while (delta>0.005 AND maxSteps<50)
{
maxSteps++;
count = 0;
for (k=0; k<lookBackBars ;k++)
if (arrey[k]<yval)
count++;
prob = count/lookBackBars;
if (prob>(initValue+eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
delta=yval-left;
}
return(yval);
}
Plot( dzBuy(RSI(),0.1,70),"",colorGreen,styleLine);
//+------------------------------------------------------------------+
//| dynamic zone smoothed rsi |
//| mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "[email protected]"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DeepSkyBlue
#property indicator_color2 LimeGreen
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_minimum 0
#property indicator_maximum 100
//
//
//
//
//
extern int RsiLength = 9;
extern int RsiPrice = PRICE_CLOSE;
extern int DzLookBackBars = 70;
extern double DzStartBuyProbability = 0.10;
extern double DzStartSellProbability = 0.10;
//
//
//
//
//
double rsi[];
double bli[];
double sli[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
SetIndexBuffer(0,rsi);
SetIndexBuffer(1,bli);
SetIndexBuffer(2,sli);
//
//
//
//
//
string PriceType;
switch(RsiPrice)
{
case PRICE_CLOSE: PriceType = "Close"; break; // 0
case PRICE_OPEN: PriceType = "Open"; break; // 1
case PRICE_HIGH: PriceType = "High"; break; // 2
case PRICE_LOW: PriceType = "Low"; break; // 3
case PRICE_MEDIAN: PriceType = "Median"; break; // 4
case PRICE_TYPICAL: PriceType = "Typical"; break; // 5
case PRICE_WEIGHTED: PriceType = "Weighted"; break; // 6
}
//
//
//
//
//
RsiLength = MathMax(RsiLength ,1);
IndicatorShortName ("Dynamic zone RSI ("+RsiLength+","+PriceType+","+DzLookBackBars+","+DoubleToStr(DzStartBuyProbability,3)+","+DoubleToStr(DzStartSellProbability,3)+")");
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMin(Bars-counted_bars,Bars-1);
//
//
//
//
//
//
for(i=limit; i >= 0; i--)
{
rsi[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
bli[i] = dzBuy (i, rsi, DzStartBuyProbability, DzLookBackBars);
sli[i] = dzSell(i, rsi, DzStartSellProbability, DzLookBackBars);
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
double dzBuy(int i, double& array[], double initValue, int lookBackBars)
{
double left = -10000;
double right = 10000;
if ((Bars-i)<lookBackBars) return(EMPTY_VALUE);
//
//
//
//
//
double eps = 0.001;
double yval = (left+right)/2.0;
double delta = yval-left;
int maxSteps = 0;
while (delta>0.005 && maxSteps<50)
{
maxSteps++;
double count = 0;
for (int k=0; k<lookBackBars;k++) if (array[i+k]<yval) count++;
double prob = count/lookBackBars;
if (prob>(initValue+eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
delta=yval-left;
}
return(yval);
}
//
//
//
//
//
double dzSell(int i, double& array[], double initValue, int lookBackBars)
{
double left = -10000;
double right = 10000;
if ((Bars-i)<lookBackBars) return(EMPTY_VALUE);
//
//
//
//
//
double eps = 0.001;
double yval = (left+right)/2.0;
double delta = yval-left;
int maxSteps = 0;
while (delta>0.005 && maxSteps<50)
{
maxSteps++;
double count = 0;
for (int k=0; k<lookBackBars;k++) if (array[i+k]>yval) count++;
double prob = count/lookBackBars;
if (prob>(initValue+eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
delta=yval-left;
}
return(yval);
}
function dzBuy(arrey,initValue,lookBackBars)
{
left = -10000;
right = 10000;
eps = 0.001;
yval = (left+right)/2.0;
delta = yval-left;
maxSteps = 0;
while (delta>0.005 AND maxSteps<50)
{
maxSteps++;
count = 0;
for (k=0; k<lookBackBars ;k++)
if (arrey[k]<yval)
count++;
prob = count/lookBackBars;
if (prob>(initValue+eps))
{
right = yval;
yval = (yval+left)/2.0;
}
if (prob<(initValue-eps))
{
left = yval;
yval = (yval+right)/2.0;
}
if (prob<(initValue+eps) && prob>(initValue-eps))
{
right = yval;
yval = (yval+left)/2.0;
}
delta=yval-left;
}
return(yval);
}
Plot( dzBuy(RSI(),0.1,70),"",colorGreen,styleLine);