Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 807

 

Good day everyone! I'm sitting here spinning the indicator. I think I've done everything right. But the thing is... Opens trades on every candle


Expert Advisor code

// получение сигнала _________________________________________________________________________________________________________

int signal=-1;

if (time_bar!=Time[0]) {

time_bar=Time[0];

double stop_buy=iCustom(Symb,0, "cm-FiguresCandle",AlertON,colorBulls,colorBears,DrawCandle,0,1)

double stop_sell=iCustom(Symb,0, "cm-FiguresCandle",AlertON,colorBulls,colorBears,DrawCandle,1,1);

if(stop_buy!=EMPTY_VALUE || stop_sell!=EMPTY_VALUE) {

double super_buy=iCustom(Symb,0, "xSuperTrend Tape MTF NRP",",",SuperTrend_Period,SuperTrend_Multiplier,SuperTrend_TimeFrame,SuperTrend_AutoTF,0,1);

if(stop_buy!=EMPTY_VALUE && super_buy==1) signal=0;

if(stop_sell!=EMPTY_VALUE && super_buy==EMPTY_VALUE) signal=1;

}


indicator code


return(0);

}

//+------------------------------------------------------------------+

int start()

{

string NameFigur;

int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

int limit=Bars-counted_bars;

if(counted_bars==0) limit-=1+2;


for(int i=1; i<limit; i++)

{

bool up=false,down=false;

double MA0 = iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,i);

double MA1 = iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,i);

double MA2 = iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,i+1);

double MA3 = iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,i+2);


if(MA0>MA1 && MA1>MA2 && MA2>MA3) up=true;

else up=false;

if(MA0<MA1 && MA1<MA2 && MA2<MA3) down=true;

else down=false;

//---

NameFigur=";

if(Close[i]>Close[i+1] && Close[i]>Open[i+1])

{

if(down && Open[i+1]>Close[i+1] && Open[i]>Close[i+1] && Close[i]<Open[i+1] && Close[i]>Open[i])

{

NameFigur="BullHarami";

Redraw(i,colorBulls,NameFigur); Redraw(i+1,colorBulls,NameFigur);

}

if(Open[i+1]>Close[i+1] && Open[i]>Close[i+1] && Open[i]<Open[i+1] && Close[i]>Open[i+1])

{

NameFigur="BullCross";

Redraw(i,colorBulls,NameFigur); Redraw(i+1,colorBulls,NameFigur);

}

if(Close[i+1]<Open[i+1] && Open[i]<Close[i+1] && Close[i]>Open[i+1])

{

NameFigur="Bullish Engulfing";

if(Close[i+1]<Open[i+1] && Close[i]>Open[i] && Open[i]<Close[i+1] && Close[i]>Close[i+1]+((Open[i+1]-Close[i+1])/2))

{

NameFigur="BullPierce";

}

Redraw(i,colorBulls,NameFigur); Redraw(i+1,colorBulls,NameFigur);

}

if(Close[i+2]<Open[i+2] && Open[i+1]<Close[i+2] && Close[i+1]<Close[i+2] && Open[i]>Close[i+1] && Open[i]>Open[i+1] && Close[i]>=Close[i+2])

{

NameFigur="Morning Star";

Redraw(i,colorBulls,NameFigur); Redraw(i+1,colorBulls,NameFigur); Redraw(i+2,colorBulls,NameFigur);

}

}

if(Open[i]-Low[i]>MathMax(High[i]-Close[i],Close[i]-Open[i])*3 && Close[i]-Low[i]>MathMax(High[i]-Close[i],Close[i]-Open[i])*3)

{

NameFigur="Hammer";

if(up) {Redraw(i,colorBulls,NameFigur); Redraw(i+1,colorBulls,NameFigur);}

if(down) {Redraw(i,colorBears,NameFigur); Redraw(i+1,colorBears,NameFigur);}

}

///// bears ///// bears ///// bears ///// bears ///// bears ///// bears ///// bears ///// bears

if(Close[i]<Close[i+1] && Close[i]<Open[i+1])

