задаем внешнюю переменную для индика:
extern int BarsForFract=48;
инициализация:
//+------------------------------------------------------------------+
//| Expert Initialization Function |
//+------------------------------------------------------------------+
int init()
{
ObjectCreate("BaryUp",OBJ_TREND,0,Time[0],0.0,Time[1],0.0);
ObjectSet("BaryUp",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("BaryUp",OBJPROP_COLOR,DodgerBlue);
ObjectCreate("BaryDown",OBJ_TREND,0,Time[0],0.0,Time[1],0.0);
ObjectSet("BaryDown",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("BaryDown",OBJPROP_COLOR,DodgerBlue);
return(0);
}
деинит:
//+------------------------------------------------------------------+
//| Expert Deinitialization Function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("BaryUp");
ObjectDelete("BaryDown");
return(0);
}
Сама процедура:
//+------------------------------------------------------------------+
//| SHI Bary Channel |
//+------------------------------------------------------------------+
void Bary()
{
int CurrentBar, UpDown, i,B1,B2, BFF;
double P1, P2, PP, Step;
datetime T1, T2;
if (BarsForFract>0) BFF=BarsForFract; else
switch (Period())
{
case 1: BFF=12; break;
case 5: BFF=48; break;
case 15: BFF=24; break;
case 30: BFF=24; break;
case 60: BFF=12; break;
case 240: BFF=15; break;
case 1440: BFF=10; break;
case 10080: BFF=6; break;
case 43200: BFF=6; break;
default: BFF=2; break;
}
CurrentBar=2; B1=-1; B2=-1; UpDown=0;
while ((B1==-1 || B2==-1) && CurrentBar<Bars)
{
if (UpDown<1 && CurrentBar==Lowest(NULL,0,MODE_LOW,BFF*2+1,CurrentBar-BFF))
{
if (UpDown==0) {UpDown=-1;B1=CurrentBar;P1=Low[B1];} else {B2=CurrentBar;P2=Low[B2];}
}
if (UpDown>-1 && CurrentBar==Highest(NULL,0,MODE_HIGH,BFF*2+1,CurrentBar-BFF))
{
if (UpDown==0) {UpDown=1;B1=CurrentBar;P1=High[B1];} else {B2=CurrentBar;P2=High[B2];}
}
CurrentBar++;
}
if (B1==-1 || B2==-1) return(0);
Step=(P2-P1)/(B2-B1);
P1=P1-B1*Step; B1=0;
if (UpDown==1)
{
PP=Low[2]-2*Step;
for (i=3; i<=B2; i++) {if (Low[i]<PP+Step*i) { PP=Low[i]-i*Step; }}
} else
{ PP=High[2]-2*Step;
for (i=3; i<=B2; i++) {if (High[i]>PP+Step*i) { PP=High[i]-i*Step;}}
}
P2=P1+(Bars-10)*Step;
T1=Time[B1]; T2=Time[Bars-10];
txt="BaryUp";
ObjectSet(txt,OBJPROP_TIME1,T2);
ObjectSet(txt,OBJPROP_TIME2,T1);
ObjectSet(txt,OBJPROP_PRICE1,PP+Step*(Bars-10));
ObjectSet(txt,OBJPROP_PRICE2,PP);
txt="BaryDown";
ObjectSet(txt,OBJPROP_TIME1,T2);
ObjectSet(txt,OBJPROP_TIME2,T1);
ObjectSet(txt,OBJPROP_PRICE1,P2);
ObjectSet(txt,OBJPROP_PRICE2,P1);
return(0);
}