**hdemarco:**

Dear all,

How can I get price of symbol to match predefined value of indicator?

Example: RSI=5 and price=30. What is the price for RSI=2? It is < 30, but how much?

Thanks in advance,

Henrique

Moderator

33805

Dear all,

How can I get price of symbol to match predefined value of indicator?

Example: RSI=5 and price=30. What is the price for RSI=2? It is < 30, but how much?

Thanks in advance,

Henrique

25

Doesn't make sense. There is no relation 1 to 1 between price and rsi. RSI is calculated on a given number of values.

*"There is no relation 1 to 1 between price and rsi."* That is why I posted in the forum. If it could be solved using a rule of three, I would not be so stupid to post here.

Lets suppose you have these given number of values (an array of prices).

You can use a loop to change the most recent price of array, that I will call as price_close.

Do Until RSI=2

price_close = price_close - 0.01

RSI = iRSI (price_array, time_frame, rsi_period, ....) and all variables required to evaluate RSI

End Loop

So you have an RSI level and a price array. You keep decreasing price until RSI level match desired value and then get price_close as the value you are looking for.

I think this logic would work, but I'd like to see if you guys have another idea or a tool that calculate this. So I don't need to code something that is already done.

Do you still think "*doesn't make sense*"?

16564

Then what is your problem? Code it:

From the MT4 RSI |
---|

diff=close[i]-close[i-1]; ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod; ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod; if(ExtNegBuffer[i]!=0.0) ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]); |

double posBufOne = RSI(handle, eBufPos, 0); double negBufOne = RSI(handle, eBufNeg, 0); double cPrev = iClose(_Symbol, _Period, 1); double cUpper = cPrev; double cLower = 0; while(cUpper - cLower > _Point){ double cCurr = (cUpper + cLower) / 2.0; double diff=cCurr-cPrev; double posBuf = posBufOne *(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod; double negBuf = negBufOne *(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod; double rsi =100.0-100.0/(1+posBuf/negBuf); if(rsi > 2) cUpper = cCurr; else cLower=cCurr; } PrintFormat("At %g rsi == 2", cUpper);

The value is good for the current bar only. It will change with each new bar

What you will find it that it will be way outside the price bars except when the RSI is approaching 2.

25

Then it is done!

First of all I got iRSIOnArray, available at https://github.com/Shmuma/mt-tools/blob/master/mt5/IndicatorsOnArray.mqh . Thanks to Max Lapan.

Set your array as a series and use flag false, otherwise RSI may not be calculated accordingly.

ArraySetAsSeries(PriceSimulated,false);

And the code is:

int array_tamanho = 100; --I prefer to set array size. If this number is too small, RSI can differ (check Wikipedia and MT5 forum if you are curious about RSI calculation).

int numberofClosePrice = CopyClose(_Symbol,0,0,array_tamanho,PriceSimulated);

do {

PriceSimulated[array_tamanho-1] -= 0.01;

}

while (iRSIOnArray(PriceSimulated,2)>Nivelsobrevendido);

Dear all,

How can I get price of symbol to match predefined value of indicator?

Example: RSI=5 and price=30. What is the price for RSI=2? It is < 30, but how much?

Thanks in advance,

Henrique