Here's a starting point.
#property version "1.00" #property indicator_separate_window #property indicator_maximum 100 #property indicator_minimum 0 #property indicator_buffers 7 #property indicator_plots 4 //--- plot OB #property indicator_label1 "Overbought;Oversold" #property indicator_type1 DRAW_FILLING #property indicator_color1 clrGray #property indicator_style1 STYLE_SOLID //--- plot RSI1 #property indicator_label2 "RSI" #property indicator_type2 DRAW_LINE #property indicator_color2 clrDeepSkyBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 2 //--- plot MA1 #property indicator_label3 "MA of RSI;Centre" #property indicator_type3 DRAW_COLOR_HISTOGRAM2 #property indicator_color3 clrGreen,clrLimeGreen,clrRed,clrFireBrick #property indicator_style3 STYLE_SOLID #property indicator_width3 5 //--- plot MA2 #property indicator_label4 "MA of MA" #property indicator_type4 DRAW_LINE #property indicator_color4 clrGold #property indicator_style4 STYLE_SOLID #property indicator_width4 2 //--- input parameters input int RSIPeriod=13; input ENUM_APPLIED_PRICE RSIPrice=PRICE_CLOSE; input int MA1Period=10; input int MA1Shift=0; input ENUM_MA_METHOD MA1Method=MODE_SMA; input int MA2Period=5; input int MA2Shift=0; input ENUM_MA_METHOD MA2Method=MODE_SMA; input int OBLevel=70; input int OSLevel=30; //--- indicator buffers double RSIBuffer[]; double MA1Buffer[]; double MA50Buffer[]; double MA1Colors[]; double MA2Buffer[]; double OBBuffer[]; double OSBuffer[]; //--- int handleRSI=INVALID_HANDLE; int handleMA1=INVALID_HANDLE; int handleMA2=INVALID_HANDLE; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if((handleRSI=iRSI(Symbol(),PERIOD_CURRENT,RSIPeriod,RSIPrice))==INVALID_HANDLE || (handleMA1=iMA(Symbol(),PERIOD_CURRENT,MA1Period,MA1Shift,MA1Method,handleRSI))==INVALID_HANDLE || (handleMA2=iMA(Symbol(),PERIOD_CURRENT,MA2Period,MA2Shift,MA2Method,handleMA1))==INVALID_HANDLE) return(INIT_PARAMETERS_INCORRECT); //--- indicator buffers mapping SetIndexBuffer(0,OBBuffer,INDICATOR_DATA); SetIndexBuffer(1,OSBuffer,INDICATOR_DATA); SetIndexBuffer(2,RSIBuffer,INDICATOR_DATA); SetIndexBuffer(3,MA1Buffer,INDICATOR_DATA); SetIndexBuffer(4,MA50Buffer,INDICATOR_DATA); SetIndexBuffer(5,MA1Colors,INDICATOR_COLOR_INDEX); SetIndexBuffer(6,MA2Buffer,INDICATOR_DATA); //--- IndicatorSetString(INDICATOR_SHORTNAME,StringFormat("RSI Signal(%d,%s %d,%s %d)", RSIPeriod,StringSubstr(EnumToString(MA1Method),5),MA1Period, StringSubstr(EnumToString(MA2Method),5),MA2Period)); IndicatorSetInteger(INDICATOR_DIGITS,1); IndicatorSetInteger(INDICATOR_LEVELS,3); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,OBLevel); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,50); IndicatorSetDouble(INDICATOR_LEVELVALUE,2,OSLevel); //--- PlotIndexSetInteger(0,PLOT_SHOW_DATA,false); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int32_t rates_total, const int32_t prev_calculated, const int32_t begin, const double &price[]) { //--- int toCopy=(rates_total==prev_calculated)?1:rates_total-prev_calculated; if(CopyBuffer(handleRSI,0,0,toCopy,RSIBuffer)!=toCopy || CopyBuffer(handleMA1,0,0,toCopy,MA1Buffer)!=toCopy || CopyBuffer(handleMA2,0,0,toCopy,MA2Buffer)!=toCopy) return(0); //--- int start=(rates_total==prev_calculated)?rates_total-1:(!prev_calculated)?RSIPeriod+MA1Period+MA2Period:prev_calculated; for(int i=start;i<rates_total;i++) { OBBuffer[i]=OBLevel; OSBuffer[i]=OSLevel; double preMA=MA1Buffer[i-1]; double curMA=MA1Buffer[i]; MA1Colors[i]=(curMA>50 && curMA>preMA)?0: (curMA>50 && curMA<preMA)?1: (curMA<50 && curMA<preMA)?2:3; MA50Buffer[i]=50; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Thanks @Ernst Van Der Merwe,
Yes, that's a lot tidier - I stuck to the original format and had cheated with the MQL4 port functions - which would be super inefficient (and lazy).
I'll take another look and thank you for taking the trouble.
With my best regards, ESB.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello All,
Whilst browsing for a useful indicator with sorce, I came across the RSISignal - indicator for MetaTrader 4. As I have my own wrapper for adding logic, I thought I'd port this combined indicator to MQL5. I have been making use of the plethora of open source indicators made available by generous & creative authors.
For this port I made extensive use of the excellent 'Migrating from MQL4 to MQL5', carefully following, modifying and adding based on this document. I know that I can make the execution more efficient, but I thought I'd just get it working first.
It now compiles, but displays sweet nothing. It seems that a little knowledge isn't enough, and I was hoping someone might take a look at what I have done and give me some hints/ideas as to what I have done wrong and what I might do to fix it please.
I'll share the port with the author once it's working as this is just derivative. Credit where credit is due.
Thank you in advance,
With my best regards, ESB.