Thank you.
what I have proven so:
zigzag1 = CopyBuffer (Zig_Handle, 1,0,1, zig1buf);
zigzag2 = CopyBuffer (Zig_Handle, 2,0,1, zig2buf);
but only get the value: (1.0).
not be where out this value, but I need the price.
If I have not corrected it well, I can escrivir well the piece of code?
thanks and regards.
Please use the SRC button when you post code.
DragonMQL:
What are the values of zig1buf[0] and zig2buf[0] ?
Thank you.
what I have proven so:
zigzag1 = CopyBuffer (Zig_Handle, 1,0,1, zig1buf);
zigzag2 = CopyBuffer (Zig_Handle, 2,0,1, zig2buf);
but only get the value: (1.0).
not be where out this value, but I need the price.
If I have not corrected it well, I can escrivir well the piece of code?
thanks and regards.
OK, did not know.
I am sorry.
first of all, I apologise if not understood me very well, the reason is that I use a translator from Spanish to English and sometimes does not translate correctly.
I'm new in MQL5 code.
not be how in MQL5 language to obtain the value in price of the indicator zigzag?
the code of the indicator zigzag is normal:
what I have is the following:
//+------------------------------------------------------------------+ //| ZigZag.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 1 //---- plot Zigzag #property indicator_label1 "Zigzag" #property indicator_type1 DRAW_SECTION #property indicator_color1 Red #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int ExtDepth=12; input int ExtDeviation=5; input int ExtBackstep=3; //--- indicator buffers double ZigzagBuffer[]; // main buffer double HighMapBuffer[]; // highs double LowMapBuffer[]; // lows int level=3; // recounting depth double deviation; // deviation in points //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ZigzagBuffer,INDICATOR_DATA); SetIndexBuffer(1,HighMapBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(2,LowMapBuffer,INDICATOR_CALCULATIONS); //--- set short name and digits PlotIndexSetString(0,PLOT_LABEL,"ZigZag("+(string)ExtDepth+","+(string)ExtDeviation+","+(string)ExtBackstep+")"); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- set empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //--- to use in cycle deviation=ExtDeviation*_Point; //--- return(0); } //+------------------------------------------------------------------+ //| searching index of the highest bar | //+------------------------------------------------------------------+ int iHighest(const double &array[], int depth, int startPos) { int index=startPos; //--- start index validation if(startPos<0) { Print("Invalid parameter in the function iHighest, startPos =",startPos); return 0; } int size=ArraySize(array); //--- depth correction if need if(startPos-depth<0) depth=startPos; double max=array[startPos]; //--- start searching for(int i=startPos;i>startPos-depth;i--) { if(array[i]>max) { index=i; max=array[i]; } } //--- return index of the highest bar return(index); } //+------------------------------------------------------------------+ //| searching index of the lowest bar | //+------------------------------------------------------------------+ int iLowest(const double &array[], int depth, int startPos) { int index=startPos; //--- start index validation if(startPos<0) { Print("Invalid parameter in the function iLowest, startPos =",startPos); return 0; } int size=ArraySize(array); //--- depth correction if need if(startPos-depth<0) depth=startPos; double min=array[startPos]; //--- start searching for(int i=startPos;i>startPos-depth;i--) { if(array[i]<min) { index=i; min=array[i]; } } //--- return index of the lowest bar return(index); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { int i=0; int limit=0,counterZ=0,whatlookfor=0; int shift=0,back=0,lasthighpos=0,lastlowpos=0; double val=0,res=0; double curlow=0,curhigh=0,lasthigh=0,lastlow=0; //--- auxiliary enumeration enum looling_for { Pike=1, // searching for next high Sill=-1 // searching for next low }; //--- initializing if(prev_calculated==0) { ArrayInitialize(ZigzagBuffer,0.0); ArrayInitialize(HighMapBuffer,0.0); ArrayInitialize(LowMapBuffer,0.0); } //--- if(rates_total<100) return(0); //--- set start position for calculations if(prev_calculated==0) limit=ExtDepth; //--- ZigZag was already counted before if(prev_calculated>0) { i=rates_total-1; //--- searching third extremum from the last uncompleted bar while(counterZ<level && i>rates_total-100) { res=ZigzagBuffer[i]; if(res!=0) counterZ++; i--; } i++; limit=i; //--- what type of exremum we are going to find if(LowMapBuffer[i]!=0) { curlow=LowMapBuffer[i]; whatlookfor=Pike; } else { curhigh=HighMapBuffer[i]; whatlookfor=Sill; } //--- chipping for(i=limit+1;i<rates_total && !IsStopped();i++) { ZigzagBuffer[i]=0.0; LowMapBuffer[i]=0.0; HighMapBuffer[i]=0.0; } } //--- searching High and Low for(shift=limit;shift<rates_total && !IsStopped();shift++) { val=low[iLowest(low,ExtDepth,shift)]; if(val==lastlow) val=0.0; else { lastlow=val; if((low[shift]-val)>deviation) val=0.0; else { for(back=1;back<=ExtBackstep;back++) { res=LowMapBuffer[shift-back]; if((res!=0) && (res>val)) LowMapBuffer[shift-back]=0.0; } } } if(low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0; //--- high val=high[iHighest(high,ExtDepth,shift)]; if(val==lasthigh) val=0.0; else { lasthigh=val; if((val-high[shift])>deviation) val=0.0; else { for(back=1;back<=ExtBackstep;back++) { res=HighMapBuffer[shift-back]; if((res!=0) && (res<val)) HighMapBuffer[shift-back]=0.0; } } } if(high[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0; } //--- last preparation if(whatlookfor==0)// uncertain quantity { lastlow=0; lasthigh=0; } else { lastlow=curlow; lasthigh=curhigh; } //--- final rejection for(shift=limit;shift<rates_total && !IsStopped();shift++) { res=0.0; switch(whatlookfor) { case 0: // search for peak or lawn if(lastlow==0 && lasthigh==0) { if(HighMapBuffer[shift]!=0) { lasthigh=high[shift]; lasthighpos=shift; whatlookfor=Sill; ZigzagBuffer[shift]=lasthigh; res=1; } if(LowMapBuffer[shift]!=0) { lastlow=low[shift]; lastlowpos=shift; whatlookfor=Pike; ZigzagBuffer[shift]=lastlow; res=1; } } break; case Pike: // search for peak if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0) { ZigzagBuffer[lastlowpos]=0.0; lastlowpos=shift; lastlow=LowMapBuffer[shift]; ZigzagBuffer[shift]=lastlow; res=1; } if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0) { lasthigh=HighMapBuffer[shift]; lasthighpos=shift; ZigzagBuffer[shift]=lasthigh; whatlookfor=Sill; res=1; } break; case Sill: // search for lawn if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0) { ZigzagBuffer[lasthighpos]=0.0; lasthighpos=shift; lasthigh=HighMapBuffer[shift]; ZigzagBuffer[shift]=lasthigh; } if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0) { lastlow=LowMapBuffer[shift]; lastlowpos=shift; ZigzagBuffer[shift]=lastlow; whatlookfor=Pike; } break; default: return(rates_total); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
the code of the expert that I want to write and in which not is how to get the price of the zigzag indicator is:
Someone can correct or explain my mistake?
Thank you.
//+------------------------------------------------------------------+ //| Andro_prueba.mq5 | //| Juan Font | //| jofomax@yahoo.es | //+------------------------------------------------------------------+ #property copyright "Juan Font" #property link "jofomax@yahoo.es" //---- input parameters generales ----- int zigzag; double zigzag1; double zigzag2; double mos =0; double zi1=0; double zi2=0; double psss =0; int Zig_Handle; double HighMapBuffer[]; // highs double LowMapBuffer[]; // lows int OnInit() //int OnStart() ******************************************************** { //------------ Handle del indicador zigzag ------------------------------------ Zig_Handle =iCustom(NULL, 0, "ZigZag",12,5,3); Print(" Valor del indicador Zig_Handle : ", Zig_Handle ); return(0); } // fin int OnInit() ************************************************************ void OnTick() //********* inicio actua en cada tick ******************************** { ArraySetAsSeries(HighMapBuffer,true); ArraySetAsSeries(LowMapBuffer,true); zigzag1 = CopyBuffer( Zig_Handle,1,0,1,HighMapBuffer); zigzag2 = CopyBuffer( Zig_Handle,2,0,1,LowMapBuffer); if(zigzag1 != zi1){ zi1=zigzag1; Print(" ** Valor del zigzag1 : ",zigzag1); } if(zigzag2 != zi2){ zi2=zigzag2; Print(" ** Valor del zigzag2 : ",zigzag2); } } // fin void OnTick() //+------------------------------------------------------------------+
DragonMQL:
first of all, I apologise if not understood me very well, the reason is that I use a translator from Spanish to English and sometimes does not translate correctly.
I'm new in MQL5 code.
not be how in MQL5 language to obtain the value in price of the indicator zigzag?
the code of the indicator zigzag is normal:
what I have is the following:
the code of the expert that I want to write and in which not is how to get the price of the zigzag indicator is:
Someone can correct or explain my mistake?
Thank you.
I already tried to explain that the value you are expecting are in the arrays passed as parameter, not in the value returned by CopyBuffer. Read the documentation :
Return Value
Returns the copied data count or -1 in case of an error.
So the values you are searching are in HighMapBuffer[0] and LowMapBuffer[0], not in zigzag1 or zigzag2.
OK, thanks, finally it got.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
what I want is that zigzag1 and zigzag2 returned me the value as price.
example : (1.29130)
a greeting.