extern int lastxbars=32;
int bartf=0;
extern int ybarsago=21;
extern int adxtf=6;
extern int adxperiod=8;
extern int adxlevel=19;
extern int exitlastxbars=31;
extern int exitybarsago=21;
int signal(int mode,int pos)
{
double high=iHigh(NULL,period(bartf),iHighest(NULL,period(bartf),MODE_HIGH,lastxbars,pos+1));
double low=iLow(NULL,period(bartf),iLowest(NULL,period(bartf),MODE_LOW,lastxbars,pos+1));
if(Close[pos]<low && iHighest(NULL,period(bartf),MODE_HIGH,lastxbars,pos+1)>=ybarsago
&& (period(adxtf)==0 || (period(adxtf)>0 && iADX(NULL,period(adxtf),adxperiod,PRICE_CLOSE,MODE_PLUSDI,pos)>adxlevel)))
if(mode==0)return(1);
if(Close[pos]>high && iLowest(NULL,period(bartf),MODE_LOW,lastxbars,pos+1)>=ybarsago
&& (period(adxtf)==0 || (period(adxtf)>0 && iADX(NULL,period(adxtf),adxperiod,PRICE_CLOSE,MODE_PLUSDI,pos)>adxlevel)))
if(mode==1)return(2);
return(0);
}
int period(int tf)
{
switch(tf)
{
case 0:return(0);
case 1:return(1);
case 2:return(5);
case 3:return(15);
case 4:return(30);
case 5:return(60);
case 6:return(240);
case 7:return(1440);
case 8:return(10080);
case 9:return(43200);
}
return(0);
}