0% found this document useful (0 votes)
19 views14 pages

Mix

Uploaded by

Pravin Mandaokar
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)
19 views14 pages

Mix

Uploaded by

Pravin Mandaokar
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/ 14

//@version=5

strategy("ADX Strategy", overlay=true)

// Input parameters
adx_length = input.int(14, title="ADX Length")
adx_threshold = input.int(25, title="ADX Threshold")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

[PDI, NDI, adx] = ta.dmi(adx_length, adx_threshold)

// Strategy logic
long_condition = adx > adx_threshold and ta.crossover(PDI, NDI)
short_condition = adx > adx_threshold and ta.crossunder(PDI, NDI)

// Plot ADX
plot(adx, color=color.blue, title="ADX")

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("ATR Strategy", overlay=true)

// Input parameters
atr_length = input.int(14, title="ATR Length")
atr_multiplier = input.float(2.0, title="ATR Multiplier")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate ATR
atr = ta.atr(atr_length)

// Strategy logic
long_condition = close > ta.sma(close, atr_length) + atr_multiplier * atr
short_condition = close < ta.sma(close, atr_length) - atr_multiplier * atr

// Plot ATR
plot(atr, color=color.blue, title="ATR")

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Bollinger Bands Strategy", overlay=true)

// Input parameters
length = input.int(20, title="BB Length")
mult = input.float(2.0, title="BB Multiplier")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Bollinger Bands


basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper_band = basis + dev
lower_band = basis - dev

// Strategy logic
long_condition = ta.crossover(close, lower_band)
short_condition = ta.crossunder(close, upper_band)

// Plot Bollinger Bands


plot(upper_band, color=color.blue, title="Upper Band")
plot(lower_band, color=color.red, title="Lower Band")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Chaikin Money Flow Strategy", overlay=true)

// Input parameters
length = input.int(20, title="Length")
overbought_level = input.float(0.3, title="Overbought Level")
oversold_level = input.float(-0.3, title="Oversold Level")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")
// Calculate Money Flow Multiplier (MFM) and Money Flow Volume (MFV)
typical_price = (high + low + close) / 3
money_flow = typical_price * volume
positive_money_flow = ta.sma(money_flow * (ta.change(typical_price) > 0 ? 1 : 0),
length)
negative_money_flow = ta.sma(money_flow * (ta.change(typical_price) < 0 ? 1 : 0),
length)

// Calculate Chaikin Money Flow (CMF)


cmf_value = (positive_money_flow - negative_money_flow) / ta.sma(volume, length)

// Strategy logic
long_condition = ta.crossover(cmf_value, oversold_level)
short_condition = ta.crossunder(cmf_value, overbought_level)

// Plot CMF
plot(cmf_value, color=color.blue, title="CMF")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = high + target_points
long_stop_loss = low - stop_loss_points
short_target = low - target_points
short_stop_loss = high + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Elliott Wave Strategy", overlay=true)

// Input parameters
fib_level = input.float(1.618, title="Fibonacci Level")
length = input.int(10, "Length of Historical Candles")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Fibonacci retracement levels


wave_high = ta.highest(high, 10)
wave_low = ta.lowest(low, 10)
wave_range = wave_high - wave_low
fib_0 = wave_high
fib_100 = wave_low
fib_1618 = fib_0 - fib_level * wave_range

// Plot Fibonacci retracement levels


plot(fib_0, color=color.blue, title="Fib 0.0")
plot(fib_100, color=color.red, title="Fib 100.0")
plot(fib_1618, color=color.green, title="Fib 161.8")

// Strategy logic
long_condition = ta.crossover(close, fib_1618)
short_condition = ta.crossunder(close, fib_1618)
// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = close + target_points
long_stop_loss = close - stop_loss_points
short_target = close - target_points
short_stop_loss = close + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Combining 3 indicator Strategy", overlay=true)

fast_ema_L = input.int(defval=9, title='Fast EMA Length', group='EMA')


slow_ema_L = input.int(defval=21, title='Slow EMA Length', group='EMA')

fast_macd_L = input.int(defval=12, title='Fast MACD Length', group='MACD')


slow_macd_L = input.int(defval=26, title='Slow MACD Length', group='MACD')
siglen = input.int(defval=9, title='Signal Smoothing MACD', group='MACD')

rsi_L = input.int(defval=7, title='RSI Length', group='RSI')


rsi_val_gt = input.int(defval=60, title='RSI greater than', group='RSI')
rsi_val_lt = input.int(defval=40, title='RSI lesser than', group='RSI')

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

fast_ema = ta.ema(close, fast_ema_L)


slow_ema = ta.ema(close, slow_ema_L)

[macdLine, signalLine, histLine] = ta.macd(close, fast_macd_L, slow_macd_L, siglen)

rsi = ta.rsi(close, rsi_L)

long_condition = ta.crossover(fast_ema, slow_ema) and signalLine > macdLine and rsi


> rsi_val_gt
short_condition = ta.crossunder(fast_ema, slow_ema) and signalLine < macdLine and
rsi < rsi_val_lt

plot(macdLine, title='MACD Line', color=color.blue)


plot(signalLine, title='MACD Signal Line', color=color.orange)

plot(fast_ema, title='Fast EMA', color=color.aqua)


plot(slow_ema, title='Slow EMA', color=color.yellow)

plot(rsi, title='RSI', color=color.lime)

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Fibonacci Retracement Strategy", overlay=true)

// Input parameters
fib_levels = input.bool(true, title="Show Fibonacci Levels")
n = input.int(20, title="Number of Historical Candles")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Fibonacci levels


high_price = ta.highest(close, 20)
low_price = ta.lowest(close, 20)
range_ = high_price - low_price
fib618 = high_price - range_ * 0.618
fib382 = high_price - range_ * 0.382

// Strategy logic
long_condition = ta.crossover(close, fib618)
short_condition = ta.crossunder(close, fib382)

// Plot Fibonacci levels


plot(fib_levels ? fib618 : na , "61.8%", color=color.blue, trackprice=true)
plot(fib_levels ? fib382 : na , "38.2%", color=color.red, trackprice=true)

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Half Trend Strategy", overlay=true)

// Input parameters
ma_length = input.int(20, title="Moving Average Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Moving Average


ma = ta.sma(close, ma_length)
// Determine trend
trend_up = close > ma
trend_down = close < ma

// Strategy logic
long_condition = trend_up and trend_up[1] == false
short_condition = trend_down and trend_down[1] == false

// Plot Moving Average


plot(ma, color=color.blue, title="Moving Average")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)
strategy("Half Trend Strategy", overlay=true)