{

if(up& Open[i+1]<Close[i+1] && Open[i]<Close[i+1] && Close[i]>Open[i+1] && Close[i]<Open[i])

{

NameFigur="BearHarami";

Redraw(i,colorBears,NameFigur); Redraw(i+1,colorBears,NameFigur);

}

if(Open[i+1]<Close[i+1] && Open[i]<Close[i+1] && Open[i]>Open[i+1] && Close[i]<Open[i+1])

{

NameFigur="BearCross";

Redraw(i,colorBears,NameFigur); Redraw(i+1,colorBears,NameFigur);

}

if(Close[i+1]>Open[i+1] && Close[i]<Open[i] && Open[i]>Close[i+1] && Close[i]<Open[i+1])

{

NameFigur="BearEngulf";

if(Close[i+1]>Open[i+1] && Open[i]>Close[i+1] && Close[i]<Close[i+1]-((Close[i+1]-Open[i+1])/2))

{

NameFigur="DarkCloud";

}

Redraw(i,colorBears,NameFigur); Redraw(i+1,colorBears,NameFigur);

}


if(Close[i+2]>Open[i+2] && Open[i+1]>Close[i+2] && Close[i+1]>Close[i+2] && Open[i]<Close[i+1] && Open[i]<Open[i+1] && Close[i]<Close[i+2])

{

NameFigur="EveningStar";

Redraw(i,colorBears,NameFigur); Redraw(i+1,colorBears,NameFigur); Redraw(i+2,colorBears,NameFigur);

}

if(up && High[i]-Open[i]>MathMax(Close[i]-Low[i],Open[i]-Close[i])*3 && High[i]-Close[i]>MathMax(Close[i]-Low[i],Open[i]-Close[i])*3)

{

NameFigur="Shooter";

Redraw(i,colorBears,NameFigur); Redraw(i+1,colorBears,NameFigur);

}

}

if(NameFigur!="")

{

double DELTA=(MathMax(High[i],High[i+1])-MathMin(Low[i],Low[i+1]))/2;

if(Color==colorBears) {BufferDN[i]=MathMax(High[i],High[i+1]);P=BufferDN[i]+DELTA;}

else {BufferUP[i]=MathMin(Low[i],Low[i+1]);P=BufferUP[i]-DELTA;}

DrawTEXT(StringConcatenate(NameFigur," ",TimeToStr(Time[i],TIME_DATE|TIME_MINUTES)),NameFigur,Color,Time[i+1],P);

}

}

if(Timei!=Time[0] && AlertON && i==0 && NameFigur!="") {Alert(Symbol()+" FiguresCandle ="+NameFigur);Timei=Time[0];}

return(0);

}

//-------------------------------------------------------------------

void Redraw(int i,color col,string name)

{

Color=col;

if(!DrawCandle) return;

name=StringConcatenate(name,",TimeToStr(Time[i],TIME_DATE|TIME_SECONDS));

ObjectCreate(name,OBJ_TREND,0,Time[i],High[i],Time[i],Low[i]);

ObjectSet(name,OBJPROP_COLOR,col);

ObjectSet(name,OBJPROP_STYLE,STYLE_SOLID);

ObjectSet(name,OBJPROP_BACK,false);

ObjectSet(name,OBJPROP_RAY,false);

ObjectSet(name,OBJPROP_WIDTH,2);

name=StringConcatenate(name," o");

ObjectCreate(name,OBJ_TREND,0,Time[i],Open[i],Time[i];

ObjectSet(name,OBJPROP_COLOR,col);

ObjectSet(name,OBJPROP_STYLE,STYLE_SOLID);

ObjectSet(name,OBJPROP_BACK,false);

ObjectSet(name,OBJPROP_RAY,false);

ObjectSet(name,OBJPROP_WIDTH,2);

name=StringConcatenate(name," c");

ObjectCreate(name,OBJ_TREND,0,Time[i],Close[i],Time[i]+Period()*60,Close[i]);

ObjectSet(name,OBJPROP_COLOR,col);

ObjectSet(name,OBJPROP_STYLE,STYLE_SOLID);

ObjectSet(name,OBJPROP_BACK,false);

ObjectSet(name,OBJPROP_RAY,false);

ObjectSet(name,OBJPROP_WIDTH,2);

}

//-------------------------------------------------------------------

void DrawTEXT(string NT,string Name,color col,datetime t1,double p1)

{

ObjectDelete(NT);

ObjectCreate(NT,OBJ_TEXT,0,t1,p1,0,0,0);

ObjectSet(NT,OBJPROP_COLOR,col);

ObjectSetText(NT,Name,10, "Arial");

}

//--------------------------------------------------------------------


 
Kos Mos:

Good day everyone! I'm sitting here spinning the indicator. I think I've done everything right. But the thing is... I opened a deal on every candle.



The "sheet" is really impressive :-) Insert the code more carefully and do not copy out obviously unnecessary things

on the subject - print yourself values of stop_buy and stop_sell. Because the condition is explicitly triggered :

  if(stop_buy!=EMPTY_VALUE || stop_sell!=EMPTY_VALUE) {

maybe stop_buy and stop_sell are initialized with 0 instead of EMPTY_VALUE

 
Maxim Kuznetsov:

The "sheet" is of course quite good :-) insert the code more carefully and do not copy anything obviously unnecessary

On the subject - print yourself stop_buy and stop_sell. Because clearly a condition is triggered :

  if(stop_buy!=EMPTY_VALUE || stop_sell!=EMPTY_VALUE) {

maybe stop_buy and stop_sell are initialized with 0 and not with EMPTY_VALUE

Sorry about that )) - for a whole page for God's sake)


I'll try it now)

 
Maxim Kuznetsov:

The "sheet" is of course quite good :-) insert the code more carefully and do not copy anything obviously unnecessary

On the subject - print yourself values of stop_buy and stop_sell. Because clearly the condition is triggered :

  if(stop_buy!=EMPTY_VALUE || stop_sell!=EMPTY_VALUE) {

maybe stop_buy and stop_sell are initialized with 0 instead of EMPTY_VALUE

it still does not work. By the way, I've noticed that sell order opens correctly, but in the buy order goes crazy and opens a billion))

 
Kos Mos:

It still does not work out the same way. I noticed, by the way, that the trades in sell are opening correctly, but in buy it goes crazy and opens a billion))

Well, at least the search can be enabled? Insert code...

What a problem... You don't even have to turn on search, the forum engine puts the skillet itself...
 
Alexey Viktorov:

Can you at least enable search? Insert code...

What a shame... You don't even have to do a search, the forum engine itself puts the skillet in...

I apologise profusely, not much experience of behaving myself on the forum)))



   // получение сигнала _________________________________________________________________________________________________________
   int signal=-1;
   if (time_bar!=Time[0]) {
      time_bar=Time[0];
      double stop_buy=iCustom(Symb,0,"cm-FiguresCandle",AlertON,colorBulls,colorBears,DrawCandle,0,1);
      double stop_sell=iCustom(Symb,0,"cm-FiguresCandle",AlertON,colorBulls,colorBears,DrawCandle,1,1);
      if(stop_buy!=EMPTY_VALUE || stop_sell!=EMPTY_VALUE) {
         double super_buy=iCustom(Symb,0,"xSuperTrend Tape MTF NRP","","",SuperTrend_Period,SuperTrend_Multiplier,SuperTrend_TimeFrame,SuperTrend_AutoTF,0,1);
        if(stop_buy!=EMPTY_VALUE && super_buy==1) signal=0;
         if(stop_sell!=EMPTY_VALUE && super_buy==EMPTY_VALUE) signal=1;
         }


 
I can't get the skis to go, can you please help me?)
 
Hi all, who can help me combine two indicators into one, I have the source code, I really need it
 
Олег:
Hello all, who can help me merge two indicators into one, I have the source code, I really need it

You either show me what you can't do when merging, or contact me if you haven't done it yourself or don't want to do it:

Торговые приложения для MetaTrader 5 на заказ
Торговые приложения для MetaTrader 5 на заказ
  • www.mql5.com
Имеется готовый год с Амиброкера который можно использовать для "перевода" в МТ4 ( с дополнениями) Советник должен работать на всех тайм фреймах (внутри дня, дневной и выше) и обязательно на Ренко Советник должен торговать на корзине инструментов (портфель) У советника должна быть возможность менять параметры в окне (без необходимости открывать...
 
Artyom Trishkin:

You either show me what you can't do when merging, or come here if you haven't done it yourself, or don't want to do it:

I'm trying to find out exactly what I can't do, I understand that no one is likely to tell me anything for free - capitalism, for fuck's sake)). I have nothing against it, I just need to understand why trades open on every candle in the buy direction.

Reason: