-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rsi divergence #18
Comments
Hi, thank you. |
tks for reply. in sample js To detect the divergence of the relative strength index (RSI) and price in JavaScript, you can use the following steps: Calculate the RSI values for a given time period, using the following formula: Calculate the price change for the same time period, by subtracting the first closing price from the last closing price. If the price has increased and the RSI has decreased, or if the price has decreased and the RSI has increased, then there is a divergence between the RSI and price. Here's some example code that demonstrates these steps: Copy code // Calculate the price change // Check for divergence let prices = [100, 105, 110, 100, 95, 105]; here is javascript convert of pinescript // Regular Bullish // Hidden Bullish // Regular Bearish // Hidden Bearish please consider add to your lib. tks so much. |
Thanks for the code, I'll try to add this as soon as possible. |
if lib have divengencer it is big move. |
Hi, I have uploaded a new version. // Regular Bullish // Hidden Bullish // Regular Bearish // Hidden Bearish |
RSI Divergence (from docs) var data = [74,83,66,78,69,70,84,73,74,73,83];
var rsi_length = 5;
var rsi_function = ta.wrsi; // default (the tradingview rsi indicator)
await ta.rsi_divergence(data, rsi_length, rsi_function);
// output (array)
// [0, 0, 1, 0, 1, 0] (better to quantify if needed) Code: async function rsi_divergence(data, length, rs) {
if(!rs) rs = module.exports.wrsi;
var rd = await rs(data, length), out = [];
data = await module.exports.mom(data.slice(length-1, data.length), 2);
for(var i = 0; i < data.length; i++) {
if((data[i] > 0 && rd[i] < 0) || (data[i] < 0 && rd[i] > 0)) {
out.push(1);
} else {
out.push(0);
}
}
return out;
} |
Hi @btm2021 , Could you share your code how do you map the |
Let's say I have the result is
How can I know which point is the start point and endpoint to draw the line ? |
@phattranky I'm not really sure how he maps the values in the array, my best guess is he just loops over it using a for loop. |
Thanks @Vultwo As I know, There are 6 kinds of Divergence. I mean with your function How can we detect it? As your example
How can We know the divergence is bear or bull and which Candles (closed price) are connected become a line ? @btm2021 in case you can help. Thanks a lot |
Here is the code of TradingView, But I don't how to convert it to Javascript
|
@phattranky The code seems to make use of pivot points to determine wether the current state is in regular or hidden.
|
@Vultwo Thanks bro. Hope We can have it soon. It must a great function. |
hello all, sorry because i in my holiday. |
important when check div is use right point. example. u can use pivot of ta.js and detect important zone of price and important zone of rsi and use function div to check. |
and important. div is technical like rsi or bb. you should combine more signal to confirm your signal. |
here my function got result and compare with ohcvl |
@Vultwo, i have write some function check swing high and swing low. and some func. utils. can you add to your lib ? |
Thanks @btm2021 , Instead of drawing on the chart, can we detect it on the code side? My idea is to create a bot that scans all the candle values in a period of time and notify to the user when they detect any divergence. The result expected may be like
|
@phattranky hi, sorry i just write frond-end ui, grap data and show to chart, your idead seem interesting but i don't know how to write for that. sorry man |
Thanks @btm2021 . Yes scanning all the coins at the background is more effective than We have to check the UI one by one =)) |
Is this different from the zigzag and fractal indicators that are already in the library? All functions are welcome if you're willing to share them. |
oh, i checked, it calc base high low and high swing and your zigzag do the same. my bad. |
Sorry for the long wait @phattranky I'm still developing the function. The function won't be perfect though. The divergence can be in multiple states at once. The historical signal values of the function also wouldn't be perfect as the states can changes as more data is coming in. I'm finishing the function over the weekend. |
I have finished the function. It would be appreciated if someone could check the function for correctness. Beware this function can 'repaint' as new data comes available. The function is by no means perfect, that's why I have put it in the experimental section. var data1 = [48,34,43,54,56,64,43,51,52,53,55,51,48,45,40,42,44,45];
var data2 = [76,74,43,55,34,32,45,47,48,53,54,54,50,52,49,47,48,46];
var length = 12; // array length to check
var lookback = 3; // lookback length to check for recent_low / recent_high (please check function code for more info)
var threshold_exaggerated = 0.03; // percentual change threshold for 'exaggerated' divergence
var threshold_normal = 0.01; // percentual change threshold for 'normal' and 'hidden' divergence
ta.divergence_state(data1, data2, length, lookback, threshold_exaggerated, threshold_normal);
// output (array of arrays)
// [['convergence'],['divergence'],['convergence'],['divergence'],['convergence'],['exaggerated_bearish']]
// it is possible for multiple states to exist at once function divergence_state(data1, data2, length, lb, threshold_ex=0.03, threshold_nm=0.01) { // [close]
if(data1.length > data2.length) data1.splice(0,data1.length-data2.length);
if(data2.length > data1.length) data2.splice(0,data2.length-data1.length);
for(var i = length, out = []; i < data1.length; i++) {
var pl1 = data1.slice(i-length,i+1);
var support1 = support(pl1, recent_low(pl1, lb));
var support1_delta = support1.slope / support1.lowest;
var resistance1 = resistance(pl1, recent_high(pl1, lb));
var resistance1_delta = resistance1.slope / resistance1.highest;
var pl2 = data2.slice(i-length,i+1);
var support2 = support(pl2, recent_low(pl2, lb));
var support2_delta = support2.slope / support2.lowest;
var resistance2 = resistance(pl2, recent_high(pl2, lb));
var resistance2_delta = resistance2.slope / resistance2.highest;
if((data1[i] > data1[i-1] && data2[i] < data2[i-1]) || (data1[i] < data1[i-1] && data2[i] > data2[i-1])) {
var obj = [];
if(resistance1_delta < -threshold_ex && resistance2_delta > -threshold_nm) obj.push('exaggerated_bearish');
if(support1_delta < threshold_nm && support2_delta > threshold_ex) obj.push('exaggerated_bullish');
if(resistance1_delta < -threshold_nm && resistance2_delta < threshold_nm) obj.push('hidden_bearish');
if(support1_delta > threshold_nm && support2_delta < -threshold_nm) obj.push('hidden_bullish');
if(resistance1_delta > threshold_nm && resistance2_delta < -threshold_nm) obj.push('regular_bearish');
if(support1_delta < -threshold_nm && support2_delta > threshold_nm) obj.push('regular_bullish');
if(obj.length <= 0) obj.push('divergence')
out.push(obj);
} else {
out.push(['convergence'])
}
}
return out;
} Please let me know if you require any changes or if something isn't working as expected. |
Great. Thanks a lot, @Vultwo . I will check and get back to you later |
Hi @Vultwo I have some questions, Could you help me to clarify?
Thanks. |
Hi @phattranky,
The problem with the trading view indicator is that the states only become known after the data has past. It is hard to predict the state as the data is coming in as it easily changes the state. |
Thanks @Vultwo I will check again. Because I'm confusing the state of your example. I see it is
So I thought those are the state values. |
Hi @Vultwo I wrote an example code here https://github.com/phattranky/ta-rsi-divergence-example/blob/main/index.js Could you help me to check why it doesn't have any divergence? Any wrong with my configuration? You can try to change the |
Hi @phattranky, I have updated the readme to be more clear. The outputted values are just of the example values. I have sent you a pull request on your test example with a working example. |
Thanks @Vultwo . You're so nice. Seems it's working. Let's me test more and get back to you later |
hi devs. first thanks your amazing lib.
divergence is important of TA. could you implement to ta.js
example here
https://www.tradingview.com/script/AkWCX6pt-RSI-Divergence-Indicator-w-Alerts/
this is rsi divergence.
thanks for amazing lib.
The text was updated successfully, but these errors were encountered: