Forex Master

Forex Master - free TradingView bot strategy and study.

Top FREE TradingView strategy this week!

To make our community more profitable we decided to start a series in which we will review open-source TradingView strategies. The aim of the review is to select a strategy (or a number of strategies) from TradingView and run a reality check on it, optimise them and convert into alerts, so you can set it up as a bot on Wunderbit Trading platform.

What we will provide

  • Open-strategy source

  • Strategy adjustment for particular exchange, pair and timeframe

  • Backtest

  • Revised study script that you can apply in Wunderbit Trading platform for bot trading.

This week we found a nice strategy for a 30 min timeframe. The original idea was taken from: Koi_Capital. Originally, this strategy was applied to a forex pair EUR/USD. Our team made some adjustment and improvements and we are happy to present this work to you.

You will find the strategy code here: Forex Master v4.0.

IMPORTANT!

  • This is a trend strategy and works better in the uptrend

  • This strategy is only working for long positions

  • We added the trend identifier using the EMA and SMA interaction

  • Take profit and stop loss levels were converted into percentage

  • We added inputs for the period selection, so you could see how the strategy is performing on a monthly basis.

Settings – Applicable to FTX: BTC-PERP 30 min

Revised strategy script code

You can copy this code and paste it into your TradingView.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Wunderbit Trading

//@version=4

strategy("Forex Master v4.0", overlay=true, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.07, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

Price = close

ribbon_period = input(33, "Period", step=1)

leadLine1 = ema(close, ribbon_period)
leadLine2 = sma(close, ribbon_period)

p1 = plot(leadLine1, color= #53b987, title="EMA", transp = 50, linewidth = 1)
p2 = plot(leadLine2, color= #eb4d5c, title="SMA", transp = 50, linewidth = 1)
fill(p1, p2, transp = 60, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)

Length = input(17, step=1)
Mult = input(1.7, step=0.1)
Basis = sma(Price, Length)
StdDev = Mult * stdev(Price, Length)
Upper = Basis + StdDev
Lower = Basis - StdDev

adxlen = input(1, title="ADX Smoothing")
dilen = input(77, title="DI Length")
dirmov(len) =>
	up = change(high)
	down = -change(low)
	truerange = rma(tr, len)
	plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
	minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
	[plus, minus]

adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
	[adx, plus, minus]

[sig, up, down] = adx(dilen, adxlen)

// plot(sig, color=color.red, title="ADX")
// plot(up, color=color.blue, title="+DI")
// plot(down, color=color.orange, title="-DI")

SmoothedADX1 = ema(sig, input(7))
SmoothedADX2 = ema(sig, input(14))


long_tp_inp = input(6.4, title='Long Take Profit %', step=0.1)/100
long_sl_inp = input(4.2, title='Long Stop Loss %', step=0.1)/100

long_take_level = strategy.position_avg_price * (1 + long_tp_inp)
long_stop_level = strategy.position_avg_price * (1 - long_sl_inp)


entry_long = crossover(Price, Lower) and SmoothedADX1 < SmoothedADX2 and leadLine2<leadLine1
exit_long =  crossunder(Price, Upper) and SmoothedADX1 < SmoothedADX2 and leadLine2>leadLine1


////// BACKTEST PERIOD ///////
testStartYear = input(2019, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(9999, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false


if testPeriod()
    strategy.entry("LongEntry", true, when = entry_long)
    strategy.exit("LongExit", "LongEntry", limit = long_take_level, stop = long_stop_level)
    strategy.close("LongEntry", when=exit_long)

Revised study script code

You can copy this code and paste it into your TradingView.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Wunderbit Trading

//@version=4

study("Forex Master v4.0", overlay=true)

Price = close

ribbon_period = input(33, "Period", step=1)

leadLine1 = ema(close, ribbon_period)
leadLine2 = sma(close, ribbon_period)

p1 = plot(leadLine1, color= #53b987, title="EMA", transp = 50, linewidth = 1)
p2 = plot(leadLine2, color= #eb4d5c, title="SMA", transp = 50, linewidth = 1)
fill(p1, p2, transp = 60, color = leadLine1 > leadLine2 ? #53b987 : #eb4d5c)

Length = input(17, step=1)
Mult = input(1.7, step=0.1)
Basis = sma(Price, Length)
StdDev = Mult * stdev(Price, Length)
Upper = Basis + StdDev
Lower = Basis - StdDev

adxlen = input(1, title="ADX Smoothing")
dilen = input(77, title="DI Length")
dirmov(len) =>
	up = change(high)
	down = -change(low)
	truerange = rma(tr, len)
	plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
	minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
	[plus, minus]

adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
	[adx, plus, minus]

[sig, up, down] = adx(dilen, adxlen)

// plot(sig, color=color.red, title="ADX")
// plot(up, color=color.blue, title="+DI")
// plot(down, color=color.orange, title="-DI")

SmoothedADX1 = ema(sig, input(7))
SmoothedADX2 = ema(sig, input(14))

long_tp_inp = input(6.4, title='Long Take Profit %', step=0.1)/100
long_sl_inp = input(4.2, title='Long Stop Loss %', step=0.1)/100

isEntry_Long = false
isEntry_Long := nz(isEntry_Long[1], false)

isExit_Long = false
isExit_Long := nz(isExit_Long[1], false)

entry_long =not isEntry_Long and (crossover(Price, Lower) and SmoothedADX1 < SmoothedADX2 and leadLine2<leadLine1)
entry_price_long=valuewhen(entry_long,close,0)
TP_long = entry_price_long * (1 + long_tp_inp)
SL_long = entry_price_long * (1 - long_sl_inp)
exit_long = not isExit_Long and ((crossunder(Price, Upper) and SmoothedADX1 < SmoothedADX2 and leadLine2>leadLine1) or high > TP_long or low < SL_long )

if (entry_long)
    isEntry_Long := true
    isExit_Long := false

if (exit_long)
    isEntry_Long := false
    isExit_Long := true

alertcondition(entry_long, title="Enter Long")
alertcondition(exit_long, title="Exit Long")
plotshape(series=entry_long, text="BUY", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(series=exit_long, text="EXIT BUY",style=shape.triangledown, location=location.abovebar, color=color.purple, size=size.small)

Last updated