//+------------------------------------------------------------------+ //| Price Oscillator.mq4 | //| Copyright © 2007, Serega Lykov | //| http://mtexperts.narod.ru/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, Serega Lykov" #property link "http://mtexperts.narod.ru/" //---- property of indicator ----------------------------------------+ #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 White //---- external parameters ------------------------------------------+ extern string _____Fast_MA__________; extern int Period_fast_ma = 12; // the period of fast ma extern int Method_fast_ma = 0; // the method of fast ma: 0-Simple, 1-Exponential, // 2-Smoothed, 3-Weighted extern int Price_fast_ma = 0; // the price for fast ma: 0-Close, 1-Open, 2-High, 3-Low, // 4-Median, 5-Typical, 6-Weighted extern int Shift_fast_ma = 0; // the shift for fast ma extern string _____Slow_MA__________; extern int Period_slow_ma = 26; // the period of slow ma extern int Method_slow_ma = 0; // the method of slow ma: 0-Simple, 1-Exponential, // 2-Smoothed, 3-Weighted extern int Price_slow_ma = 0; // the price for slow ma: 0-Close, 1-Open, 2-High, 3-Low, // 4-Median, 5-Typical, 6-Weighted extern int Shift_slow_ma = 0; // the shift for slow ma //---- buffers ------------------------------------------------------+ static double IndBuffer[]; //---- global variables ---------------------------------------------+ static double point; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- set a "short" name of the indicator switch(Method_fast_ma) { case 1: string fast_ma = "EMA("; break; case 2: fast_ma = "SMMA("; break; case 3: fast_ma = "LWMA("; break; default: fast_ma = "SMA("; Method_fast_ma = 0; } switch(Method_slow_ma) { case 1: string slow_ma = "EMA("; break; case 2: slow_ma = "SMMA("; break; case 3: slow_ma = "LWMA("; break; default: slow_ma = "SMA("; Method_slow_ma = 0; } IndicatorShortName("Price Oscillator " + fast_ma + Period_fast_ma + ")," + slow_ma + Period_slow_ma + ")"); //---- set a accuracy of values of the indicator IndicatorDigits(0); //---- set a style for lines of the indicator SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2); //---- set a arrays for lines of the indicator SetIndexBuffer(0,IndBuffer); //---- set a first bar for drawing the lines of the indicator SetIndexDrawBegin(0,MathMax(Period_fast_ma,Period_slow_ma)); //---- set a names for lines of the indicator SetIndexLabel(0,"Price Oscillator"); //---- initialization values of constants point = Point; //---- finish of initialization return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { // amount not changed after last call of the indicator of bars int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); // last counted bar will be recounted if(counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; // calculate lines of channel for (int i=limit; i>=0; i--) IndBuffer[i] = NormalizeDouble((iMA(NULL,0,Period_fast_ma,Shift_fast_ma,Method_fast_ma,Price_fast_ma,i)-iMA(NULL,0,Period_slow_ma,Shift_slow_ma,Method_slow_ma,Price_slow_ma,i))/point,0); // finish of iteration return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Implements a curve of type DRAW_HISTOGRAM
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: