-2

I have the code below, is a simple strategy and somehow I manage to it up, can anyone fix this? It was working fine until I added time and ADX parts to it

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

//@version=6

strategy("SG", overlay=true)

/////SMMA
len = input(30, minval=1, title="Length")
src = input(close, title="Source")
smma = 0.0
smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
plot(smma, color=color.red)

////EMA
len1 = input(9, minval=1, title="Length")
src1 = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
out = ema(src1, len1)
plot(out, title="EMA", color=color.blue, offset=offset)
////////////////TIME

t = time(timeframe.period, "0800-2000")
time_cond = not na(t) 

/////////////ADX
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
    up = ta.change(high)
    down = -ta.change(low)
    plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
    minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
    truerange = ta.rma(ta.tr, len)
    plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
    minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
    [plus, minus]
adx(dilen, adxlen) =>
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
/////////////
    

longCondition = (out > smma ) and (close > out)
if(longCondition and time_cond and sig>20)
    strategy.entry("Longo", long=true, qty= 50000)
    strategy.exit("Exit", "Longo", qty=50000, when = open < smma ) 
    
    
shortCondiiton = (out < smma) and ( close < out)
if(shortCondiiton and time_cond and sig>20)
    strategy.entry("Shorto", long=false, qty= 50000)
    strategy.exit("Exit", "Shorto", qty= 50000, when = open > smma)

1 Answers1

0

there is no version 6 mate.

//@version=6   

try changing this

to this:

//@version=5

you may think this line is a comment however pinescript reads it !

however I noticed you still get a lot of errors when you change to 5 so I tried to correct some errors however it doesn't give long or short signals. But it's being added to chart maybe someone who knows better than me can fix it

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

//@version=5

strategy("SG", overlay=true)

/////SMMA
len = input.int(30, minval=1, title="Length")
src = close
smma = 0.0
smma := na(ta.sma(close,1)) ? ta.sma(src,len) : (ta.sma(close,1) * (len - 1) + src) / len
plot(smma, color=color.red)

////EMA
len1 = input.int(9, minval=1, title="Length")
src1 = close
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
out = ta.ema(src1, len1)
plot(out, title="EMA", color=color.blue, offset=offset)
////////////////TIME

t = time(timeframe.period, "0800-2000")
time_cond = not na(t) 

/////////////ADX
adxlen = input.int(14, title="ADX Smoothing")
dilen = input.int(14, title="DI Length")
dirmov(len) =>
    up = ta.change(high)
    down = -ta.change(low)
    plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
    minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
    truerange = ta.rma(ta.tr, len)
    plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
    minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
    [plus, minus]
adx(dilen, adxlen) =>
    [plus, minus] = dirmov(dilen)
    sum = plus + minus
    adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
/////////////
    

longCondition = (out > smma ) and (close > out)
if(longCondition and time_cond and sig>20)
    strategy.entry("Long", strategy.long, qty= 50000)
    strategy.close("Exit", qty=50000, when = open < smma )
    
shortCondiiton = (out < smma) and ( close < out)
if(shortCondiiton and time_cond and sig>20)
    strategy.entry("Short",  strategy.short, qty= 50000)
    strategy.close("Exit",  qty= 50000, when = open > smma)
Lones
  • 36
  • 6