Function define to return several value in one dimention array

Publish your article and thousands of people all over the world will read it!
4480
2013.09.22 18:04

hi,

i want to define a function such that : return several value in one dimention array for each ------

i wrote this:

```.
.
int LastPeak_bar[20]=0;
.
.
//+------------------------------------------------------------------+
void OnInit()
{
.
.
}
//+------------------------------------------------------------------+
int OnCalculate(...)
{
.
.
for(int i )
{
LastPeak_bar[i]=GetIndicatorLastPeak(count_bar_above,bar)  [i]; <===  some thing like that
}
.
.
.
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
int GetIndicatorLastPeak(int count_bar,int bar) [i]   <===
{
for(int i=0;i<20; i++)  int LastPeak[i]=0;
if(count_bar<6) return(0);

for(int j=bar+3; j<=count_bar-2; j++)
{
k=1;
if(...)
{
LastPeak[k]=j;
}
k++;
}
return(LastPeak[k]);
}
```

how can do that ?

thank you.
4480
2013.09.22 22:15

can use array in function?

```int GetIndicatorLastPeak(int count_bar,int barLastPeak[])
{
for(int i=0;i<20; i++)  int LastPeak[i]=0;
if(count_bar<6) return(0);

for(int j=bar+3; j<=count_bar-2; j++)
{
k=1;
if(...)
{
LastPeak[k]=j;
}
k++;
}
return(LastPeak[k]);
}
```
4684
2013.09.22 22:23
TIMisthebest:

can use array in function?

Yes you can, but you must put it by reference:

`int GetIndicatorLastPeak(int count_bar,int &barLastPeak[])`
4480
2013.09.22 22:36
Candles:

Yes you can, but you must put it by reference:

thank you,

and is this store the calculation ( more than one for exit ) in LastPeak[i] ?

```int GetIndicatorLastPeak(int count_bar,int &LastPeak[])
{
for(int i=0;i<20; i++)  int LastPeak[i]=0;
if(count_bar<6) return(0);

for(int j=bar+3; j<=count_bar-2; j++)
{
k=1;
if(...)
{
LastPeak[k]=j;
}
k++;
}
return(LastPeak[k]);
}```
4480
2013.09.22 22:53

must complete search about :

function, array , argument, parameter of function,

function send one for exit & function send several to exit

all this in c++

---------------------------------

any help in this field by fix the first comment

4480
2013.09.23 07:15

may be i must to use: class

any help please ?

4480
2013.09.23 20:36

i wrote this to assign divergance on ao according to :

https://www.mql5.com/en/docs/standardlibrary/expertclasses/csignal/signal_ao

·         Divergence — the first analyzed bottom of the indicator is shallower than the previous one, and the corresponding price valley is deeper than the previous one. In addition, the indicator must not rise above the zero level.

then i have this :

but the 2 line showed is missed because of above problem. how can do it ? any help please ?

here it is:    ( because of characters limitasion in next comment ).

Documentation on MQL5: Standard Library / Trading Strategy Classes / Modules of Trade Signals / Signals of the Indicator Awesome Oscillator
• www.mql5.com
Standard Library / Trading Strategy Classes / Modules of Trade Signals / Signals of the Indicator Awesome Oscillator - Documentation on MQL5
4480
2013.09.23 20:36

i wrote this to assign divergance on ao according to :

https://www.mql5.com/en/docs/standardlibrary/expertclasses/csignal/signal_ao

·         Divergence — the first analyzed bottom of the indicator is shallower than the previous one, and the corresponding price valley is deeper than the previous one. In addition, the indicator must not rise above the zero level.

then i have this :

but the 2 line showed is missed because of above problem. how can do it ? any help please ?

here it is:    ( because of characters limitasion in next comment ).

here it is

```.
.
int TOTAL_BAR;
int count_bar_above=0;
int count_bar_down=0;
int LastTrough_bar=0;
int LastPeak_bar=0;
.
.
//+------------------------------------------------------------------+
void OnInit()
{
.
}
//+------------------------------------------------------------------+
int OnCalculate(...)
{
.
TOTAL_BAR=rates_total;
.
.
.
for(int bar=rates_total-10; bar>=0; bar--)
{
Indicator_count_bar_above(bar);
if(Indicator_count_bar_above(bar)!=0)
{
IsIndicatorPeak(count_bar_above,bar);
GetIndicatorLastPeak(count_bar_above,bar);
LastPeak_bar=GetIndicatorLastPeak(count_bar_above,bar);
}
if(IsIndicatorPeak(count_bar_above,bar)==true&&GetIndicatorLastPeak(count_bar_above,bar)>=3 )
{
DrawIndicatorTrendLine(bar,Time[bar],Time[GetIndicatorLastPeak(count_bar_above,bar)],
Ext_AO_Buffer[bar],Ext_AO_Buffer[GetIndicatorLastPeak(count_bar_above,bar)],Red,STYLE_SOLID);
}

Indicator_count_bar_down(bar);
if(Indicator_count_bar_down(bar)!=0)
{
IsIndicatorTrough(count_bar_down,bar);
GetIndicatorLastTrough(count_bar_down,bar);
LastTrough_bar=GetIndicatorLastTrough(count_bar_down,bar);
}
if(IsIndicatorTrough(count_bar_down,bar)==true&&GetIndicatorLastTrough(count_bar_down,bar)>=3 )
{
DrawIndicatorTrendLine(bar,Time[bar],Time[GetIndicatorLastTrough(count_bar_down,bar)],
Ext_AO_Buffer[bar],Ext_AO_Buffer[GetIndicatorLastTrough(count_bar_down,bar)],Blue,STYLE_SOLID);
}

}
.
//--- done
return(rates_total);
}
//----------------------------------------------------------------------------------------------------------//
void OnDeinit(const int reason)
{
.
for(int j=1;j<=TOTAL_BAR;j++)
{
if(ObjectFind(0,"AO_Divergence"+IntegerToString(j))>=0) ObjectDelete(0,"AO_Divergence"+IntegerToString(j));
}

ChartRedraw();
ChartSetInteger(0,CHART_FOREGROUND,foreground);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Check domain_above Awesome_Oscillator bar                        |
//+------------------------------------------------------------------+
int Indicator_count_bar_above(int bar)
{
count_bar_above=0;
for(int j=bar; j<TOTAL_BAR-10; j++)
{
if(Ext_AO_Buffer[j]>=0.0)
{
if(Ext_AO_Buffer[j]>=0.0&&Ext_AO_Buffer[j+1]<=0.0)
{
count_bar_above=j+1;
break;
}
}
else break;
}
return(count_bar_above);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Check domain_down Awesome_Oscillator bar                         |
//+------------------------------------------------------------------+
int Indicator_count_bar_down(int bar)
{
count_bar_down=0;
for(int j=bar; j<TOTAL_BAR-10; j++)
{
if(Ext_AO_Buffer[j]<=0.0)
{
if(Ext_AO_Buffer[j]<=0.0&&Ext_AO_Buffer[j+1]>=0.0)
{
count_bar_down=j+1;
break;
}
}
else break;
}
return(count_bar_down);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Get Awesome_Oscillator last Peak                                 |
//+------------------------------------------------------------------+
int GetIndicatorLastPeak(int count_bar,int bar)
{
int LastPeak=0;
if(count_bar<6) return(LastPeak);
for(int j=bar+3; j<=count_bar-2; j++)
{
if(Ext_AO_Buffer[j]>=Ext_AO_Buffer[j+1]&& Ext_AO_Buffer[j]>Ext_AO_Buffer[j+2]&&
Ext_AO_Buffer[j]>=Ext_AO_Buffer[j-1]&& Ext_AO_Buffer[j]>Ext_AO_Buffer[j-2])
{
LastPeak=j;
break;
}
}
return(LastPeak);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Get Awesome_Oscillator last Trough                               |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int count_bar,int bar)
{
int LastTrough=0;
if(count_bar<6) return(LastTrough);
for(int j=bar+3; j<=count_bar-2; j++)
{
if(Ext_AO_Buffer[j]<=Ext_AO_Buffer[j+1]&& Ext_AO_Buffer[j]<Ext_AO_Buffer[j+2]&&
Ext_AO_Buffer[j]<=Ext_AO_Buffer[j-1]&& Ext_AO_Buffer[j]<Ext_AO_Buffer[j-2])
{
LastTrough=j;
break;
}
}
return(LastTrough);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Is Awesome_Oscillator Peak                                       |
//+------------------------------------------------------------------+
bool IsIndicatorPeak(int Peak, int bar)
{
if(Peak<4) return(false);
if(Ext_AO_Buffer[bar]>=Ext_AO_Buffer[bar+1]&& Ext_AO_Buffer[bar]>Ext_AO_Buffer[bar+2]&&
Ext_AO_Buffer[bar]>Ext_AO_Buffer[bar-1])  return(true);
return(false);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Is Awesome_Oscillator Trough                                     |
//+------------------------------------------------------------------+
bool IsIndicatorTrough(int Trough, int bar)
{
if(Trough<4) return(false);
if(Ext_AO_Buffer[bar]<=Ext_AO_Buffer[bar+1]&& Ext_AO_Buffer[bar]<Ext_AO_Buffer[bar+2]&&
Ext_AO_Buffer[bar]<Ext_AO_Buffer[bar-1])  return(true);
return(false);
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Function for drawing a trend line in the indicator window        |
//+------------------------------------------------------------------+
void DrawIndicatorTrendLine(int bar,datetime x1,datetime x2,double y1,
double y2,color lineColor,int style)
{
int indicatorWindow=ChartWindowFind(0,short_name);
if(indicatorWindow<0) return;
string label="AO_Divergence"+IntegerToString(bar);

if(ObjectFind(0,label)==-1)
{
ObjectCreate(0,label,OBJ_TREND,indicatorWindow,x1,y1,x2,y2);
ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
ObjectSetInteger(0,label,OBJPROP_STYLE,style);
ObjectSetInteger(0,label,OBJPROP_WIDTH,2);
ObjectSetInteger(0,label,OBJPROP_RAY,0);
ObjectSetInteger(0,label,OBJPROP_BACK,false);
}
else
{
ObjectMove(0,label,0,x1,y1);
ObjectMove(0,label,1,x2,y2);
}
}
//----------------------------------------------------------------------------------------------------------//
//+------------------------------------------------------------------+
//| Function for drawing a trend line in a price chart window        |
//+------------------------------------------------------------------+
void DrawPriceTrendLine(datetime x1,datetime x2,double y1,
double y2,color lineColor,int style)
{
string label="AO_DivergenceLine.0# "+DoubleToString(x1,0);

if(ObjectFind(0,label)==-1)
{
ObjectCreate(0,label,OBJ_TREND,0,x1,y1,x2,y2);
ObjectSetInteger(0,label,OBJPROP_COLOR,lineColor);
ObjectSetInteger(0,label,OBJPROP_STYLE,style);
ObjectSetInteger(0,label,OBJPROP_WIDTH,0);
ObjectSetInteger(0,label,OBJPROP_RAY,0);
ObjectSetInteger(0,label,OBJPROP_BACK,true);
}
else
{
ObjectMove(0,label,0,x1,y1);
ObjectMove(0,label,1,x2,y2);
}
}
//----------------------------------------------------------------------------------------------------------//
```

1

Documentation on MQL5: Standard Library / Trading Strategy Classes / Modules of Trade Signals / Signals of the Indicator Awesome Oscillator
• www.mql5.com
Standard Library / Trading Strategy Classes / Modules of Trade Signals / Signals of the Indicator Awesome Oscillator - Documentation on MQL5
4480
2013.09.25 18:36

problem solved.

```//+------------------------------------------------------------------+
int GetIndicatorALL_LastPeak_bar(int count_bar,int bar)
{
for(int i=0;i<200; i++)   ALL_LastPeak_bar[i]=0;
ALL_LastPeak_bar[0]=bar;
int ii=1;
for(int j=bar+3; j<=count_bar-2; j++)
{
ALL_LastPeak_bar[ii]=GetIndicatorLastPeak(count_bar,ALL_LastPeak_bar[ii-1]);
if(ii>1&&ALL_LastPeak_bar[ii]==0&&ALL_LastPeak_bar[ii-1]>=0) break;
ii++;
}
return(0);
}
//+------------------------------------------------------------------+```
Moderator
30721
2013.09.25 19:04
TIMisthebest:

problem solved.

Congratulations.
4480
2013.09.25 19:06
angevoyageur:
Congratulations.
thank you.
12