Untitled

 avatar
unknown
plain_text
4 months ago
4.0 kB
8
Indexable
//@version=5
strategy('RSN RSI MOMENTUM SCALP STRATEGY', overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// ** ---> Inputs ------------- {
var bool positive       = false
var bool negative       = false
string RSI_group        = "RSI Settings"
string visual           = "Visuals" 

// RSI and Momentum Settings
int Len2                = input(14, "RSI Length", inline = "rsi", group = RSI_group)
int rsi_buy_threshold   = input(52, "RSI Buy Threshold", inline = "rsi1", group = RSI_group)  // Alım için RSI 52
int rsi_sell_threshold  = input(32, "RSI Sell Threshold", inline = "rsi2", group = RSI_group) // Satım için RSI 32

// Take-profit settings
float take_profit_percent = input.float(2.0, "Take Profit (%)", inline="tp", group = "Risk Management", step=0.1)  // Take-profit parameter

// Date range input parameters (without STRAT and END labels)
var string date_group = "Date Range"
start_year             = input(2024, "Year", inline = "start", group = date_group)
start_month            = input(1, "Month", inline = "start", group = date_group)
start_day              = input(1, "Day", inline = "start", group = date_group)

end_year               = input(2025, "Year", inline = "end", group = date_group)
end_month              = input(12, "Month", inline = "end", group = date_group)
end_day                = input(31, "Day", inline = "end", group = date_group)

start_date             = timestamp(start_year, start_month, start_day, 0, 0)  // Start date parameter
end_date               = timestamp(end_year, end_month, end_day, 23, 59)  // End date parameter
inDateRange            = (time >= start_date and time <= end_date)

// Apply RSI calculation
rsi = ta.rsi(close, Len2)

// ** ---> Entry Conditions ------------- {
bool filleshow = input(true, "Show highlighter ❓", inline = "002", group = visual)
color bull = input(color.rgb(76, 175, 79, 62), "Bull", inline = "002", group = visual)  // Bullish color
color bear = input(color.rgb(255, 82, 82, 66), "Bear", inline = "002", group = visual)  // Bearish color

// a = plot(filleshow ? ta.ema(high,5) : na, display = display.none, editable = false)
// b = plot(filleshow ? ta.ema(low,10) : na, style = plot.style_stepline, color = color.red, display = display.none, editable = false)

// fill(a, b, color = rsi >= rsi_buy_threshold ? bull : bear, editable = false)

//plotting 
bool showlabels = input(true, "Show Momentum ❓", inline = "001", group = visual)
color p = input(color.rgb(76, 175, 79, 62), "Positive", inline = "001", group = visual)  // Positive color
color n = input(color.rgb(255, 82, 82, 66), "Negative", inline = "001", group = visual)  // Negative color

pcondition = rsi >= rsi_buy_threshold
ncondition2 = rsi < rsi_sell_threshold

// plotshape(showlabels ? pcondition : na, title = "RSI Above 52", style = shape.labelup, color = p, location = location.belowbar, size = size.tiny, text = "Buy", textcolor = color.white)
// plotshape(showlabels ? ncondition2 : na, title = "RSI Below 32", style = shape.labeldown, color = n, location = location.abovebar, size = size.tiny, text = "Sell", textcolor = color.white)

// ** ---> Strategy Logic ------------- {

if inDateRange
    // Enter buy position only if RSI >= 52
    if pcondition
        strategy.entry("Buy", strategy.long)
        alert("MOM AL", alert.freq_once_per_bar_close)  // Buy alert
        
    // Close buy position when RSI < 32 (Sell condition)
    if ncondition2
        strategy.close("Buy")
        alert("MOM SAT", alert.freq_once_per_bar_close)  // Sell alert

    // Apply take-profit logic (2% increase in price)
    take_profit_price = strategy.position_avg_price * (1 + take_profit_percent / 100)
    
    // Exit at 2% profit
    if (close >= take_profit_price)
        strategy.exit("Take Profit", from_entry="Buy", limit=take_profit_price)  // Take profit exit condition
Editor is loading...
Leave a Comment