Hello,
I am very new to MQL4.
Been doing a lot of digging and couldn't find, thus the post.
What I'm trying to do here is basically having a text/comment to display on my chart when I move the mouse. I know that I can get the data via Data Window, however, at the end of the day, I'd like to have the text/comment to display the variance, instead of looking at the Data Window and do the calculation on the brain.
Below is what I have. But my BB on RSI always shows 0.
The first parameter for iBands is a string type for a Symbol. You can't pass a double.
The first parameter for iBands is a string type for a Symbol. You can't pass a double.
Thanks for the reply.
If I were to change it to 'NULL', instead or 'rsi', then it'll be showing the value of the price, not the value of the RSI (or 'Apply to: First
Indicator's Data).
iBandsOnArray() should be used.
#property copyright "Copyright 2019, ernst" #property link "https://www.mql5.com/en/users/pippod" #property version "1.00" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 4 #property indicator_plots 4 //--- plot RSI #property indicator_label1 "RSI" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLime #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Upper #property indicator_label2 "Upper" #property indicator_type2 DRAW_LINE #property indicator_color2 clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Middle #property indicator_label3 "Middle" #property indicator_type3 DRAW_LINE #property indicator_color3 clrYellow #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot Lower #property indicator_label4 "Lower" #property indicator_type4 DRAW_LINE #property indicator_color4 clrRed #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- input parameters input int RSIPeriod=14; input ENUM_APPLIED_PRICE RSIPrice=PRICE_CLOSE; input int BandsPeriod=20; input double Deviation=2.0; input int Shift=0; //--- indicator buffers double RSIBuffer[]; double UpperBuffer[]; double MiddleBuffer[]; double LowerBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,RSIBuffer); SetIndexBuffer(1,UpperBuffer); SetIndexBuffer(2,MiddleBuffer); SetIndexBuffer(3,LowerBuffer); //--- IndicatorDigits(1); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- int begin=!prev_calculated?rates_total-1-RSIPeriod:rates_total-prev_calculated; for(int i=begin;i>=0 && !_StopFlag;i--) RSIBuffer[i]=iRSI(_Symbol,_Period,RSIPeriod,RSIPrice,i); begin=!prev_calculated?rates_total-1-RSIPeriod-BandsPeriod:rates_total-prev_calculated; for(int i=begin;i>=0 && !_StopFlag;i--) { UpperBuffer[i]=iBandsOnArray(RSIBuffer,0,BandsPeriod,Deviation,Shift,MODE_UPPER,i); MiddleBuffer[i]=iBandsOnArray(RSIBuffer,0,BandsPeriod,Deviation,Shift,MODE_MAIN,i); LowerBuffer[i]=iBandsOnArray(RSIBuffer,0,BandsPeriod,Deviation,Shift,MODE_LOWER,i); } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_CLICK) { //--- Prepare variables int x =(int)lparam; int y =(int)dparam; datetime dt =0; double price =0; int window=0; if(ChartXYToTimePrice(0,x,y,window,dt,price)) { int i=iBarShift(_Symbol,_Period,dt); double rsi = iRSI(_Symbol,_Period,RSIPeriod,RSIPrice,i); double rsi_UBB = iBandsOnArray(RSIBuffer, 0, BandsPeriod, Deviation, Shift, MODE_UPPER,i); double rsi_LBB = iBandsOnArray(RSIBuffer, 0, BandsPeriod, Deviation, Shift, MODE_LOWER,i); Comment(StringFormat("RSI: %.1f " "\nrUBB: %.1f rLBB: %.1f", rsi, rsi_UBB, rsi_LBB )); } } } //+------------------------------------------------------------------+

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am very new to MQL4.
Been doing a lot of digging and couldn't find, thus the post.
First of all, to be clear, I'm trying to implement BB to RSI. If I were to implement it to the chart, I'll drag BB to RSI Window, and then, on BB Setup Window, under 'Apply to', I'll select 'First Indicator's Data' from the drop down list.
What I'm trying to do here is basically having a text/comment to display on my chart when I move the mouse. I know that I can get the data via Data Window, however, at the end of the day, I'd like to have the text/comment to display the variance, instead of looking at the Data Window and do the calculation on the brain.
Below is what I have. But my BB on RSI always shows 0.