//+------------------------------------------------------------------+ //| #dtosc.mq4 | //| mladen | //+------------------------------------------------------------------+ //mod #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_separate_window #property indicator_buffers 3 #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Yellow #property indicator_width1 2 #property indicator_width2 2 #property indicator_level1 30 #property indicator_level2 70 // // // // // extern string TimeFrame = "Current time frame"; extern int PeriodRSI =13; extern int PriceRSI = 5; extern int PeriodStoch= 8; extern int PeriodSK = 5; extern int PeriodSD = 3; // 0 = SMA // 1 - EMA // 2 - SMMA // 3 - LWMA extern int MAMode=1; extern bool showOpenBarY=1; extern string MA_Method_Price = "SMA0 EMA1 SMMA2 LWMA3||0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6"; // // // // // double SK[]; double SD[]; double Sy[]; double StoRSI[]; double RSI[]; string IndicatorFileName; int timeFrame; bool returnBars=false; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { IndicatorBuffers(5); SetIndexBuffer(0,SK); SetIndexBuffer(1,SD); if (showOpenBarY) SetIndexBuffer(2,Sy); SetIndexBuffer(3,StoRSI); SetIndexBuffer(4,RSI); // // // // // if (TimeFrame == "getBarsCount") { returnBars=true; return(0); } timeFrame = stringToTimeFrame(TimeFrame); // // // // // IndicatorShortName("DTOSC ("+PeriodRSI+","+PeriodStoch+","+PeriodSK+","+PeriodSD+")"); IndicatorFileName = WindowExpertName(); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { int i,limit; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit=Bars-counted_bars; // // // // // if (returnBars) { SK[0] = limit; return(0); } if (timeFrame != Period()) { limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,IndicatorFileName,"getBarsCount",0,0)*timeFrame/Period())); // // // // // for(i=0; i<limit; i++) { int y = iBarShift(NULL,timeFrame,Time[i]); SK[i] = iCustom(NULL,timeFrame,IndicatorFileName,"",PeriodRSI,PriceRSI,PeriodStoch,PeriodSK,PeriodSD,MAMode,showOpenBarY,0,y); SD[i] = iCustom(NULL,timeFrame,IndicatorFileName,"",PeriodRSI,PriceRSI,PeriodStoch,PeriodSK,PeriodSD,MAMode,showOpenBarY,1,y); Sy[i] = EMPTY_VALUE; if(iBarShift(NULL,timeFrame,Time[i])==0) Sy[i] = SK[i]; } return(0); } // // // // // for(i=limit; i>=0; i--) { RSI[i] = iRSI(NULL,0,PeriodRSI,PRICE_CLOSE,i); double LLV = RSI[ArrayMinimum(RSI,PeriodStoch,i)]; double HHV = RSI[ArrayMaximum(RSI,PeriodStoch,i)]; if ((HHV-LLV)!=0) StoRSI[i] = 100.0*((RSI[i] - LLV)/(HHV - LLV)); else StoRSI[i] = 0; } for(i=limit; i>=0; i--) SK[i]=iMAOnArray(StoRSI,0,PeriodSK,0,MAMode,i); for(i=limit; i>=0; i--){ SD[i]=iMAOnArray( SK,0,PeriodSD,0,MAMode,i); Sy[i] = EMPTY_VALUE; if(i<=1) Sy[i]=SK[i]; } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int stringToTimeFrame(string tfs) { for(int l = StringLen(tfs)-1; l >= 0; l--) { int char = StringGetChar(tfs,l); if((char > 96 && char < 123) || (char > 223 && char < 256)) tfs = StringSetChar(tfs, l, char - 32); else if(char > -33 && char < 0) tfs = StringSetChar(tfs, l, char + 224); } // // // // // int tf=0; if (tfs=="M1" || tfs=="1") tf=PERIOD_M1; if (tfs=="M5" || tfs=="5") tf=PERIOD_M5; if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15; if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30; if (tfs=="H1" || tfs=="60") tf=PERIOD_H1; if (tfs=="H4" || tfs=="240") tf=PERIOD_H4; if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1; if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1; if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1; if (tf<Period()) tf=Period(); return(tf); }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Relative strength index
Moving average indicator
Custom Indicators Used:
IndicatorFileName
Order Management characteristics:
Other Features: