[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 269

 
You are slightly confused, UNINIT REASON has nothing to do with returns relative to standard functions. Write an EA and call the "init" from "start" with different return results and see. Actuallyhttps://docs.mql4.com/ru/basis/functions/special the doc says it all perfectly. Just re-read it again carefully .
 
drknn:


1. To decide exactly what a normal function should return, I should know why the main code needs such a value. For example, if I want to make a decision to open a buy order when there is a signal, I will write a function that returns the number of already opened buy orders. Depending on how many there are, the code will make a decision following the logic embedded in the code. I don't know what logic is embedded in the return code. Today I was looking through an article about creating a semaphore and I came across a return code (-2). Surprised, asked a question here. That's all. ( https://www.mql5.com/ru/articles/1412 - article here).

2. the terminal ignores the return values. Is this accurate? If so, then again a legitimate question arises, why in creating an EA/indicator/script the developer put in a template exactly int, because it would be more logical to put there void - then the terminal would not have to ignore anything - we would then gain 1 tact of processor time? Maybe there is some logic in WHAT to return from int init(), int deinit() and int start() functions? I think Roche already explained it to someone somewhere - he remembered a description of when to return zero and when to return (-1). It was this very explanation I was searching for. Too bad I couldn't find it...

P.S.

The author of the article uses return(-2) for his own purposes. But the fact is that sometimes the start() function ends with code returning a value different from zero. And it is not only one person who does it. This is exactly this logic I want to understand.

1. I cannot add anything to it. Whatever you want, return it.

2. The terminal ignores it and your code doesn't ignore it, if that's how it's built. The system call ignores both parameters and the return value. It's pretty obvious. Where does it go back to in this case?

We can only guess at the creation of the pattern. The developers must have proceeded from the default INT.

 
okvseok:

how you can understand these lines:

Write like this and look in the journal:

//---- return orders volume

if(buys>0){
 Print("buys = ",buys);
 return(buys);
}
else{
 Print("-sells = ",-sells);
 return(-sells);// это эквивалентно команде return(sells*(-1));
}
 

Can you give me some advice?

I use several indicators that use date in global variables

extern bool   shiftdata           = false;
extern string ShiftHistory        = "02.06.2012 00:00";

If you change the date in the history, you have to change it in all indicators.

Ihave made an indicator that sends shift value through iCustom to int bars.

But the problem is that it passes the unchanged date which is compiled (02.07.2012), but when you change it manually (02.06.2012) it's not passed!

WHY and WHAT TO DO????

//+------------------------------------------------------------------+
//|                                                        iTime.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
extern string BLOK_______1        = "Работа с историей";
extern string ShiftHistory        = "02.07.2012 00:00";
extern string PERIOD              = "D1";
//---
double buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,buffer);
   SetIndexStyle(0,DRAW_ARROW,0,0);
   SetIndexEmptyValue(0,0.0);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
int  counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
int i,period,limit,bs,barn;

if(PERIOD=="MN1") period=PERIOD_MN1;
else
if(PERIOD=="W1")  period=PERIOD_W1;
else
if(PERIOD=="D1")  period=PERIOD_D1;
else 
if(PERIOD=="H4")  period=PERIOD_H4;
else
if(PERIOD=="H1")  period=PERIOD_H1;
else
if(PERIOD=="M30") period=PERIOD_M30;
else
if(PERIOD=="M15") period=PERIOD_M15;
else
if(PERIOD=="M5")  period=PERIOD_M5;
else
if(PERIOD=="M1")  period=PERIOD_M1;
else
period=PERIOD_D1;

bs=iBarShift(Symbol(),period,StrToTime(ShiftHistory));
barn=iBars(Symbol(),period);
limit=barn-100;

if(limit>bs)
for(i=barn-1; i>=0; i--)
{
if (i==bs) buffer[i]=bs;
} RefreshRates();
return(0);
}

Here is the receiver

for(int y=barn-100; y>=0; y--)
{
int bbb,st=iCustom(Symbol(),PERIOD,"iTime",0,y);
if(st>0) bbb=st;
}
 Comment(bbb);

Comment writes shift 16. And at 02.06.2012 should be 48.

Please help advise!

 

help me determine the last high and low of a zigzag in an EA

double zz1;
int start()
{
zz1=iCustom(NULL,0, "ZigZag", 12, 5, 3, 0, 1);
MessageBox("zz1="+zz1,"zz1");
return(0);
}
"0.00000" is coming out

 
spek:

help me determine the last high and low of a zigzag in an EA

double zz1;
int start()
{
zz1=iCustom(NULL,0, "ZigZag", 12, 5, 3, 0, 1);
MessageBox("zz1="+zz1,"zz1");
return(0);
}
"0.00000" is coming out

double ZZ[10000]={0.0};  //массив для значений ZigZag
double zz1[10000]={0.0};

