Нашел в библиотеке кода полезный индикатор Ind-Fractals. Однако, он рисует фракталы на каждом баре, вместо того, чтобы просчитывать их как надо. Хотелось бы попользоваться индикатором, а он "сломан"((( Помогите найти ошибку
Поправил
//+------------------------------------------------------------------+ //| Ind-Fractals-1.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ //| Corrections: forex-time@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2018, forex-time@mail.ru" #property link "forex-time@mail.ru" #property strict //---- #property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 Red #property indicator_color2 Red #property indicator_color3 Blue #property indicator_color4 Blue #property indicator_color5 Lime #property indicator_color6 Lime #property indicator_color7 Sienna #property indicator_color8 Sienna //---- input parameters extern bool Comm=true; //Комментарий //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; double ExtMapBuffer5[]; double ExtMapBuffer6[]; double ExtMapBuffer7[]; double ExtMapBuffer8[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init(){ //---- indicators IndicatorBuffers(8); SetIndexStyle(0,DRAW_ARROW);SetIndexArrow(0,217); SetIndexBuffer(0,ExtMapBuffer1);SetIndexEmptyValue(0,0.0); SetIndexStyle(1,DRAW_ARROW);SetIndexArrow(1,218); SetIndexBuffer(1,ExtMapBuffer2);SetIndexEmptyValue(1,0.0); SetIndexStyle(2,DRAW_ARROW);SetIndexArrow(2,217); SetIndexBuffer(2,ExtMapBuffer3);SetIndexEmptyValue(2,0.0); SetIndexStyle(3,DRAW_ARROW);SetIndexArrow(3,218); SetIndexBuffer(3,ExtMapBuffer4);SetIndexEmptyValue(3,0.0); SetIndexStyle(4,DRAW_ARROW);SetIndexArrow(4,217); SetIndexBuffer(4,ExtMapBuffer5);SetIndexEmptyValue(4,0.0); SetIndexStyle(5,DRAW_ARROW);SetIndexArrow(5,218); SetIndexBuffer(5,ExtMapBuffer6);SetIndexEmptyValue(5,0.0); SetIndexStyle(6,DRAW_ARROW);SetIndexArrow(6,217); SetIndexBuffer(6,ExtMapBuffer7);SetIndexEmptyValue(6,0.0); SetIndexStyle(7,DRAW_ARROW);SetIndexArrow(7,218); SetIndexBuffer(7,ExtMapBuffer8);SetIndexEmptyValue(7,0.0); return(0);} //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { Comment(""); return(0);} //------------------------------------------------------------------ bool Fractal(string F,double Per,int shift) { if(Period()>Per) return(0); Per=Per/Period()*2+MathCeil(Per/Period()/2); if(shift<Per)return(0); if(shift>Bars-Per)return(0); for(int i=1;i<=Per;i++) { if(shift+i>=Bars || shift-i<0) return(0); if(F=="Up") { if(High[shift+i]>High[shift])return(0); if(High[shift-i]>=High[shift])return(0);} if(F=="Dn") { if(Low[shift+i]<Low[shift])return(0); if(Low[shift-i]<=Low[shift])return(0);}} return(1); } //------------------------------------------------------------------ int start() { double P=0.0; int D1=1440,H4=240,H1=60,M15=15; int counted_bars=IndicatorCounted(); int shift,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit = MathMin(Bars-counted_bars,Bars-1); if(counted_bars==0) {limit--;limit-=10;} else limit++; if(Period()==D1)P=150*Point;// period возвращает текущий период графика if(Period()==H4)P=70*Point; if(Period()==H1)P=40*Point; if(Period()==30)P=30*Point; if(Period()==M15)P=20*Point; if(Period()==5)P=10*Point; if(Period()==1)P=5*Point; for(shift=limit; shift>0; shift--) { if(Fractal("Up",M15,shift)==1 && Period()==M15) {ExtMapBuffer1[shift]=High[shift]+P;} else ExtMapBuffer1[shift]=0.0; if(Fractal("Up",H1,shift)==1 && Period()==H1) {ExtMapBuffer3[shift]=High[shift]+P;} else ExtMapBuffer3[shift]=0.0; if(Fractal("Up",H4,shift)==1 && Period()==H4) {ExtMapBuffer5[shift]=High[shift]+P;} else ExtMapBuffer5[shift]=0.0; if(Fractal("Up",D1,shift)==1 && Period()==D1) {ExtMapBuffer7[shift]=High[shift]+P;} else ExtMapBuffer7[shift]=0.0; if(Fractal("Dn",M15,shift)==1 && Period()==M15) {ExtMapBuffer2[shift]=Low[shift]-P;} else ExtMapBuffer2[shift]=0.0; if(Fractal("Dn",H1,shift)==1 && Period()==H1) {ExtMapBuffer4[shift]=Low[shift]-P;} else ExtMapBuffer4[shift]=0.0; if(Fractal("Dn",H4,shift)==1 && Period()==H4) {ExtMapBuffer6[shift]=Low[shift]-P;} else ExtMapBuffer6[shift]=0.0; if(Fractal("Dn",D1,shift)==1 && Period()==D1) {ExtMapBuffer8[shift]=Low[shift]-P;} else ExtMapBuffer8[shift]=0.0; } if(Comm) Comment(" D1 - коричневый\n H4 - зелёный\n H1 - синий\nM15 - красный "); return(0);} //+------------------------------------------------------------------+
Там внутри есть функция Fractal(), она объявлена как bool, надо изменить на int.
заменить на
огромное спасибо. бился несколько дней над этим. а не подскажете, почему такая ошибка. bool это же false (-1) или true (1). По коду, функция других значений не принимает, следовательно компилятор должен понимать, что false меньше нуля, true больше
false, это только 0, остальные значение - true, кажется так. Но не в этом дело. Значение возвращаемое функцией используется как int. Раньше в mql4 получалось так, можно было через переменную bool передавать значения int. Потом переменная bool стала работать как настоящая переменная bool и работать перестало.
В Fractal() все -1 заменить на 0
Еще вопрос, возможно ли прописать в коде настройки линий по умолчанию, чтобы не нулевые значения по толщине были, а отличные от нуля

- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Вы принимаете политику сайта и условия использования
Привет всем.
Нашел в библиотеке кода полезный индикатор Ind-Fractals. Однако, он рисует фракталы на каждом баре, вместо того, чтобы просчитывать их как надо. Хотелось бы попользоваться индикатором, а он "сломан"((( Помогите найти ошибку, пробовал связаться с автором, но он на сообщения не отвечает. Для удобства продублировал код сюда и приложение.
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue
#property indicator_color5 Lime
#property indicator_color6 Lime
#property indicator_color7 Sienna
#property indicator_color8 Sienna
//---- input parameters
extern bool Comm=true;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);//стиль линии индикатора
SetIndexArrow(0,217); // прописывает тип стрелки
SetIndexBuffer(0,ExtMapBuffer1);//Связывает указанный индикаторный буфер с одномерным динамическим массивом типа double. Существует 2 варианта функции.
SetIndexEmptyValue(0,0.0);//Устанавливает значение пустой величины для линии индикатора.
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,218);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,217);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,218);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,217);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,218);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,217);
SetIndexBuffer(6,ExtMapBuffer7);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,218);
SetIndexBuffer(7,ExtMapBuffer8);
SetIndexEmptyValue(7,0.0);
return(0); }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {return(0); }
//------------------------------------------------------------------
bool Fractal(string F,int Per,int shift) {
if(Period()>Per) return(-1);
Per=Per/Period()*2+MathCeil(Per/Period()/2);
if(shift<Per)return(-1);
if(shift>Bars-Per)return(-1);
for(int i=1;i<=Per;i++) {
if(shift+i>=Bars || shift-i<0) return(-1);
if(F=="U") {
if(High[shift+i]>High[shift])return(-1);
if(High[shift-i]>=High[shift])return(-1); }
if(F=="L") {
if(Low[shift+i]<Low[shift])return(-1);
if(Low[shift-i]<=Low[shift])return(-1); } }
return(1); }
//------------------------------------------------------------------
int start()
{
int D1=1440,H4=240,H1=60,M15=15,B;
double P;
int counted_bars=IndicatorCounted();// количество баров неизмененных после последнего вызова индикатора
B=Bars-counted_bars;
if(counted_bars==0) B--;
if(Period()==D1)P=150*Point;// period возвращает текущий период графика
if(Period()==H4)P=70*Point;
if(Period()==H1)P=40*Point;
if(Period()==30)P=30*Point;
if(Period()==M15)P=20*Point;
if(Period()==5)P=10*Point;
if(Period()==1)P=5*Point;
for(int shift=B;shift>0;shift--)
{
if(Fractal("U",M15,shift)==1) ExtMapBuffer1[shift]=High[shift]+P;
else ExtMapBuffer1[shift]=0;
if(Fractal("L",M15,shift)==1) ExtMapBuffer2[shift]=Low[shift]-P;
else ExtMapBuffer2[shift]=0;
if(Fractal("U",H1,shift)==1) ExtMapBuffer3[shift]=High[shift]+P;
else ExtMapBuffer3[shift]=0;
if(Fractal("L",H1,shift)==1) ExtMapBuffer4[shift]=Low[shift]-P;
else ExtMapBuffer4[shift]=0;
if(Fractal("U",H4,shift)==1) ExtMapBuffer5[shift]=High[shift]+P;
else ExtMapBuffer5[shift]=0;
if(Fractal("L",H4,shift)==1) ExtMapBuffer6[shift]=Low[shift]-P;
else ExtMapBuffer6[shift]=0;
if(Fractal("U",D1,shift)==1) ExtMapBuffer7[shift]=High[shift]+P;
else ExtMapBuffer7[shift]=0;
if(Fractal("L",D1,shift)==1) ExtMapBuffer8[shift]=Low[shift]-P;
else ExtMapBuffer8[shift]=0;
}
if(Comm) Comment(" D1 - коричневый\n H4 - зелёный\n H1 - синий\nM15 - красный ");
return(0);
}