can use array in function?
Yes you can, but you must put it by reference:
int GetIndicatorLastPeak(int count_bar,int &barLastPeak[])
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]); }
may be i must to use: class
any help please ?
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 Documentation on MQL5: Standard Library / Trading Strategy Classes / Modules of Trade Signals / Signals of the Indicator Awesome Oscillator](/i/community/logo_mql5_small.png)
- www.mql5.com
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 Documentation on MQL5: Standard Library / Trading Strategy Classes / Modules of Trade Signals / Signals of the Indicator Awesome Oscillator](/i/community/logo_mql5_small.png)
- www.mql5.com
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); } //+------------------------------------------------------------------+
![](https://c.mql5.com/3/11/Jumping_Jack_Green_Smiley__30.gif)
problem solved.
Congratulations.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi,
i want to define a function such that : return several value in one dimention array for each ------
i wrote this:
how can do that ?
can you please help ?
thank you.