Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Multi_Oscillator_v1
//+------------------------------------------------------------------+
//| Multi_Oscillator_v1.mq4 |
//+------------------------------------------------------------------+
#property copyright "By cja for tsd forum"
#property link "http://cjatradingtools.com/"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 LimeGreen
#property indicator_color3 Red
#property indicator_color4 Gold
#property indicator_color5 Red
#property indicator_color6 Red
#property indicator_color7 Red
#property indicator_color8 Gold
#property indicator_width1 1
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 2
#property indicator_width8 2
#property indicator_style1 0
#property indicator_style3 0
#property indicator_style4 0
#property indicator_style5 2
#property indicator_style6 2
#property indicator_style7 0
#property indicator_style8 0
//---- input parameters
extern string __________________LABEL_1 =" MA METHOD Settings";
extern string MODE_SMA. ="0 = Simple moving average";
extern string MODE_EMA. ="1 = Exponential moving average";
extern string MODE_SMMA. ="2 = Smoothed moving average";
extern string MODE_LWMA. ="3 = Linear weighted moving average";
extern string __________________LABEL_2 =" MA PRICE Settings";
extern string PRICE_CLOSE. ="0 = Close price";
extern string PRICE_OPEN. ="1 = Open price";
extern string PRICE_HIGH. ="2 = High price";
extern string PRICE_LOW. ="3 = Low price";
extern string PRICE_MEDIAN. ="4 = Median price, (high+low)/2";
extern string PRICE_TYPICAL. ="5 = Typical price, (high+low+close)/3";
extern string PRICE_WEIGHTED. ="6 = Weighted price, (hi+low+cl+cl)/4";
extern string ___________________________="______________________________";
extern string __________________LABEL_3 = " Base PERIOD + PRICE";
extern int Multi_Period = 13;
extern int Multi_Price = 0;
extern string __________________LABEL_4 = "Select ONLY 1 Indicator";
extern bool RSI = false;
extern bool CCI = false;
extern bool MFI = false;
extern bool STO = false;
extern bool DEM = true;
extern bool WPR = false;
extern bool RVI = false;
extern string __________________LABEL_5 = "2 x MA Smoothing Applied";
extern string __________________MA1 ="";
extern int MAPeriod1 = 28;
extern int MAMethod1 = 0;
extern string __________________MA2 ="";
extern int MAPeriod2 = 18;
extern int MAMethod2 = 0;
extern string __________________LABEL_6 = "SHOW or HIDE Lines";
extern bool Show_Histo_Display = false;
extern bool Show_Base_Indicator = true;
extern bool Show_MA1_Line = true;
extern bool Show_MA2_Line = true;
extern string __________________LABEL_7 = "Level Color + Style";
extern color Level_color = DarkSlateGray;
extern int Level_Style = 2;
//---- indicator buffers
double MULTIBuffer[];
double MABuffer1[];
double MABuffer2[];
double BarBuffer[];
double UPBuffer[];
double DNBuffer[];
double RVIBuffer[];
double STOBuffer[];
string indicator;
double bar,bar2,bar3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
// Main source Indicator Buffer
SetIndexDrawBegin(0,Multi_Period);
SetIndexBuffer(0,MULTIBuffer);
if(Show_Histo_Display==true){SetIndexStyle(0,DRAW_NONE);}
else if(Show_Base_Indicator==true){SetIndexStyle(0,DRAW_LINE);}
else{SetIndexStyle(0,DRAW_NONE);}
// Histo Buffers
SetIndexBuffer(1,BarBuffer);
SetIndexStyle(1,DRAW_NONE);
SetIndexBuffer(2,UPBuffer);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(3,DNBuffer);
SetIndexStyle(3,DRAW_HISTOGRAM);
// 2nd Lines for STO & RVI
SetIndexDrawBegin(4,Multi_Period);
SetIndexBuffer(4,RVIBuffer);
if(Show_Histo_Display==true||Show_Base_Indicator==false){SetIndexStyle(4,DRAW_NONE);}
else if(RVI==true){SetIndexStyle(4,DRAW_LINE);}
else{SetIndexStyle(4,DRAW_NONE);}
SetIndexDrawBegin(5,Multi_Period);
SetIndexBuffer(5,STOBuffer);
if(Show_Histo_Display==true||Show_Base_Indicator==false){SetIndexStyle(5,DRAW_NONE);}
else if(STO==true){SetIndexStyle(5,DRAW_LINE);}
else{SetIndexStyle(5,DRAW_NONE);}
// MA Line Buffers
SetIndexDrawBegin(6,MAPeriod1);
SetIndexBuffer(6,MABuffer1);
if(Show_Histo_Display==true){SetIndexStyle(6,DRAW_HISTOGRAM);}
else if(Show_MA1_Line==true){SetIndexStyle(6,DRAW_LINE);}
else{SetIndexStyle(6,DRAW_NONE);}
SetIndexDrawBegin(7,MAPeriod2);
SetIndexBuffer(7,MABuffer2);
if(Show_Histo_Display==true){SetIndexStyle(7,DRAW_HISTOGRAM);}
else if(Show_MA2_Line==true){SetIndexStyle(7,DRAW_LINE);}
else{SetIndexStyle(7,DRAW_NONE);}
IndicatorDigits(1);
// Indicator Label code
if(RSI==true)indicator="RSI";
if(CCI==true)indicator="CCI";
if(MFI==true)indicator="MFI";
if(STO==true)indicator="STOCH";
if(DEM==true)indicator="DEM";
if(WPR==true)indicator="WPR";
if(RVI==true)indicator="RVI";
SetIndexLabel(0,"Multi "+indicator+"");
SetIndexLabel(1,"MA1 "+MAPeriod1+"");
SetIndexLabel(2,"MA2 "+MAPeriod2+"");
IndicatorShortName("Multi_Oscillator v1 "+indicator+" "+Multi_Period+" ( MA1 "+MAPeriod1+" ) ( MA2 "+MAPeriod2+" )");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Multi Oscillator |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit = Bars-counted_bars-1;
for(int i=limit; i>=0; i--)
{
// Source Base Indicators
if(RSI==true){MULTIBuffer[i]=iRSI(NULL,0,Multi_Period,Multi_Price,i);}
if(CCI==true){MULTIBuffer[i]=iCCI(NULL,0,Multi_Period,Multi_Price,i);}
if(MFI==true){MULTIBuffer[i]=iMFI(NULL,0,Multi_Period,i);}
if(STO==true){MULTIBuffer[i]=iStochastic(NULL,0,Multi_Period,Multi_Period/2,Multi_Period/2,0,Multi_Price,MODE_SIGNAL,i);}
if(STO==true){STOBuffer[i]=iStochastic(NULL,0,Multi_Period,Multi_Period/2,Multi_Period/2,0,Multi_Price,MODE_MAIN,i);}
if(DEM==true){MULTIBuffer[i]=iDeMarker(NULL,0,Multi_Period,i);}
if(WPR==true){MULTIBuffer[i]=iWPR(NULL,0,Multi_Period,i);}
if(RVI==true){MULTIBuffer[i]=iRVI(NULL,0,Multi_Period,MODE_SIGNAL,i);}
if(RVI==true){RVIBuffer[i]=iRVI(NULL,0,Multi_Period,MODE_MAIN,i);}
// Indicator line levels
if(Show_Histo_Display==false){
if(CCI==true){SetLevelValue(0,0);SetLevelValue(1,100);SetLevelValue(2,-100);SetLevelValue(3,-250);SetLevelValue(4,250);}
if(RSI==true||MFI==true){SetLevelValue(0,50);SetLevelValue(1,70);SetLevelValue(2,30);}
if(STO==true){SetLevelValue(0,50);SetLevelValue(1,80);SetLevelValue(2,20);}
if(WPR==true){SetLevelValue(0,-50);SetLevelValue(1,-80);SetLevelValue(2,-20);}
if(RVI==true){SetLevelValue(0,0);}
SetLevelStyle(Level_Style,0,Level_color);}
else{SetLevelValue(0,0);SetLevelValue(1,0);SetLevelValue(2,0);SetLevelValue(3,0);SetLevelValue(4,0);SetLevelStyle(Level_Style,0,Level_color);}
}
// MA Buffers for Lines
for (i=limit-1;i>=0;i--)
{
if(Show_Histo_Display==false){
MABuffer1[i]=iMAOnArray(MULTIBuffer,0,MAPeriod1,0,MAMethod1,i);
MABuffer2[i]=iMAOnArray(MULTIBuffer,0,MAPeriod2,0,MAMethod2,i);
}
// MA Buffers for Histograms
if(Show_Histo_Display==true){
BarBuffer[i]=(iMAOnArray(MULTIBuffer,0,MAPeriod2,0,MAMethod2,i)-iMAOnArray(MULTIBuffer,0,MAPeriod1,0,MAMethod1,i))*10;
UPBuffer[i]=iMAOnArray(MULTIBuffer,0,MAPeriod1,0,MAMethod1,i);
DNBuffer[i]=iMAOnArray(MULTIBuffer,0,MAPeriod2,0,MAMethod2,i);
bar =BarBuffer[i];
bar2=UPBuffer[i];
bar3=DNBuffer[i];
if(bar2 > bar3)
{
UPBuffer[i] = bar;
DNBuffer[i] = EMPTY_VALUE;
}
if(bar2 < bar3)
{
UPBuffer[i] = EMPTY_VALUE;
DNBuffer[i] = bar;
}
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---