0% found this document useful (0 votes)
84 views3 pages

BTC Script 1

Uploaded by

Karl Max
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views3 pages

BTC Script 1

Uploaded by

Karl Max
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//@version=5

strategy("Customizable Buy and Sell Strategy", overlay=true)

// Input Parameters
lengthATR = input.int(14, title="ATR Length")
atrMultiplier = input.float(1.5, title="ATR Multiplier for Target")
slMultiplier = input.float(1.0, title="ATR Multiplier for SL")
trailOffset = input.float(1.0, title="Trailing Offset in ATR")

// Customizable Target and SL for Buying


customTargetLong = input.float(0, title="Custom Target for Long (in points)",
step=0.1)
customSLLong = input.float(0, title="Custom SL for Long (in points)", step=0.1)
useCustomTargetLong = input.bool(true, title="Enable Custom Target for Long")
useCustomSLLong = input.bool(true, title="Enable Custom SL for Long")
useTrailSLLong = input.bool(true, title="Enable Trailing SL for Long")

// Customizable Target and SL for Selling


customTargetShort = input.float(0, title="Custom Target for Short (in points)",
step=0.1)
customSLShort = input.float(0, title="Custom SL for Short (in points)", step=0.1)
useCustomTargetShort = input.bool(true, title="Enable Custom Target for Short")
useCustomSLShort = input.bool(true, title="Enable Custom SL for Short")
useTrailSLShort = input.bool(true, title="Enable Trailing SL for Short")

// RSI Filter Parameters


rsiLength = input.int(14, title="RSI Length")
rsiOversold = input.int(30, title="RSI Oversold Level")
rsiOverbought = input.int(70, title="RSI Overbought Level")

// Volume Confirmation Parameters


volumeLength = input.int(20, title="Volume Moving Average Length")
volumeMultiplier = input.float(1.5, title="Volume Threshold Multiplier")

// Calculate Indicators
atr = ta.atr(lengthATR)
rsi = ta.rsi(close, rsiLength)
volumeMA = ta.sma(volume, volumeLength)

// Buy Condition based on Shivji ka Robot


ma_length = input.int(50, title="Moving Average Length")
ma = ta.sma(close, ma_length)
buyCondition = ta.crossover(close, ma) and rsi < rsiOverbought and volume >
volumeMA * volumeMultiplier

// Sell Condition for Short Selling


sellCondition = ta.crossunder(close, ma) and rsi > rsiOversold and volume >
volumeMA * volumeMultiplier

// Initialize variables for tracking


var float entryPriceLong = na
var float trailSLLong = na
var float targetPriceLong = na

var float entryPriceShort = na


var float trailSLShort = na
var float targetPriceShort = na

// Long Entry
if (buyCondition)
entryPriceLong := close
targetPriceLong := useCustomTargetLong ? entryPriceLong + customTargetLong :
entryPriceLong + (atr * atrMultiplier)
trailSLLong := useCustomSLLong ? entryPriceLong - customSLLong : entryPriceLong
- (atr * slMultiplier)

// Execute Buy Order


strategy.entry("Buy Order", strategy.long)

// Plot Entry Price


label.new(bar_index, close, "Buy Order", color=color.green,
style=label.style_label_down, textcolor=color.white)

// Update Trailing SL for Long


if (not na(entryPriceLong))
if (useTrailSLLong and close > entryPriceLong + (atr * trailOffset))
trailSLLong := math.max(trailSLLong, close - (atr * slMultiplier))

// Long Sell Condition (exit when trailing SL is hit or target reached)


sellConditionLong = close <= trailSLLong or close >= targetPriceLong

if (sellConditionLong)
// Execute Sell Order for Long
strategy.exit("Sell Exit Long", from_entry="Buy Order", limit=targetPriceLong,
stop=trailSLLong)

// Plot Sell Condition for Long


label.new(bar_index, close, "Sell Order Long", color=color.red,
style=label.style_label_up, textcolor=color.white)

// Short Entry
if (sellCondition)
entryPriceShort := close
targetPriceShort := useCustomTargetShort ? entryPriceShort -
customTargetShort : entryPriceShort - (atr * atrMultiplier)
trailSLShort := useCustomSLShort ? entryPriceShort + customSLShort :
entryPriceShort + (atr * slMultiplier)

// Execute Short Order


strategy.entry("Sell Order", strategy.short)

// Plot Entry Price


label.new(bar_index, close, "Sell Order", color=color.red,
style=label.style_label_down, textcolor=color.white)

// Update Trailing SL for Short


if (not na(entryPriceShort))
if (useTrailSLShort and close < entryPriceShort - (atr * trailOffset))
trailSLShort := math.min(trailSLShort, close + (atr * slMultiplier))

// Short Sell Condition (exit when trailing SL is hit or target reached)


sellConditionShort = close >= trailSLShort or close <= targetPriceShort

if (sellConditionShort)
// Execute Buy Order to cover Short
strategy.exit("Cover Short Exit", from_entry="Sell Order",
limit=targetPriceShort, stop=trailSLShort)
// Plot Sell Condition for Short
label.new(bar_index, close, "Cover Short Order", color=color.green,
style=label.style_label_up, textcolor=color.white)

// Plotting
plot(ma, color=color.blue, title="Moving Average")
plot(entryPriceLong, style=plot.style_cross, color=color.green, title="Entry Price
Long")
plot(targetPriceLong, color=color.red, title="Target Price Long")
plot(trailSLLong, color=color.orange, title="Trailing Stop-Loss Long")
hline(rsiOversold, "RSI Oversold", color=color.green)
hline(rsiOverbought, "RSI Overbought", color=color.red)
plot(rsi, color=color.purple, title="RSI")
plot(volumeMA, color=color.orange, title="Volume MA")

// Background colors for buy and sell conditions


bgcolor(buyCondition ? color.new(color.green, 90) : na)
bgcolor(sellCondition ? color.new(color.red, 90) : na)

// Alerts
alertcondition(buyCondition, title="Buy Alert", message="Buy Signal: Price crossed
above the moving average, RSI is below overbought, high volume confirmed.")
alertcondition(sellCondition, title="Sell Alert", message="Sell Signal: Price
crossed below the moving average, RSI is above oversold, high volume confirmed.")

You might also like