//-----
int init()
{

}
return(0);
//---
int start()
{
int q=1;   //ПОПРАВИЛ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

for(int i=1; i<=1000; i++)
{
zz1[i]=iCustom(NULL,0,"ZigZag", 12, 5, 3, 0, i);
if(zzl[i]>0) { ZZ[q]=zzl[i];  q++; }
//MessageBox("zz1="+zz1,"zz1");
Comment(ZZ[1],"  ",ZZ[2]);

return(0);
}
 

I want to put "Alert()" in it to tell me when the trend has reversed.

I want to put "Alert()" there to tell me when the trend reversed.

//+------------------------------------------------------------------+
//|                                                    mikahekin.mq4 |
//|                        Copyright 2004, MetaQuotes Software Corp. |
//|                                                http://www.sasara |
//|                              Modified by: Ronald Verwer/ROVERCOM |
//+------------------------------------------------------------------+
#property copyright "Copyright 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property  indicator_chart_window
#property  indicator_buffers 4
#property  indicator_color1  Silver
#property  indicator_color2  Yellow
#property  indicator_color3  Red
#property  indicator_color4  Blue
#property  indicator_width1 3
#property  indicator_width2 3

//---- input parameters
extern int KPeriod=3;
extern int DPeriod=3;
extern int JPeriod=7;

double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double HighesBuffer[];
double LowesBuffer[];

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
        IndicatorBuffers(6);
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 3);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 3);
   SetIndexStyle(2,DRAW_ARROW, 0, 1);
   SetIndexStyle(3,DRAW_ARROW, 0, 1);
//----
   SetIndexDrawBegin(0,10);
   SetIndexDrawBegin(1,10);
   SetIndexDrawBegin(2,10);
   SetIndexDrawBegin(3,10);
   SetIndexDrawBegin(4,10);
   SetIndexDrawBegin(5,10);
//---- indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
   SetIndexBuffer(3,ind_buffer4);
   SetIndexBuffer(4, HighesBuffer);
   SetIndexBuffer(5, LowesBuffer);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("mikahekin");
   SetIndexLabel(0,"Open");
   SetIndexLabel(1,"Close");
   SetIndexLabel(2,"High");
   SetIndexLabel(3,"Low");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,j;
   int    counted_bars=IndicatorCounted();
   double price;
   
//----
   if(Bars<=10) return(0);
//---- initial zero
   if(counted_bars<0) return (-1);
//---- minimums  counting
   i=Bars-KPeriod;
   if(counted_bars>KPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double min=1000000;
      k=i+KPeriod-1;
      while(k>=i)
        {
         price=Low[k];
         if(min>price) min=price;
         k--;
        }
      LowesBuffer[i]=min;
      i--;
     }
//---- maximums counting
   i=Bars-DPeriod;
   if(counted_bars>DPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double max=-100000;
      j=i+DPeriod-1;
      while(j>=i)
        {
         price=High[j];
         if(price>max) max=price;
         j--;
        }
      HighesBuffer[i]=max;
      i--;
     }
//---- mikahekin calcaulation
   i=Bars-JPeriod;
   if(counted_bars>JPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumlow=0.0;
      double sumhigh=0.0;
      double sumopen=0.0;
      double sumclose=0.0;
      double close=0.0;
      double open=0.0;
      double high=0.0;
      double low=0.0;

      for(k=(i+JPeriod-1);k>=i;k--)
         {
         sumclose+=Close[k];
         close=sumclose/JPeriod;
         sumlow+= LowesBuffer[k];
         low= sumlow/JPeriod;
         sumopen+=Open[k];
         open=sumopen/JPeriod;
         sumhigh+=HighesBuffer[k];
         high=sumhigh/JPeriod;
         }
         
      ind_buffer1[i]=open;
      ind_buffer2[i]=close;
      ind_buffer3[i]=high;
      ind_buffer4[i]=low;

      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
Z.I. I'm a little better at mql4 than I am at ballet, but...
 
Zhunko:

1. I can't add anything. Whatever you want, return it.

2. terminal ignores and your code doesn't ignore, if that's how it's built. The system call ignores both the parameters and the return value. It's pretty obvious. Where does it go back to in this case?

We can only guess at the creation of the pattern. The developers must have proceeded from the default INT.


A tick has come, the terminal calls the EA's start() function. You state that the value returned by this function is indifferent to the terminal. Is this documented anywhere?
 
KoKoS:

I want to put "Alert()" in it to tell me when the trend has reversed.

I want to use "Alert()" to tell me when the trend reverses.

Z.U. I'm a little better at mql4 than I am at ballet but...


Lines

#property  indicator_color1  Silver
#property  indicator_color2  Yellow

I think that the first two buffers are the indicator of a trend change. They have red marks on top of candlesticks and blue ones on the bottom. Only the yellow-grey combination works as an indicator of trend reversal. For them it will be accordingly:

//---- indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);// для серого цвета
   SetIndexBuffer(1,ind_buffer2);// для жёлтого цвета
There, in the values of those buffers, dig.
 
Folks, advise on the transfer of date through iCustom. Passes current compiled value, how to pass on the buffer changed at the global level? When I change the date, it still passes the same value.
extern bool   shiftdata           = false;
extern string ShiftHistory        = "02.06.2012 00:00";

Indicator posted just above.....

Or it doesn't change in any way?????

Could you guys tell me about the date transfer via iCustom?

Reason: