Questions from Beginners MQL4 MT4 MetaTrader 4 - page 224

 
In the Expert Advisor, the first lines in
OnTick()

After these lines, further code will be executed once per candle. At the moment of its formation.

You call this indicator from the EA, as I understand it?

 
Aleksei Stepanenko:
In the Expert Advisor, the first lines in

After these lines, further code will be executed once per candle. At the moment of its formation.

You are calling this indicator from the EA, as I understand it?

Well, actually, I insert this indicator in another indicator that sends the signal to another program. That is, there is no Expert Advisor. That is, it should be inserted somewhere in the indicator itself, but how?
 
Which programme opens the deals? It is an advisor. Isn't it?
 
Aleksei Stepanenko:
And what program opens the deal? It is the Expert Advisor. Isn't it?

Ah, well, maybe... But then things seem to get a lot more complicated... There's no way to fit it into this code, is there? And there's no code in the second indicator code either.

OnTick()
How the hell does that even work...:)))))
 
You can try another way, where you call this indicator via iCustom, put 1 at the end of this function instead of 0 too.
 
By the way, the indicator still draws a lot of arrows, but when I reload the chart, only some of them remain. :( As if the indicator is saving itself on the history, like look how I trade well, but in real time it is completely different. :(
 
ElenkaVladi:
By the way, the indicator still draws a lot of arrows as well,

Yes? Hmm, I'll have a look at it later.

 
Aleksei Stepanenko:
You can try another way, where you call this indicator via iCustom, put 1 at the end of this function instead of 0 too.

You mean like this?

if (IndicatorName != "") {
      up = iCustom(NULL, 0, IndicatorName, IndiBufferCall, SignalType);
      dn = iCustom(NULL, 0, IndicatorName, IndiBufferPut, SignalType);
if (IndicatorName != "") {
      up = iCustom(NULL, 1, IndicatorName, IndiBufferCall, SignalType);
      dn = iCustom(NULL, 1, IndicatorName, IndiBufferPut, SignalType);

Like this?

 
Aleksei Stepanenko:

Yes? Hmm, I'll have a look at it later.

Maybe it's that message. Shouldn't we do what it says?

https://www.mql5.com/ru/forum/160587/page223#comment_19618305

Anyway, thanks so much for fiddling with us here... :)))

Attaching the files for a better understanding of the situation.

Вопросы от начинающих MQL4 MT4 MetaTrader 4
Вопросы от начинающих MQL4 MT4 MetaTrader 4
  • 2020.11.29
  • www.mql5.com
Если у Вас вопросы по MQL4, MT4, MetaTrader 4, пожалуйста пишите в этой теме. Особенно когда вопросы касаются торговых функций...
 
ElenkaVladi:

Here's the working code:

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_color2  Red
//---- indicator parameters
extern int  period = 4; //12
extern int  shift  = 0; //сдвиг по бару
//---- indicator buffers
double BufferUp[],BufferDn[];
double Ma[],MaOn[];

datetime LastTime=0;
int i, st=5;

int OnInit()
   {
   IndicatorBuffers(2);
//---- drawing settings
   SetIndexStyle(0,DRAW_ARROW,2);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW,2);
   SetIndexArrow(1,234);

   SetIndexBuffer(0,BufferUp);//стрелка синяя верх
   SetIndexBuffer(1,BufferDn);//стрелка красная вниз
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("T3MA-ALARM ("+period+")");
   
   ArraySetAsSeries(Ma,true);
   ArraySetAsSeries(MaOn,true);
//---- initialization done
   if(Digits==3 || Digits==5) st*=10;
   return(INIT_SUCCEEDED);
   }
   
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
   {
   if(rates_total<=MathMax(period,shift)) return(0);
   int limit=rates_total-prev_calculated;   
   if(prev_calculated>0) limit++;

   if(LastTime!=time[1])
      {
      LastTime=time[1];
      ArrayCopy(Ma,Ma,rates_total-ArraySize(Ma),0,WHOLE_ARRAY);
      ArrayCopy(MaOn,MaOn,rates_total-ArraySize(MaOn),0,WHOLE_ARRAY);
      }

   for(i=limit; i>=1; i--) Ma[i]=iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit; i>=1; i--) MaOn[i]=iMAOnArray(Ma,rates_total,period,0,MODE_EMA,i);
      
   for(i=limit; i>=1; i--)
      {
      if(MaOn[i+shift]-MaOn[i+1+shift]<0 && MaOn[i+1+shift]-MaOn[i+2+shift]>0){BufferDn[i+1]=high[i+1]+st*Point;}
      if(MaOn[i+shift]-MaOn[i+1+shift]>0 && MaOn[i+1+shift]-MaOn[i+2+shift]<0){BufferUp[i+1]=low[i+1]-st*Point;}
      }
   return(rates_total);
   }
Note that the arrow is drawn backwards BufferDn[i+1]=... This is unfortunate.
Reason: