//+------------------------------------------------------------------+ //| Parabolic_SW.mq4 | //| Copyright © 2008, syanwar (admin@viking234.biz) | //| http://www.viking234.com/ | //| Modified from MetaQuotes Custom Parabolic Indicator | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, syanwar (admin@viking234.biz)" #property link "http://www.viking234.com/" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red //---- input parameters extern string SARset="<< SAR Input >>"; extern double Step=0.01; extern double Maximum=0.1; extern string MACDset="<< MACD Input >>"; extern int FastEMA=5; extern int SlowEMA=8; extern int SignalSMA=9; //---- buffers double SarBuffer[]; //---- int save_lastreverse; bool save_dirlong; double save_start; double save_last_high; double save_last_low; double save_ep; double save_sar; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,159); SetIndexBuffer(0,SarBuffer); //---- return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SaveLastReverse(int last,int dir,double start,double low,double high,double ep,double sar) { save_lastreverse=last; save_dirlong=dir; save_start=start; save_last_low=low; save_last_high=high; save_ep=ep; save_sar=sar; } //+------------------------------------------------------------------+ //| Parabolic Sell And Reverse system | //+------------------------------------------------------------------+ int start() { static bool first=true; bool dirlong; double start,last_high,last_low; double ep,sar,price_low,price_high,price; int i,counted_bars=IndicatorCounted(); //---- if(Bars<3) return(0); //---- initial settings i=Bars-2; if(counted_bars==0 || first) { first=false; dirlong=true; start=Step; last_high=-10000000.0; last_low=10000000.0; while(i>0) { save_lastreverse=i; price_low= iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i); // price_low=Low[i]; if(last_low>price_low) last_low=price_low; // price_high=High[i]; price_high= iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i); if(last_highiMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i+1) && price_low>iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i+1)) break; if(price_high=0) { price_low=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i); price_high=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i); //--- check for reverse if(dirlong && price_lowSarBuffer[i+1]) { SaveLastReverse(i,false,start,last_low,price_high,ep,sar); start=Step; dirlong=true; ep=price_high; last_high=price_high; SarBuffer[i]=last_low; i--; continue; } //--- price=SarBuffer[i+1]; sar=price+start*(ep-price); if(dirlong) { if(epprice) sar=price; price=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i+1); if(sar>price) sar=price; if(sar>price_low) { SaveLastReverse(i,true,start,price_low,last_high,ep,sar); start=Step; dirlong=false; ep=price_low; last_low=price_low; SarBuffer[i]=last_high; i--; continue; } if(epprice_low && (start+Step)<=Maximum) start+=Step; if(price_lowprice_low) { last_low=price_low; ep=price_low; } } SarBuffer[i]=sar; i--; } // sar=SarBuffer[0]; // price=iSAR(NULL,0,Step,Maximum,0); // if(sar!=price) Print("custom=",sar," SAR=",price," counted=",counted_bars); // if(sar==price) Print("custom=",sar," SAR=",price," counted=",counted_bars); //---- return(0); } //+------------------------------------------------------------------+