Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Uniden202
- //@version=5
- indicator('Moving Average Cross and RSI', overlay=false, precision=0)
- //variable
- var indicatorshort = 0.0
- var indicatorlong = 0.0
- // Define variables for MAC
- ema8 = ta.ema(close, 10)
- ema24 = ta.ema(close, 30)
- // Plot EMAs
- plot(ema8, color=color.rgb(255, 82, 82, 100))
- plot(ema24, color=color.rgb(33, 150, 243, 100))
- // Define condition to long
- longcondition = ema8 > ema24
- if longcondition
- indicatorlong := 100
- indicatorlong
- else
- shortcondition = ema8 < ema24
- if shortcondition
- indicatorlong := na
- indicatorlong
- // Define Condition to Short
- Shortcondition = ema8 < ema24
- if Shortcondition
- indicatorshort := 0
- indicatorshort
- else
- shortcondition = ema8 > ema24
- if shortcondition
- indicatorshort := na
- indicatorshort
- // Entry and Exit conditions for the trade
- long_entry = ema8 > ema24 and ema8[1] <= ema24[1]
- short_entry = ema8 < ema24 and ema8[1] >= ema24[1]
- closelong = ema8 < ema24 and not long_entry[2]
- closeshort = ema8 > ema24 and not short_entry[2]
- // Plot the direction of the trade
- plot(indicatorshort, title='indicatorshort', color=color.rgb(78, 177, 81, 100))
- plot(indicatorlong, title='indicatorlong', color=color.rgb(78, 177, 81, 100))
- // Define variables for RSI
- rsi_length = 8
- rsi_source = hl2
- rsi_ema_length = 3
- // Calculate RSI
- rsi = ta.rsi(rsi_source, rsi_length)
- upper = 64
- lower = 30
- // Calculate EMA for RSI
- rsi_ema = ta.ema(rsi, rsi_ema_length)
- // Plot RSI and EMA
- plot(rsi, style=plot.style_line, color=color.rgb(32, 146, 240), linewidth=2, title='RSI')
- plot(rsi_ema, style=plot.style_line, color=color.rgb(255, 82, 82), linewidth=2, title='EMA(RSI)')
- plot(upper, title='Overbought', color=color.rgb(218, 218, 218), linewidth=1, style=plot.style_circles)
- plot(lower, title='Overbought', color=color.rgb(218, 218, 218), linewidth=1, style=plot.style_circles)
- //plot(wtCross ? wt2 : na, title = 'Buy and sell circle', color = signalColor, style = plot.style_circles, linewidth = 3, transp = 15)
- plot(indicatorshort, 'Short', color=color.rgb(240, 77, 113), style=plot.style_circles, linewidth=3, offset=1)
- plot(indicatorlong, 'Long', color=color.rgb(36, 250, 17, 17), style=plot.style_circles, linewidth=3, offset=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement