Помогите начинающему разобратся с экспертом

 
Пробую написать эксперта на основе примера с данного сайта. Почемуто открывает позиции только SEL, а BAY не хочет. Помогите.
Сам эксперт (После текста эксперта, приведу на всякий случай текст индикатора, на котором основывается эксперт):
extern double TakeProfit = 300;
extern double Lots = 1;
extern double TrailingStop = 20;
extern double StopLoss =20;
extern int AroonPeriod=10;
extern int Filter=50;
extern int CountBars=3000;

extern int Level1=80;
extern int Level2=-80;

int start()
{
double AroonCurrent, AroonPrevious, AroonPrevious2;
int cnt=0, ticket, total;
// первичные проверки данных
// важно удостовериться что эксперт работает на нормальном графике и
// пользователь правильно выставил внешние переменные (Lots, StopLoss,
// TakeProfit, TrailingStop)
// в нашем случае проверяем только TakeProfit
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // проверяем TakeProfit
}
if(StopLoss<15)
{
Print("StopLoss loss than 15");
return(0); // проверяем TakeProfit
}
// ради упрощения и ускорения кода, сохраним необходимые
// данные индикаторов во временных переменных
AroonCurrent=iCustom(NULL,0,"Aroon_Oscilator_v1",AroonPeriod,Filter,CountBars,DRAW_LINE,0);
AroonPrevious=iCustom(NULL,0,"Aroon_Oscilator_v1",AroonPeriod,Filter,CountBars,DRAW_LINE,1);
AroonPrevious2=iCustom(NULL,0,"Aroon_Oscilator_v1",AroonPeriod,Filter,CountBars,DRAW_LINE,2);


total=OrdersTotal();
if(total<1)
{
// нет ни одного открытого ордера
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
// проверяем на возможность встать в длинную позицию (BUY)
if(AroonCurrent>Level2 && AroonPrevious<Level2)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"AT&CF sample",16384,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
// проверяем на возможность встать в короткую позицию (SELL)
if(AroonCurrent<Level1 && AroonPrevious>Level1)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,
"AT&CF sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
// переходим к важной части эксперта - контролю открытых позиций
// 'важно правильно войти в рынок, но выйти - еще важнее...'
for(cnt=0;cnt<total;cnt++) //Оператор цикла. (Усл. запуска; Усл. заверш.цикла;+1 )
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); //Функция выбирает ордер. Возвращает ИСТИНА при успешном завершении функции
//(Позиция ордера, ,ордер выбирается среди открытых и отложенных ордеров)
if(OrderType()<=OP_SELL && // это открытая позиция? OP_BUY или OP_SELL
OrderSymbol()==Symbol()) // инструмент совпадает?
{
if(OrderType()==OP_BUY) // открыта длинная позиция
{
// проверим, может уже пора закрываться?
if(AroonCurrent>Level1 && AroonPrevious<Level1)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // закрываем позицию
return(0); // выходим
}
// проверим - может можно/нужно уже трейлинг стоп ставить?
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,
OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // иначе это короткая позиция
{
// проверим, может уже пора закрываться?
if(AroonCurrent<Level2 && AroonPrevious>Level2)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // закрываем позицию
return(0); // выходим
}
// проверим - может можно/нужно уже трейлинг стоп ставить?
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,
OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
// конец.

ИНДИКАТОР:
//+------------------------------------------------------------------+
//| Custom Aroon Oscilator_v1.mq4 |
//| rafcamara |
//| Has corrected - Ramdass |
//+------------------------------------------------------------------+
#property copyright "rafcamara"
#property link "rafcamara@yahoo.com"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Snow
#property indicator_color4 Green

//---- indicator parameters
extern int AroonPeriod=10;
extern int Filter=50;
extern int CountBars=300;

//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];

double HighBarBuffer[];
double LowBarBuffer[];
double ArOscBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{

//---- additional buffers are used for counting.
IndicatorBuffers(6);
SetIndexBuffer(4, HighBarBuffer);
SetIndexBuffer(5, LowBarBuffer);
SetIndexBuffer(3, ArOscBuffer);
SetIndexBuffer(0, ind_buffer1);
SetIndexBuffer(1, ind_buffer2);
SetIndexBuffer(2, ind_buffer3);



//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);

IndicatorDigits(0);
//-- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2)
&& !SetIndexBuffer(2,ind_buffer3))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("Aroon Osc_v1("+AroonPeriod+", "+Filter+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Aroon Oscilator |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>=Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+AroonPeriod+1);
SetIndexDrawBegin(1,Bars-CountBars+AroonPeriod+1);
SetIndexDrawBegin(2,Bars-CountBars+AroonPeriod+1);
SetIndexDrawBegin(3,Bars-CountBars+AroonPeriod+1);
double ArOsc, HighBar=0,LowBar=0;
int ArPer;
int limit,i;
// bool up,dn;
int counted_bars=IndicatorCounted();

ArPer=AroonPeriod;
//---- check for possible errors
if(counted_bars<0) return(-1);

//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=ArPer;i++) HighBarBuffer[CountBars-i]=0.0;
for(i=1;i<=ArPer;i++) LowBarBuffer[CountBars-i]=0.0;
for(i=1;i<=ArPer;i++) ArOscBuffer[CountBars-i]=0.0;
for(i=1;i<=ArPer;i++) ind_buffer1[CountBars-i]=0.0;
for(i=1;i<=ArPer;i++) ind_buffer2[CountBars-i]=0.0;
for(i=1;i<=ArPer;i++) ind_buffer3[CountBars-i]=0.0;
}

//---- last counted bar will be recounted
//if(counted_bars>0) counted_bars--;
limit=CountBars-AroonPeriod;

//----Calculation---------------------------
for( i=0; i<limit; i++)
{
HighBarBuffer[i] = Highest(NULL,0,MODE_HIGH,ArPer,i); //Periods from HH
LowBarBuffer[i] = Lowest(NULL,0,MODE_LOW,ArPer,i); //Periods from LL

ArOscBuffer[i]= 100*(LowBarBuffer[i]-HighBarBuffer[i])/ArPer; //Short formulation
}

//---- dispatch values between 2 buffers
for(i=limit-1; i>=0; i--)
{
ArOsc=ArOscBuffer[i];
if(ArOsc>Filter)
{
ind_buffer1[i]=ArOsc;
ind_buffer2[i]=0.0;
ind_buffer3[i]=0.0;
}
if(ArOsc<-Filter)
{
ind_buffer1[i]=0.0;
ind_buffer2[i]=ArOsc;
ind_buffer3[i]=0.0;
}
if(ArOsc<=Filter && ArOsc>=-Filter)
{
ind_buffer1[i]=0.0;
ind_buffer2[i]=0.0;
ind_buffer3[i]=ArOsc;
}
}
//---- done
return(0);
}
 
Глянь на значение которые возвращает индикатор:
AroonCurrent=iCustom(NULL,0,"Aroon_Oscilator_v1",AroonPeriod,Filter,CountBars,DRAW_LINE,0);
AroonPrevious=iCustom(NULL,0,"Aroon_Oscilator_v1",AroonPeriod,Filter,CountBars,DRAW_LINE,1);
AroonPrevious2=iCustom(NULL,0,"Aroon_Oscilator_v1",AroonPeriod,Filter,CountBars,DRAW_LINE,2);


У меня при тестировании получилось соответственно:
2147483647.00000000
2147483647.00000000
2147483647.00000000

Хотя как я понял число должно быть в интервале от -100 до 100.
Levitator, откуда этот индикатор, ссылку будьте добры!?

 
К сожалению не помню где взял. Гдето в интернете. Просто тут как-то руки дошли просмотреть пользовательские индикаторы, наткнулся на него. Подключил к графику и решил что можно попробовать его использовать.
 
extern int Level1=80;
extern int Level2=-80;



Надо бы double. Глянуд на графике на 4-х часовке, рисует, но эти уронви достигает редко и с опозданием, дневки не смотрел.

 
И я тут только что проверял его еще раз. Заменил в установках внутренних переменных индекс линии с DRAW_LINE на 3. Вродеэксперт заработал. Правда пока не проверил насколько правильно.
Причина обращения: