i recommend that you search codebase for any "on array indicator" for mt4, and then insert your own rso code in the appropriate place, or look over the ma on array code and copy that into your rso indicator. OR pay a coder on freelance, that is: if you cant code it yourself.
I have added a MA on price array to my RSO the only thing is that it looks a little different than when I add it to the RSO via drag and drop on mt4. It also does not go below zero. The code isn't that long if I sent it could you take a look and see what the issue would possibly be ?
The image of the indicators are attached, the one above is what it should look like, the one below is after coding the MA on price array into the RSO
Here is the code, the MA on price array is at the bottom and the only other thing added was the code for colour, width, buffer, setindexbuffer, and setindexstyle
//+------------------------------------------------------------------+//| RSO.mq4 |//| Copyright 2005-2014, MetaQuotes Software Corp. |//| Modification by Paran Softwares, 2017. |//| http://www.mql4.com |//+------------------------------------------------------------------+#property copyright"2005-2014, MetaQuotes Software Corp; 2017, Paran Softwares"#property link"http://www.mql4.com"#property description"Relative Strength Oscillator"#property strict#property indicator_separate_window#property indicator_buffers5#property indicator_minimum -50#property indicator_maximum50#property indicator_level10#property indicator_level20#property indicator_levelcolor Silver
#property indicator_levelstyleDRAW_LINE#property indicator_color1 DodgerBlue
#property indicator_color2 Lime
#property indicator_color3 White
#property indicator_color5 Coral
#property indicator_width12#property indicator_width22#property indicator_width32#property indicator_width51//--- input parametersexternint InpRSOPeriod = 6; // RSO Period//--- buffersdouble ExtRSOBuffer[];
double ExtRSOUpBuffer[];
double ExtRSODnBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
double SimpleMAOnBuffer[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit(void)
{
string short_name;
//--- buffers mapping
IndicatorBuffers(5);
//--- indicator lineSetIndexBuffer(0, ExtRSOBuffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(5, SimpleMAOnBuffer);
SetIndexStyle(5, DRAW_LINE);
//--- indicator barsSetIndexBuffer(1, ExtRSOUpBuffer);
SetIndexStyle(1, DRAW_HISTOGRAM);
SetIndexBuffer(2, ExtRSODnBuffer);
SetIndexStyle(2, DRAW_HISTOGRAM);
SetIndexBuffer(3, ExtPosBuffer);
SetIndexStyle(3, DRAW_LINE);
SetIndexBuffer(4, ExtNegBuffer);
//--- name for DataWindow and indicator subwindow label
short_name="RSO("+string(InpRSOPeriod)+")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
//--- check for inputif(InpRSOPeriod < 2)
{
Print("Incorrect value for input variable InpRSOPeriod = ", InpRSOPeriod);
Print("Corrected to 14!");
InpRSOPeriod = 6;
}
//---
SetIndexDrawBegin(0, InpRSOPeriod);
SetIndexDrawBegin(1, InpRSOPeriod);
SetIndexDrawBegin(2, InpRSOPeriod);
//--- initialization donereturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Relative Strength Index |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
int i, pos;
double diff;
//---if(Bars<=InpRSOPeriod || InpRSOPeriod<2)
return(0);
//--- counting from 0 to rates_totalArraySetAsSeries(ExtRSOBuffer, false);
ArraySetAsSeries(ExtRSOUpBuffer, false);
ArraySetAsSeries(ExtRSODnBuffer, false);
ArraySetAsSeries(ExtPosBuffer, false);
ArraySetAsSeries(ExtNegBuffer, false);
ArraySetAsSeries(close, false);
//--- preliminary calculations
pos = prev_calculated-1;
if(pos <= InpRSOPeriod)
{
//--- first RSIPeriod values of the indicator are not calculated
ExtRSOBuffer[0]=0.0;
ExtPosBuffer[0]=0.0;
ExtNegBuffer[0]=0.0;
double sump=0.0;
double sumn=0.0;
for(i=1; i<=InpRSOPeriod; i++)
{
ExtRSOBuffer[i]=0.0;
ExtPosBuffer[i]=0.0;
ExtNegBuffer[i]=0.0;
diff=close[i]-close[i-1];
if(diff>0)
sump+=diff;
else
sumn-=diff;
}
//--- calculate first visible value
ExtPosBuffer[InpRSOPeriod]=sump/InpRSOPeriod;
ExtNegBuffer[InpRSOPeriod]=sumn/InpRSOPeriod;
if(ExtNegBuffer[InpRSOPeriod]!=0.0)
ExtRSOBuffer[InpRSOPeriod]=50.0-(100.0/(1.0+ExtPosBuffer[InpRSOPeriod]/ExtNegBuffer[InpRSOPeriod]));
else
{
if(ExtPosBuffer[InpRSOPeriod]!=0.0)
ExtRSOBuffer[InpRSOPeriod]=50.0;
else
ExtRSOBuffer[InpRSOPeriod]=0.0;
}
//--- prepare the position value for main calculation
pos = InpRSOPeriod+1;
}
//--- the main loop of calculationsfor(i=pos; i<rates_total && !IsStopped(); i++)
{
diff=close[i]-close[i-1];
ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSOPeriod-1)+(diff>0.0?diff:0.0))/InpRSOPeriod;
ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSOPeriod-1)+(diff<0.0?-diff:0.0))/InpRSOPeriod;
if(ExtNegBuffer[i]!=0.0)
ExtRSOBuffer[i]=50.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);
else
{
if(ExtPosBuffer[i]!=0.0)
ExtRSOBuffer[i]=50.0;
else
ExtRSOBuffer[i]=0.0;
}
if(ExtRSOBuffer[i] - ExtRSOBuffer[i-1] < 0)
ExtRSODnBuffer[i] = 0.9*ExtRSOBuffer[i];
else
ExtRSOUpBuffer[i] = 0.9*ExtRSOBuffer[i];
}
//---return(rates_total);
}
//+------------------------------------------------------------------+//| Simple moving average on price array |//+------------------------------------------------------------------+int SimpleMAOnBuffer(constint rates_total,constint prev_calculated,constint begin,
constint period,constdouble& price[],double& buffer[])
{
int i,limit;
//--- check for dataif(period<=1 || rates_total-begin<period) return(0);
//--- save as_series flagsbool as_series_price=ArrayGetAsSeries(price);
bool as_series_buffer=ArrayGetAsSeries(buffer);
if(as_series_price) ArraySetAsSeries(price,false);
if(as_series_buffer) ArraySetAsSeries(buffer,false);
//--- first calculation or number of bars was changedif(prev_calculated==0) // first calculation
{
limit=period+begin;
//--- set empty value for first barsfor(i=0;i<limit-1;i++) buffer[i]=0.0;
//--- calculate first visible valuedouble firstValue=0;
for(i=begin;i<limit;i++)
firstValue+=price[i];
firstValue/=period;
buffer[limit-1]=firstValue;
}
else limit=prev_calculated-1;
//--- main loopfor(i=limit;i<rates_total;i++)
buffer[i]=buffer[i-1]+(price[i]-price[i-period])/period;
//--- restore as_series flagsif(as_series_price) ArraySetAsSeries(price,true);
if(as_series_buffer) ArraySetAsSeries(buffer,true);
//---return(rates_total);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
i recommend that you search codebase for any "on array indicator" for mt4, and then insert your own rso code in the appropriate place, or look over the ma on array code and copy that into your rso indicator. OR pay a coder on freelance, that is: if you cant code it yourself.
I have added a MA on price array to my RSO the only thing is that it looks a little different than when I add it to the RSO via drag and drop on mt4. It also does not go below zero. The code isn't that long if I sent it could you take a look and see what the issue would possibly be ?
The image of the indicators are attached, the one above is what it should look like, the one below is after coding the MA on price array into the RSO
Here is the code, the MA on price array is at the bottom and the only other thing added was the code for colour, width, buffer, setindexbuffer, and setindexstyle