Projection Oscillator MT4 qualcuno sa inserire i periodi di rallentamento (1 Viewer)

Frenk

Nuovo forumer
Salve a tutti qui sotto metto il codice dell' indicatore, ma manca dei periodi slow, siccome io del linguaggio di programmazione di MT 4 ne conosco - di 0, qualcuno mi darebbe una mano,,,, metto anche il codice delle relative bande a chi serve...

Oscillatore:

#property copyright "mladen"
#property link "[email protected]"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_color2 PaleVioletRed
#property indicator_width2 2
//#property indicator_style1 STYLE_DOT

//
//
//
//
//

extern int ProjectionPeriod = 20;
extern double SignalPeriod = 3;

//
//
//
//
//

double bufferPoc[];
double bufferSig[];

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
SetIndexBuffer(0,bufferPoc);
SetIndexBuffer(1,bufferSig);
IndicatorShortName("Projection oscilator ("+ProjectionPeriod+","+DoubleToStr(Sign alPeriod,2)+")");
return(0);
}
int deinit() { return(0); }


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
int counted_bars=IndicatorCounted();
int limit,i;

if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=MathMin(Bars-counted_bars,Bars-1);

//
//
//
//
//

double alpha = 2.0/(1.0+SignalPeriod);
for(i=limit; i>=0; i--)
{
double slopel = lrsSlope(ProjectionPeriod,PRICE_LOW ,i);
double slopeh = lrsSlope(ProjectionPeriod,PRICE_HIGH,i);
double max = iMA(NULL,0,1,0,MODE_SMA,PRICE_HIGH,i);
double min = iMA(NULL,0,1,0,MODE_SMA,PRICE_LOW ,i);

for (int k=1; k<ProjectionPeriod; k++)
{
min = MathMin(min,iMA(NULL,0,1,0,MODE_SMA,PRIC E_LOW ,i+k)+k*slopel);
max = MathMax(max,iMA(NULL,0,1,0,MODE_SMA,PRIC E_HIGH,i+k)+k*slopeh);
}
if (max!=min)
bufferPoc = 100.0*(iMA(NULL,0,1,0,MODE_SMA,PRICE_CLO SE,i)-min)/(max-min);
else bufferPoc = 0;
bufferSig = bufferSig[i+1]+alpha*(bufferPoc-bufferSig[i+1]);
}

//
//
//
//
//

return(0);
}



//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//

double lrsSlope(int period,int appliedPrice,int shift)
{
double sumx = period*(period+1.0)/2.0;
double sumx2 = period*(period+1.0)*(2*period+1.0)/6.0;
double sumxy = 0.00;
double sumy = 0.00;

int n = period;
int i;
for (i=0; i<period; i++,n--)
{
double price = iMA(NULL,0,1,0,MODE_SMA,appliedPrice,shi ft+i);
sumxy += n*price;
sumy += price;
}

//
//
//
//
//

double slope = 0.00;
double top = period*sumxy - sumx*sumy;
double bot = period*sumx2 - sumx*sumx;
if (bot != 0) slope = top/bot;
return(slope);
}

Bande:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 PaleVioletRed
#property indicator_color2 DeepSkyBlue

//
//
//
//
//

extern int ProjectionPeriod = 20;

//
//
//
//
//

double bufferUp[];
double bufferDn[];

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{DrawLogo();//¼ÓÔØLogo
SetIndexBuffer(0,bufferUp);
SetIndexBuffer(1,bufferDn);
IndicatorShortName("Projection bands ("+ProjectionPeriod+")");
return(0);
}
int deinit()
{
DeleteLogo();//ɾ³ýLogo
return(0);
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
int counted_bars=IndicatorCounted();
int limit,i;

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--)
{
double slopel = lrsSlope(ProjectionPeriod,PRICE_LOW ,i);
double slopeh = lrsSlope(ProjectionPeriod,PRICE_HIGH,i);
double max = iMA(NULL,0,1,0,MODE_SMA,PRICE_HIGH,i);
double min = iMA(NULL,0,1,0,MODE_SMA,PRICE_LOW ,i);

for (int k=1; k<ProjectionPeriod; k++)
{
min = MathMin(min,iMA(NULL,0,1,0,MODE_SMA,PRIC E_LOW ,i+k)+k*slopel);
max = MathMax(max,iMA(NULL,0,1,0,MODE_SMA,PRIC E_HIGH,i+k)+k*slopeh);
}
bufferUp = max;
bufferDn = min;
}

//
//
//
//
//

return(0);
}



//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//

double lrsSlope(int period,int appliedPrice,int shift)
{
double sumx = period*(period+1.0)/2.0;
double sumx2 = period*(period+1.0)*(2*period+1.0)/6.0;
double sumxy = 0.00;
double sumy = 0.00;

int n = period;
int i;
for (i=0; i<period; i++,n--)
{
double price = iMA(NULL,0,1,0,MODE_SMA,appliedPrice,shi ft+i);
sumxy += n*price;
sumy += price;
}

//
//
//
//
//

double slope = 0.00;
double top = period*sumxy - sumx*sumy;
double bot = period*sumx2 - sumx*sumx;
if (bot != 0) slope = top/bot;
return(slope);
}
void writetext(string Labelname,string data,int x,int y,int Corner,color ColorValue,int FontSize)//ͨ¹ýObjectдÎÄ×Ö
{
ObjectDelete(Labelname);
ObjectCreate(Labelname, OBJ_LABEL, 0, 0, 0);
ObjectSetText(Labelname, data, FontSize, "Arial", ColorValue);
ObjectSet(Labelname, OBJPROP_CORNER, 0);
ObjectSet(Labelname, OBJPROP_CORNER,Corner);
ObjectSet(Labelname, OBJPROP_XDISTANCE, x);
ObjectSet(Labelname, OBJPROP_YDISTANCE, y);
}
void DrawLogo()
{
int Corner=2;
int x=10;
int y=10;
color ColorValue=White;
color LogoColor=Yellow;

}

void DeleteLogo()
{
ObjectDelete("×óϽÇ");
for(int i=0;i<=10;i++)
ObjectDelete("ÉϺáÏß"+i);
ObjectDelete("ÓÒϽÇ");
for(int j=0;j<=1;j++)
ObjectDelete("×óÊúÏß"+j);
for(j=0;j<=1;j++)
ObjectDelete("×óÊúÏß1"+j);
ObjectDelete("×óÉϽÇ");
ObjectDelete("ÎÄ×Ö1");
ObjectDelete("ÎÄ×Ö2");
for(int k=0;k<=10;k++)
ObjectDelete("ϺáÏß"+k);
ObjectDelete("ÓÒÉϽÇ");
for(int r=0;r<=1;r++)
ObjectDelete("ÓÒÊúÏß"+r);
for(r=0;r<=1;r++)
ObjectDelete("ÓÒÊúÏß1"+r);
}
 

Users who are viewing this thread

Alto