MACD SR
Nobody?
Daniel Cioca:
Hi guys,
trying to make an indicator to plot sr lines on main chart on macd crossover...like My MACD S/R from tradingview...
I have this code, it compiles, but is not what I want...:)... I can see a spike on that chart line at macd crossover but the line comes back again to same level...
a litle push please :
Post a code that can be compiled and checked
#property strict //--- indicator settings #property indicator_chart_window #property indicator_buffers 3 //--- indicator parameters input int InpFastEMA=12; // Fast EMA Period input int InpSlowEMA=26; // Slow EMA Period input int InpSignalSMA=9; // Signal SMA Period input int InpLoockback = 10; input double InpOffSet =0.5 ; //--- indicator buffers double ExtMacdBuffer[]; double ExtSignalBuffer[]; double UpperLine[],LowerLine[],MeanLine[]; //--- right input parameters flag bool ExtParameters=false; int OnInit(void) { // IndicatorDigits(Digits+1); SetIndexBuffer(0,UpperLine); SetIndexStyle(0,DRAW_LINE,0,1,clrYellow); SetIndexLabel(0,"Upper"); ArraySetAsSeries(UpperLine,true); SetIndexBuffer(1,MeanLine); SetIndexStyle(1,DRAW_LINE,2,1,clrAliceBlue); SetIndexLabel(1,"Mean"); ArraySetAsSeries(UpperLine,true); SetIndexBuffer(2,LowerLine); SetIndexStyle(2,DRAW_LINE,0,1,clrYellow); SetIndexLabel(2,"Lower"); ArraySetAsSeries(UpperLine,true); IndicatorShortName("MACDSR"); 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,upperline=0,lowerline=0; bool crossup =false; bool crossdwn=false; //--- int limit = rates_total-prev_calculated; if (prev_calculated>0) limit++; for ( i=limit-1; i>=0; i--){ double macd = MACD(i); double macdsid = MACDsig(i); if(MACD(i+1)>MACDsig(i+1) && MACD(i) < MACDsig(i)) (crossup =true); if(MACD(i+1)<MACDsig(i+1) && MACD(i) > MACDsig(i)) (crossdwn =true); if(crossup == true) { upperline = iLowest(_Symbol,_Period,MODE_LOW,InpLoockback,GetShift(0,i)); UpperLine[i]=iLow(_Symbol,_Period,upperline); } if(crossdwn == true) { lowerline=iHighest(_Symbol,_Period,MODE_HIGH,InpLoockback,GetShift(1,i)); LowerLine[i]=iHigh(_Symbol,_Period,lowerline); } MeanLine[i]= (UpperLine[i] + LowerLine[i])*0.5; PrintFormat("UpperLine %g, LowerLine %g, MeanLine%g macd %g , macdsig %g ",UpperLine[i],LowerLine[i],MeanLine[i],macd,macdsid); Print(GetShift(1,i)); Print(GetShift(0,i)); } return(rates_total); } //+------------------------------------------------------------------+ double MACD (int shift) { return( iMACD(_Symbol,_Period,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,shift ));} double MACDsig (int shift) { return( iMACD(_Symbol,_Period,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_SIGNAL,shift));} int GetShift(int up,int i){ double s1,s2,s3,s4; // int i; int k=iBars(NULL, 0), ke=0, ks=0; // for(i=0; i<k; i++){ s1=MACD(i); s2= MACDsig(i);s3= MACD(i+1); s4=MACDsig(i+1); if( s4>s3 && s1>s2) { ke++ ; if( up==0)return(i);}// crossdown if( s4<s3 && s1<s2) { ke++ ; if( up==1)return(i);}//crossup // } return(-1); }
Is for mt5
Any ideeas?
Hi guys,
trying to make an indicator to plot sr lines on main chart on macd crossover...like My MACD S/R from tradingview...
I have this code, it compiles, but is not what I want...:)... I can see a spike on that chart line at macd crossover but the line comes back again to same level...
a litle push please :