miyako.pro

RSI Algo Trader

This is a simple RSI based signal indicator. It is intended for algorithmic trading by bots, currently working one up for http://bitforex.uk.to and http://okcoin.uk.to to use this.

For the best results leave it on 1-Hour time-frame. It also works best on bitcoin and stocks , not so much oil             . GBP/USD             and AUD/USD             it fairs well too.

When RSI touches 70 it gives a Buy signal and when RSI touches 30 it gives a sell signal. The position is then held out until an opposite signal has been given. If the back-testing shows poor results but looks as though the inverse would be good, there is an easy toggle in the settings to flip it. Also in the code is a nifty             method to pragmatically keep a variable's value from resetting each candle until later changed.

MSFT             Stock:
snapshot
Remove from Favorite Scripts Add to Favorite Scripts
study("RSI Algo", overlay=true)
myPeriod = input(defval=14, type=integer, title="Period")
myThresholdUp = input(defval=70, type=float, title="Upper Threshold")
myThresholdDn = input(defval=30, type=float, title="Lower Threshold")
myAlgoFlipToggle = input(defval=false, type=bool, title="Imverse Algorthim")
myLineToggle = input(defval=true, type=bool, title="Show Lines")
myLabelToggle = input(defval=true, type=bool, title="Show Labels")
myRSI=rsi(close, myPeriod)
buy = myAlgoFlipToggle ? falling(myRSI,1) and cross(myRSI, myThresholdDn) : rising(myRSI, 1) and cross(myRSI,myThresholdUp)
sell = myAlgoFlipToggle ? rising(myRSI, 1) and cross(myRSI,myThresholdUp) : falling(myRSI,1) and cross(myRSI, myThresholdDn)
myPosition = buy==1 ? 0 : sell==1 or myPosition[1]==1 ? 1 : 0
trendColor = buy ? red : sell ? green : na
plot(myLineToggle ? buy and myPosition[1]==1 ? low - 0.004: sell and myPosition[1]==0 ? high + 0.004 : na : na, color=trendColor, style=line, linewidth=4, editable=false)
plotshape(myLabelToggle ? buy and myPosition[1]==1 ? low - 0.005 : na : na, style=shape.labelup, location=location.absolute, text="Buy", transp=0, textcolor = white, color=black, editable=false)
plotshape(myLabelToggle ? sell and myPosition[1]==0 ? high + 0.005 : na : na, style=shape.labeldown, location=location.absolute, text="Sell", transp=0, textcolor = white, color=black, editable=false)
Hausky
a year ago
Have you just back-tested manually or is it in the indicator?
Reply
miyako.pro Hausky
a year ago
I backtested manually here on tradingview by drawing a trendline to each point and recording the data, as well as in the cTrader platform.
 
Reply
miyako.pro miyako.pro
a year ago
Backtest in cTrader - http://content.screencast.com/users/kitsune948609/folders/Snagit/media/06c850a5-e049-488e-a04e-a67eb3b29b22/07.25.2015-17.47.png
Reply
Hausky
a year ago
Ok, thx man! :)
Reply
amazing_ilya
a year ago
In this script it's assumed that we buy at the lowest point of the hourly candle and sell at the highest. Although RSI will only break 30/70 after some price movement, so we may found ourselfves on the half-way down of the candle at the moment of RSI break before selling. For example, look at 12 July - trading bot according to this script will close not at the highest point, but lower on the candle
+1 Reply
amazing_ilya amazing_ilya
a year ago
Sorry, I meant 13 July drop
Reply
miyako.pro amazing_ilya
a year ago
On tradingview it is merely a visual representation for our eyes to see. In terms of a bot, one may code it to trade exactly how they'd wish for it to open and close. Per the example and what I am working on off tradingview it will buy/sell the moment that rsi touches. The code on tradingview plots the lines about 40 forex pips from the highs and lows. Of course since it is open source on here, it may be adapted for exact specifications such as marking the positions at the OHCL values of candles rather than where I have placed them for ease of viewing.


protected override void OnTick()
{
if (rsi.Result.LastValue < 30)
{
Close(TradeType.Sell);
Open(TradeType.Buy);
}
else if (rsi.Result.LastValue > 70)
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
+1 Reply
miyako.pro miyako.pro
a year ago
Ideally it would be nice if pine script could plot at exact moments, however it is limited to OHCL +/- a number. Pine is awfully limited in many areas such as that.
+1 Reply
svyarnall
a year ago
Thank you :)
Reply
svyarnall
a year ago
Pardon me....This does not seem to work ... I don't see the buy sell prompts or the green or red lines...
Reply
TASAVANT
a year ago
Would you be able to convert this one in a strategy so the performance can be tracked?
Reply
miyako.pro TASAVANT
10 months ago
Now that I am back on tradingview, I have been considering a full rewrite of all of my scripts as strategies. When I originally wrote them all, tradingview didn't have strategies implemented.
Reply
zmm20
a year ago
The problem is... this script uses candle high as the sell price and candle low as the buy price, which is not realistic. It should use candle close price for a more realistic algo trader, in which case, the results are much worse.
Reply
amazing_ilya
10 months ago
Interesting how completely different code not based on RSI at all generates the same signals

snapshot
Reply
miyako.pro amazing_ilya
10 months ago
Many indicators are the same exact data represented in different views.
Reply
karabogerald miyako.pro
7 months ago
can you help, with creating an Alert for this. thank you.
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out