// Input parameters
ma_length = input.int(20, title="Moving Average Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Moving Average


ma = ta.sma(close, ma_length)

// Determine trend
trend_up = close > ma
trend_down = close < ma

// Strategy logic
long_condition = trend_up and trend_up[1] == false
short_condition = trend_down and trend_down[1] == false

// Plot Moving Average


plot(ma, color=color.blue, title="Moving Average")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points
// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Half Trend Strategy", overlay=true)

// Input parameters
ma_length = input.int(20, title="Moving Average Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Moving Average


ma = ta.sma(close, ma_length)

// Determine trend
trend_up = close > ma
trend_down = close < ma

// Strategy logic
long_condition = trend_up and trend_up[1] == false
short_condition = trend_down and trend_down[1] == false

// Plot Moving Average


plot(ma, color=color.blue, title="Moving Average")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Ichimoku Cloud Strategy", overlay=true)

// Input parameters
conversion_period = input.int(9, title="Conversion Line Period")
base_period = input.int(26, title="Base Line Period")
lagging_span2_period = input.int(52, title="Lagging Span 2 Period")
displacement = input.int(26, title="Displacement")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Ichimoku Cloud


tenkan_sen = ta.sma((high + low) / 2, conversion_period)
kijun_sen = ta.sma((high + low) / 2, base_period)
senkou_span_a = ((tenkan_sen + kijun_sen) / 2)[displacement]
senkou_span_b = ta.sma((high + low) / 2, lagging_span2_period)[displacement]

// Strategy logic
long_condition = close > senkou_span_a and close > senkou_span_b
short_condition = close < senkou_span_a and close < senkou_span_b

// Plot Ichimoku Cloud


plot(senkou_span_a, color=color.blue, title="Senkou Span A")
plot(senkou_span_b, color=color.red, title="Senkou Span B")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Moving Averages Strategy", overlay=true)

// Input parameters
fast_length = input.int(9, title="Fast MA Length")
slow_length = input.int(21, title="Slow MA Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate moving averages


fast_ma = ta.sma(close, fast_length)
slow_ma = ta.sma(close, slow_length)

// Strategy logic
long_condition = ta.crossover(fast_ma, slow_ma)
short_condition = ta.crossunder(fast_ma, slow_ma)

// Plot moving averages


plot(fast_ma, color=color.blue, title="Fast MA")
plot(slow_ma, color=color.red, title="Slow MA")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)
strategy("MACD Strategy", overlay=true)

// Input parameters
fast_length = input.int(12, title="Fast EMA Length")
slow_length = input.int(26, title="Slow EMA Length")
signal_length = input.int(9, title="Signal Line Length")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate MACD
[macd_line, signal_line, _] = ta.macd(close, fast_length, slow_length,
signal_length)

// Strategy logic
long_condition = ta.crossover(macd_line, signal_line)
short_condition = ta.crossunder(macd_line, signal_line)

// Plot MACD
plot(macd_line, color=color.blue, title="MACD Line")
plot(signal_line, color=color.red, title="Signal Line")

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("OBV Strategy", overlay=true)

// Input parameters
length = input.int(14, title="Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Initialize OBV variable


var float obv_value = na

// Calculate OBV
obv_value := nz(obv_value[1]) + (close - close[1]) * (volume > volume[1] ? 1 :
volume < volume[1] ? -1 : 0)

// Strategy logic
long_condition = ta.crossover(obv_value, ta.sma(obv_value, length))
short_condition = ta.crossunder(obv_value, ta.sma(obv_value, length))

// Plot OBV
plot(obv_value, color=color.blue, title="OBV")
// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Parabolic SAR Strategy", overlay=true)

// Input parameters
af_start = input.float(0.02, title="Acceleration Factor Start")
af_increment = input.float(0.02, title="Acceleration Factor Increment")
af_maximum = input.float(0.2, title="Acceleration Factor Maximum")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Parabolic SAR


sar = ta.sar(af_start, af_increment, af_maximum)

// Strategy logic
long_condition = ta.crossover(close, sar)
short_condition = ta.crossunder(close, sar)

// Plot Parabolic SAR


plot(sar, color=color.blue, title="Parabolic SAR", offset=-1)

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("RSI Strategy", overlay=true)

// Input parameters
rsi_length = input.int(14, title="RSI Length")
overbought_level = input.int(70, title="Overbought Level")
oversold_level = input.int(30, title="Oversold Level")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate RSI
rsi = ta.rsi(close, rsi_length)

// Strategy logic
long_condition = ta.crossover(rsi, oversold_level)
short_condition = ta.crossunder(rsi, overbought_level)

// Plot RSI
plot(rsi, color=color.blue, title="RSI")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Stochastic Oscillator Strategy", overlay=true)

// Input parameters
k_period = input.int(14, title="K Period")
d_period = input.int(3, title="D Period")
overbought_level = input.int(80, title="Overbought Level")
oversold_level = input.int(20, title="Oversold Level")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Stochastic Oscillator


k = ta.stoch(close, high, low, k_period)
d = ta.sma(k, d_period)

// Strategy logic
long_condition = ta.crossover(k, d) and k < oversold_level
short_condition = ta.crossunder(k, d) and k > overbought_level

// Plot Stochastic Oscillator


plot(k, color=color.blue, title="K")
plot(d, color=color.red, title="D")

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("TEMA Strategy", overlay=true)

// Input parameters
length = input.int(14, title="TEMA Length")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate TEMA
ema1 = ta.ema(close, length)
ema2 = ta.ema(ema1, length)
ema3 = ta.ema(ema2, length)
tema = 3 * ema1 - 3 * ema2 + ema3

// Strategy logic
long_condition = ta.crossover(close, tema)
short_condition = ta.crossunder(close, tema)

// Plot TEMA
plot(tema, color=color.blue, title="TEMA")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)

if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("EMA, VWAP, Volume Strategy", overlay=true, process_orders_on_close=true)

// Inputs
emaLength = input.int(21, title="EMA Length")
vwapSource = input.source(defval=hlc3, title='VWAP Source')
stopLossPoints = input.float(100, title="Stop Loss (points)")
targetPoints = input.float(200, title="Target (points)")
session = input.session("0950-1430", title='Only take entry during')
exit = input.session(defval='1515-1525', title='Exit Trade')

tradein = not na(time(timeframe.period, session))


exit_time = not na(time(timeframe.period, exit))
// Calculate indicators
ema = ta.ema(close, emaLength)
vwapValue = ta.vwap(vwapSource)

// Entry Conditions
longCondition = close > vwapValue and close > ema and volume > volume[1] and close
> open and tradein
shortCondition = close < vwapValue and close < ema and volume > volume[1] and open
> close and tradein

// Exit Conditions
longExitCondition = ta.crossunder(close, vwapValue) or ta.crossunder(close, ema) or
close - strategy.position_avg_price >= targetPoints or close -
strategy.position_avg_price <= -stopLossPoints or exit_time
shortExitCondition = ta.crossover(close, vwapValue) or ta.crossover(close, ema) or
strategy.position_avg_price - close >= targetPoints or strategy.position_avg_price
- close <= -stopLossPoints or exit_time

// Plotting
plot(vwapValue, color=color.blue, title="VWAP")
plot(ema, color=color.green, title="EMA")

// Strategy
if longCondition
strategy.entry("Long", strategy.long)

if shortCondition
strategy.entry("Short", strategy.short)

if longExitCondition
strategy.close('Long', immediately=true)

if shortExitCondition
strategy.close("Short", immediately=true)

strategy("VWAP Strategy", overlay=true)

// Input parameters
length = input.int(14, title="VWAP Length")

target_points = input.int(100, title="Target Points")


stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate VWAP
vwap = ta.vwap(volume, length)

// Strategy logic
long_condition = ta.crossover(close, vwap)
short_condition = ta.crossunder(close, vwap)

// Plot VWAP
plot(vwap, color=color.blue, title="VWAP")

// Strategy entry and exit


if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Calculate target and stop loss levels
long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

strategy("Williams %R Strategy", overlay=true)

// Input parameters
length = input.int(14, title="Williams %R Length")
overbought_level = input.int(-20, title="Overbought Level")
oversold_level = input.int(-80, title="Oversold Level")
target_points = input.int(100, title="Target Points")
stop_loss_points = input.int(50, title="Stop Loss Points")

// Calculate Williams %R
hh = ta.highest(high, length)
ll = ta.lowest(low, length)
williams_r = (hh - close) / (hh - ll) * -100

// Strategy logic
long_condition = williams_r < oversold_level
short_condition = williams_r > overbought_level

// Plot Williams %R
plot(williams_r, color=color.blue, title="Williams %R")

// Strategy entry
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

// Calculate target and stop loss levels


long_target = strategy.position_avg_price + target_points
long_stop_loss = strategy.position_avg_price - stop_loss_points
short_target = strategy.position_avg_price - target_points
short_stop_loss = strategy.position_avg_price + stop_loss_points

// Strategy exit
strategy.exit("Long Exit", "Long", limit=long_target, stop=long_stop_loss)
strategy.exit("Short Exit", "Short", limit=short_target, stop=short_stop_loss)

You might also like