[Help] I created Custom RSI indicator manually but it's don't work. How to calculate Average Gains/Loses??
avg_gain = gain/9;
What you have is utter babel, starting with the undefined variable gain.- Musngi: I created Custom RSI indicator manually but it's don't work. How to calculate Average Gains/Loses??Why don't you look at the real RSI code and find out.
- What you have is utter babel, starting with the undefined variable gain.
- Why don't you look at the real RSI code and find out.
1. I declared the variable "gain" as global variable.
- So what is it's value? As previously answered, "undefined."
- What code? Go to the <data folder>\MQL4\indicators\RSI.mq4 and look at it. No OOP code at all.
-
Why did you post your MT4 question in the
Root /
MT5 General section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - "ugly code" "horrible" " setting for extern?" "I don't understand" "You are damn arrogant" "Could you elaborate more?" I had you listed a year ago as a troll with your vague questions and absurd responses. Apparently you haven't changed. So I will mark you again, and ignore you.
- So what is it's value? As previously answered, "undefined."
- What code? Go to the <data folder>\MQL4\indicators\RSI.mq4 and look at it. No OOP code at all.
-
Why did you post your MT4 question in the
Root /
MT5 General section
instead of the
MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - "ugly code" "horrible" " setting for extern?" "I don't understand" "You are damn arrogant" "Could you elaborate more?" I had you listed a year ago as a troll with your vague questions and absurd responses. Apparently you haven't changed. So I will mark you again, and ignore you.
It's still no answer from expert?
It's still no answer from expert?
Please stop doing that (to be clear updating your post to get your topic at the top of the section).
Everyone saw your topic and everyone decided to not answer for some reason.
Please stop doing that (to be clear updating your post to get your topic at the top of the section).
Everyone saw your topic and everyone decided to not answer for some reason.
Don't worry I discovered the answer but I have two problem: first, I don't know if my algorithm is correct and second, there's an additional two numbers in the upper left corner of indicator subwindow.
Its works even I didn't use SetIndexStyle(). It confused me.
#property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 clrPink extern int inp_period = 9; double RSI_buffer[]; double pos_buffer[]; double neg_buffer[]; int init() { string short_name; //IndicatorBuffers(3); SetIndexBuffer(0, RSI_buffer); SetIndexBuffer(1, pos_buffer); SetIndexBuffer(2, neg_buffer); //--- set levels IndicatorSetInteger(INDICATOR_LEVELS,2); IndicatorSetDouble(INDICATOR_LEVELVALUE,0,30); IndicatorSetDouble(INDICATOR_LEVELVALUE,1,70); //--- set maximum and minimum for subwindow IndicatorSetDouble(INDICATOR_MINIMUM,0); IndicatorSetDouble(INDICATOR_MAXIMUM,100); //--- name for DataWindow and indicator subwindow label short_name = "RSI("+string(inp_period)+")"; IndicatorShortName(short_name); SetIndexLabel(0, short_name); return 0; } int start() { int limit; int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); //---- the last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i<limit; i++) { double now_close = iClose(Symbol(), Period(), i); double prev_close = iClose(Symbol(), Period(), i+1); double ma = (now_close - prev_close); if(ma > 0) { pos_buffer[i] = ma; neg_buffer[i] = 0.0; } else { neg_buffer[i] = MathAbs(ma); pos_buffer[i] = 0.0; } } for(int x=0; x<limit; x++) { double avg_gain = iMAOnArray(pos_buffer, 0, inp_period, 0, MODE_SMMA, x); double avg_lose = iMAOnArray(neg_buffer, 0, inp_period, 0, MODE_SMMA, x); if(avg_lose != 0) { double rs = avg_gain/avg_lose; RSI_buffer[x] = 100.0-(100.0/(1+rs)); } } return 0; }
[Help] I created Custom RSI indicator manually but it's don't work. How to calculate Average Gains/Loses??
https://en.wikipedia.org/wiki/Relative_strength_index#Calculation
I'm using MQL4. There's no built-in function for Average Gains/Loses. If you know how to code that average gains/loses, please correct my code or change it completely.