C1616
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: July 15th, 2023

i am having trouble with the strategy tester and drawing data onto the chart

//@version = 5

strategy(title = "impulse MACD", overlay = false,
initial_capital = 100000,
default_qty_type = strategy.percent_of_equity,
default_qty_value = 100)

lengthMA = input(34)
lengthSignal = input(9)

calc_smma(src, len) =>
ema1 = ta.ema(src, lengthMA)
ema2 = ta.ema(ema1, lengthSignal)

//d = ema1 - ema2
//ema1 + d
src = hlc3

hi = calc_smma(high, lengthMA)
lo = calc_smma(low, lengthMA)
mi = calc_smma(close, lengthMA)
md = (mi > hi) ? (mi - hi) : (mi < lo) ? (mi + 10) : na

sb = ta.sma(md, lengthSignal)
sh = md - sb
mcd = close > mi ? close > hi ? color.lime : color.green : close < lo ? color.red : color.orange

//detect crosses

upCross = ta.crossover(md, sb)
downCross = ta.crossunder(md, sb)

// Enter long trade
if upCross and ta.crossover(md - sb, 2) and strategy.position_size == 0
strategy.entry(id = "LONG", direction = strategy.long)

// Enter short trade
if downCross and ta.crossover(md - sb, 2) and strategy.position_size == 0
strategy.entry(id = "SHORT", direction = strategy.short)

//define pull outs for short positions
pullShort = strategy.position_size == 1 and upCross
PullEarlyShort = strategy.position_size == 1 and md > md[1]

//define pullouts for long positions
pullLong = strategy.position_size == 1 and downCross
PullEarlyLong = strategy.position_size == 1 and md < md[1]

if pullLong
strategy.close(id = "LONG", qty_percent = 100)

if PullEarlyLong

strategy.close(id = "LONG", qty_percent = 45)


if pullShort
strategy.close(id = "SHORT", qty_percent = 100)

if PullEarlyShort
strategy.close(id = "SHORT", qty_percent = 45)

hline(0, color = color.rgb(128,128,128), linewidth = 2, title = "MidLine")
plot(md, color = mcd, linewidth = 2, title = "Impulse MACD")
plot(sh, color = color.blue, linewidth = 2, title = "impulse Histogram", style = plot.style_line)
plot(sb, color = color.maroon, linewidth = 2, title = "Impulse MACD Signal")
ebc = input(false, title = "enable bar colors")
barcolor(ebc ? mcd : na)

it wont draw the data onto the chart and the strategy tester is saying that there is giving me an error message

Return to “General Trading Discussions”