Questions from Beginners MQL5 MT5 MetaTrader 5 - page 266

 
jommerbot:

OK, even in the simplest case it doesn't work:

I don't understand where my mistake is. Copying the same indicator buffer in EA and script works, but not in indicator. The indicator handle is initialized without error.

Find the difference. )

#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrRed
//---
double ExtLineBuffer[];
int    iRocHandleEURUSD =INVALID_HANDLE;
int    iPlotShift       =0;
int    iPeriod          =6;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
   IndicatorSetInteger(INDICATOR_DIGITS,2);
   SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(0,PLOT_SHIFT,iPlotShift);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,iPeriod-1);
//---
   iRocHandleEURUSD=iCustom("EURUSD",0,"Examples\\ROC");
   if(iRocHandleEURUSD==INVALID_HANDLE)
      Print("Не удалось получить хендл индикатора ROC EURUSD");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int    rates_total,
                const int    prev_calculated,
                const int    begin,
                const double &price[])
  {
//---
   if(rates_total<iPeriod)
      return(0);
//---
   int first=0;
   double aRocRatesEURUSD[];
   ArraySetAsSeries(ExtLineBuffer,true);
//---
   if(prev_calculated==0)
      first=0;
   else
      first=prev_calculated-1;
//---
   for(int bar=first; bar<rates_total; bar++)
     {
      CopyBuffer(iRocHandleEURUSD,0,bar,1,aRocRatesEURUSD);
      Print("bar: ",bar,"; value: ",DoubleToString((aRocRatesEURUSD[0]!=EMPTY_VALUE)?aRocRatesEURUSD[0]:0,2));
      ExtLineBuffer[bar]=aRocRatesEURUSD[0];
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Yep, got it, in the last version of my code the indicator handler was getting into the wrong scope of the variable. I missed it, thank you. But there is one problem - in the tester, on historical bars before the beginning of the testing period, the indicator works normally, but starting from the beginning of the testing period the newly arrived ticks are not considered. I.e. buffer of a child indicator is not updated.

 

Good people, please help to correct the code, so that from job line in "Input parameters" of advisor
extern string Lot = "0.2 0.2 0.3 0.4 0.5"; // (through a space)
the last value (in this case 0.5) would repeat infinitely i.e. not to type
"0.2 0.2 0.2 0.3 0.4 0.5 0.5 0.5 0.5 0.5 0.5 0.5";

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

StringToArrayLot(Lot,xiLot);

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

int StringToArrayLot(string st,double &ad[])
{
int i=0,np; string stp;ArrayResize(ad,0);
while(StringLen(st)>0)
{
np=StringFind(st," ");
if(np<0)
{
stp=st;
st="";
} else{
stp=StringSubstr(st,0,np);
st=StringSubstr(st,np+1);
}
i++;
ArrayResize(ad,i);
ad[i-1]=StrToDouble(stp);
}
return(ArraySize(ad));
}

 
Why can't I see my EA on the website or in the terminal?
 
Krasev157:
Why can't I see my EA on the website or in the terminal?
To see it on the website you have to upload it. To compile it in the terminal.
 
zfs:
To see it on the website, you have to upload it. To compile it in the terminal.

I can't see it on my profile.

 
Krasev157:

will post it on the website I can't see it on my profile

Give me a link to an Albanian dictionary, please.
 
barabashkakvn:
Give me a link to an Albanian dictionary, please.

http://www.txtblog.ru/blog/1165306807 here you go

 

Herr Hattar's on fire.

Come on!

Bazinga!

 
Hello, if it's not too much trouble, could you tell me please? How do I put the price of the last 5 ticks into an array?
Reason: