작업 종료됨
명시
I've been working on other things but over the past month been back and forward with this.
I need to store fractals in an array to compare them.
Recent fractal lower than last fractal and last fractal higher than third last fractal. Plot a buffer on the middle fractal.
The same for low fractals.
(image included).
So the dots are fractals that plot fine if a fractal has a higher/lower pair of fractals either side plot another buffer on it.
The fractal indicator i have works fine i just want to add this extra feature to make it clearer when trend changes direction.
So store last three fractal values and compare them. I don't want to use Ifractals as that limits me to only 2 bars either side of the fractal.
Code is below:
#property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Yellow //---- input parameters //---- buffers double ExtUpFractalsBuffer[]; double ExtDownFractalsBuffer[]; double TOP[]; double UP_ARRAY[3]; double DOWN_ARRAY[3]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicator buffers mapping SetIndexBuffer(0,ExtUpFractalsBuffer); SetIndexBuffer(1,ExtDownFractalsBuffer); SetIndexBuffer(2,TOP); //---- drawing settings SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,119); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,119); SetIndexStyle(2, DRAW_ARROW,0,4); SetIndexArrow(2,119); //---- SetIndexEmptyValue(0,0.0); SetIndexEmptyValue(1,0.0); SetIndexEmptyValue(2,0.0); //---- name for DataWindow SetIndexLabel(0,"Fractal Up"); SetIndexLabel(1,"Fractal Down"); SetIndexLabel(2, "TOP"); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,nCountedBars; bool bFound; double dCurrent; nCountedBars=IndicatorCounted(); //---- last counted bar will be recounted if(nCountedBars<=2) i=Bars-nCountedBars-3; if(nCountedBars>2) { nCountedBars--; i=Bars-nCountedBars-1; } //----Up and Down Fractals while(i>=2) { //----Fractals up bFound=false; dCurrent=Close[i]; if(dCurrent>Close[i+1] && dCurrent>Close[i-1]) { bFound=true; ExtUpFractalsBuffer[i]=dCurrent; int TotalUp =3; for(int j=TotalUp-1;j>=0;j--) { if(ExtUpFractalsBuffer[i]!=0) { UP_ARRAY[j]=dCurrent; UP_ARRAY[j]=UP_ARRAY[j-1]; } } if(UP_ARRAY[0]<UP_ARRAY[1] && UP_ARRAY[1]>UP_ARRAY[2]) { TOP[i]=dCurrent; } } //----Fractals down bFound=false; dCurrent=Close[i]; if(dCurrent<Close[i+1] && dCurrent<Close[i-1] ) { bFound=true; ExtDownFractalsBuffer[i]=dCurrent; } i--; } //---------------- //---------------- return(0); }
The yellow is the array and plotting buffer part I've had a shot at but no luck.
If you could make it run and perhaps a brief summary of these sections and how you got it to work so i can learn from it.
Thank you in advance.
Torexvir