1
votes

I am trying to create a simple backtesting code in Tradingview. The idea is to buy once price breaks above 40 weekly moving average and sell when price closes below 40 weekly MA, with a stoploss og 5%. I have gotten the crossover strategy to work, I think but it seems that my returns, depend entirely on how many contracts I trade. I just want to see the plain and simple return of the strategy, regardless of contract size. Also I am struggling to implement the stop loss into my code. This is my code so far.

//@version=4
strategy(" SMA cross")

sma40 = sma(close,40)

long = close > sma200
sell = close < sma200

start= timestamp(1995,6,1,0,0)
end= timestamp(2020,6,1,0,0)

if time>= start and time <=end
    strategy.entry("Long", strategy.long,1000, when= long)

strategy.close("Long", when = sell)

The part where is says 1000 has significant change on my return. I just want to see the neutral return form this strategy.