//+------------------------------------------------------------------+ //| Supertrend.mq4 | //| Copyright © 2005, Jason Robinson (jnrtrading). | //| http://www.jnrtrading.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Jason Robinson (jnrtrading)." #property link "http://www.jnrtrading.co.uk" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Yellow int st = 0; int CCIPeriod=50; double Trend[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, Trend); SetIndexDrawBegin(0,CCIPeriod); return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i; double cciTrendNow, cciTrendPrevious, var; int counted_bars = IndicatorCounted(); limit=Bars-counted_bars-1; if(counted_bars ==0) limit=Bars-CCIPeriod-1; for(i = limit; i >= 0; i--) { cciTrendNow = iCCI(NULL, 0, CCIPeriod, PRICE_TYPICAL, i); Trend[i]=Trend[i+1]; if (cciTrendNow > st) { Trend[i]=Low[i] - iATR(NULL, 0, 5, i); if (Trend[i] < Trend[i+1]) { Trend[i]=Trend[i+1]; } } else if (cciTrendNow < st) { Trend[i]=High[i] + iATR(NULL, 0, 5, i); if (Trend[i] > Trend[i+1]) { Trend[i]=Trend[i+1]; } } } //---- //---- return(0); } //+------------------------------------------------------------------+