//+------------------------------------------------------------------+ //| Perfect Order.mq4 | //| Oluwasina Olukoye | //| forexnewbies.com | //+------------------------------------------------------------------+ #property copyright "Oluwasina Olukoye" #property link "forexnewbies.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 5 input int SlowestPeriod = 200; input int SlowPeriod = 100; input int NormalPeriod = 50; input int FastPeriod = 20; input int FastestPeriod = 10; input ENUM_MA_METHOD MAMethod = MODE_SMA; double BufferSlowest[]; double BufferSlow[]; double BufferNormal[]; double BufferFast[]; double BufferFastest[]; #define SlowestIndicator 0 #define SlowIndicator 1 #define NormalIndicator 2 #define FastIndicator 3 #define FastestIndicator 4 //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexStyle(SlowestIndicator,DRAW_LINE,STYLE_SOLID,1,clrYellow); SetIndexBuffer(SlowestIndicator,BufferSlowest); SetIndexLabel(SlowestIndicator,"SlowestPeriod"); SetIndexStyle(SlowIndicator,DRAW_LINE,STYLE_SOLID,1,clrLimeGreen); SetIndexBuffer(SlowIndicator,BufferSlow); SetIndexLabel(SlowIndicator,"SlowPeriod"); SetIndexStyle(NormalIndicator,DRAW_LINE,STYLE_SOLID,1,clrBlue); SetIndexBuffer(NormalIndicator,BufferNormal); SetIndexLabel(NormalIndicator,"NormalPeriod"); SetIndexStyle(FastIndicator,DRAW_LINE,STYLE_SOLID,1,clrMagenta); SetIndexBuffer(FastIndicator,BufferFast); SetIndexLabel(FastIndicator,"FastPeriod"); SetIndexStyle(FastestIndicator,DRAW_LINE,STYLE_SOLID,1,clrRed); SetIndexBuffer(FastestIndicator,BufferFastest); SetIndexLabel(FastestIndicator,"FastestPeriod"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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 limit; double slowest, slow, normal, fast, fastest; if(rates_total <= SlowestPeriod) return (0); limit = rates_total - prev_calculated; if(prev_calculated > 0) limit++; for(int i=limit-1;i>=0;i--) { slowest = iMA(NULL,0,SlowestPeriod,0,MAMethod,PRICE_CLOSE,i); slow = iMA(NULL,0,SlowPeriod,0,MAMethod,PRICE_CLOSE,i); normal = iMA(NULL,0,NormalPeriod,0,MAMethod,PRICE_CLOSE,i); fast = iMA(NULL,0,FastPeriod,0,MAMethod,PRICE_CLOSE,i); fastest = iMA(NULL,0,FastestPeriod,0,MAMethod,PRICE_CLOSE,i); if(slowest>slow>normal>fast>fastest) { BufferSlowest[i]=slowest; BufferSlow[i]=slow; BufferNormal[i]=normal; BufferFast[i]=fast; BufferFastest[i]=fastest; Comment("Downtrend"); } else if(slowest normal) { Comment("Not in a trend"); } else if(fastest > fast && fast < normal) { Comment("Not in a trend"); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+