how to combine two oscillator in a code (On balance volume oscillator into custom oscillator)
Thanks for your reply..
i did that but the OBV is not showing on chart
//+------------------------------------------------------------------+ //| RSI OBV | //| Abu Saidu | //| t.me/thegoldentrades | //+------------------------------------------------------------------+ #property version "1.00" #property copyright "abu saidu" #property link "t.me/thegoldentrades" #property description "Features of this indicator:" #property strict #property indicator_separate_window #property indicator_buffers 9 #define SignalName "OBVRSI" //---- Overbought1 #property indicator_color1 clrBlue #property indicator_width1 2 #property indicator_style1 STYLE_SOLID //---- Oversold1 #property indicator_color2 clrYellow #property indicator_width2 2 #property indicator_style2 STYLE_SOLID //---- Overbought2 #property indicator_color3 clrGreen #property indicator_width3 1 #property indicator_style3 STYLE_DOT //---- Oversold2 #property indicator_color4 clrRed #property indicator_width4 1 #property indicator_style4 STYLE_DOT //---- middle level #property indicator_color5 clrWhiteSmoke #property indicator_width5 1 #property indicator_style5 STYLE_SOLID //---- RSI line 1 #property indicator_color6 clrAqua #property indicator_width6 2 #property indicator_style6 STYLE_SOLID //---- RSI line 2 #property indicator_color7 clrAqua #property indicator_width7 2 #property indicator_style7 STYLE_SOLID //---- RSI line 3 #property indicator_color8 clrAqua #property indicator_width8 2 #property indicator_style8 STYLE_SOLID //---- iOBV line #property indicator_color9 clrGold #property indicator_width9 2 #property indicator_style9 STYLE_SOLID //+------------------------------------------------------------------+ //| Enumeration of OBV | //+------------------------------------------------------------------+ enum OBV { Call_iOBV , // use iOBV Call_IndicatorCreate // use IndicatorCreate }; //--- input parameters extern string Separator1="======= RSI Params ======="; extern int RSI1=13; // RSI1 Period extern int RSI2=0; // RSI2 Period extern int RSI3=0; // RSI3 Period extern ENUM_APPLIED_PRICE RSI_Price=PRICE_CLOSE; // RSI Price extern int ExtOBVAppliedPrice=0; extern int Overbought1=70; // Overbought 1 extern int Oversold1=30; // Oversold 1 extern int Overbought2=80; // Overbought 2 extern int Oversold2=20; // Oversold 2 extern string Separator3="====== Enable/Disable ======"; extern bool OBVLine=true; // OBV Line extern bool RSILine1=true; // RSI1 Line extern bool RSILine2=false; // RSI2 Line extern bool RSILine3=false; // RSI3 Line extern bool RSILevel1=true; // RSI Level 1 extern bool RSILevel2=true; // RSI Level 2 extern bool ZeroLine=true; // Zero Line //---- indicator buffers double OB1Buffer[]; double OS1Buffer[]; double OB2Buffer[]; double OS2Buffer[]; double ZeroLineBuffer[]; double RSI1Buffer[]; double RSI2Buffer[]; double RSI3Buffer[]; double ExtOBVBuffer[] //---- Global variables ;static datetime LastAlertTime; //record the time of last alert int AlertShift; //0: alert for current unfinished bar; 1: alert for finished bar const long Chart_ID=ChartID(); string sShortName; //--- variable for storing the handle of the iOBV indicator int handle; //--- name of the indicator on a chart string short_name; //--- we will keep the number of values in the On Balance Volume indicator int bars_calculated=500; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers IndicatorBuffers(19); //---- Check validation of input parameters if(RSI1<1 || RSI1>100 || RSI2<1 || RSI2>100 || RSI3<1 || RSI3>100) { Print("Error: RSI period is out of range!"); RSI1=13; RSI2=3; RSI3=21; } if(Overbought1>100 || Oversold1<0 || Overbought2>100 || Oversold2<0) { Print("Invalid overbought or oversold value!"); Overbought1=70; Oversold1=30; Overbought2=80; Oversold2=20; } if(AlertShift<0 || AlertShift>1) { Print("AlertShift must be 0 or 1."); AlertShift=0; } //--- indicator digits IndicatorDigits(0); //--- Set indicator name, show RSI period, MA period and MA method. sShortName="RSIOBV ("+IntegerToString(RSI1); if(RSILine2) sShortName+=","+IntegerToString(RSI2); if(RSILine3) sShortName+=","+IntegerToString(RSI3); if(OBVLine) sShortName+=","+IntegerToString(OBVLine); sShortName+=")"; IndicatorShortName(sShortName); //--- buffer mapping and drawing setting int n=0; SetIndexBuffer(n,OB1Buffer); if(RSILevel1) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexLabel(n,NULL); SetIndexDrawBegin(n,0); n++; SetIndexBuffer(n,OS1Buffer); if(RSILevel1) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexDrawBegin(n,0); n++; SetIndexBuffer(n,OB2Buffer); if(RSILevel2) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexDrawBegin(n,0); n++; SetIndexBuffer(n,OS2Buffer); if(RSILevel2) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexDrawBegin(n,0); n++; SetIndexBuffer(n,ZeroLineBuffer); if(ZeroLine) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexLabel(n,NULL); SetIndexDrawBegin(n,0); n++; SetIndexBuffer(n,RSI1Buffer); if(RSILine1) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexLabel(n,"RSI"+IntegerToString(RSI1)); SetIndexDrawBegin(n,RSI1); n++; SetIndexBuffer(n,RSI2Buffer); if(RSILine2) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexLabel(n,"RSI"+IntegerToString(RSI2)); SetIndexDrawBegin(n,RSI2); n++; SetIndexBuffer(n,RSI3Buffer); if(RSILine3) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexLabel(n,"RSI"+IntegerToString(RSI3)); SetIndexDrawBegin(n,RSI3); n++; SetIndexBuffer(n,RSI3Buffer); if(RSILine3) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_NONE); SetIndexLabel(n,"RSI"+IntegerToString(RSI3)); SetIndexDrawBegin(n,RSI3); n++; SetIndexBuffer(n,ExtOBVBuffer); if(OBVLine) SetIndexStyle(n,DRAW_LINE); else SetIndexStyle(n,DRAW_LINE); SetIndexLabel(n,"OBV"+IntegerToString(OBVLine)); SetIndexDrawBegin(n,ExtOBVAppliedPrice); n++; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectsDeleteAll(0,SignalName); Print(__FUNCTION__,"_Uninitalization reason code = ",reason); return; } //+------------------------------------------------------------------+ //| 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[]) { //--- check rates_total if(rates_total<1) return(-1); //--- prepare loop index int i; int limit1=rates_total; int limit2=rates_total-1; if(prev_calculated>0) limit1=limit2=rates_total-IndicatorCounted(); //--- calculate overbought, oversold, RSI1, RSI2, RSI3 for(i=limit1-1; i>=0 && !IsStopped(); i--) { //---- overbought and oversold levels OB1Buffer[i]=Overbought1-50.0; OS1Buffer[i]=Oversold1-50.0; OB2Buffer[i]=Overbought2-50.0; OS2Buffer[i]=Oversold2-50.0; //--- zero line ZeroLineBuffer[i]=0.0; //---- RSI 1, RSI 2, RSI 3 RSI1Buffer[i]=iRSI(NULL,0,RSI1,RSI_Price,i)-50.0; RSI2Buffer[i]=iRSI(NULL,0,RSI2,RSI_Price,i)-50.0; RSI3Buffer[i]=iRSI(NULL,0,RSI3,RSI_Price,i)-50.0; ExtOBVBuffer[i]=iOBV(NULL,0,ExtOBVAppliedPrice,i); } return(0); } //+------------------------------------------------------------------+ string GetChartPeriod() { string per=""; int chartPeriod=Period(); switch(chartPeriod) { case 1: per="M1"; break; case 5: per="M5"; break; case 15: per="M15"; break; case 30: per="M30"; break; case 60: per="H1"; break; case 240: per="H4"; break; case 1440: per="D1"; break; case 10080: per="W1"; break; case 43200: per="MN"; break; } return (per); } //+------------------------------------------------------------------+
Abubakar
Saidu:
Thanks for your reply..
i did that but the OBV is not showing on chart
/*
SetIndexBuffer(n,RSI3Buffer);
if(RSILine3) SetIndexStyle(n,DRAW_LINE);
else SetIndexStyle(n,DRAW_NONE);
SetIndexLabel(n,"RSI"+IntegerToString(RSI3));
SetIndexDrawBegin(n,RSI3);
n++;
*/
Delete one of the two same parts.
Abubakar
Saidu:
i did that and this is what happened
That's right.
It doesn't make sense to display them in the same chart because OBV and RSI have different units.
Naguisa Unada:
Okay Thanks a lot for your time and support..
That's right.
It doesn't make sense to display them in the same chart because OBV and RSI have different units.


Hello, Please how do i combine two oscillators in one
combining OBV with a custom indicator
Thanks