Me@PSC
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: November 22nd, 2023

No Trades executed

Hi everyone,

I´m just doing my first steps in pine script and so I copied the script from a You-Tuber to learn how to built a strategy and to run a backtesting.

I used the version he used in his tutorial and typed in exactly his script. But there seems to be a problem with the timestamp function because the script does only run trades if the variable "timeperiod" is taken out of the script. And then it shows a few trades back in 1982. (Problaby because it´s getting back to the point when unix time starts and the instrument I chose was issued in 1982.)

If I use the script as shown below no trades are exectued at all.

This is the original link of his tutorial: https://www.youtube.com/watch?v=DJ97c8VkZaY

Does someone know what is wrong about this piece oif code?

KR
Marc

Code: Select all

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

//@version=4
// Step 1. Define strategy settings
strategy(title="Crossover EMAs", overlay = true, initial_capital = 1000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity)
fastEMA = ema(close,24)
slowEMA = ema(close, 200)

goLongCondition1 = crossover(fastEMA, slowEMA) 
timeperiod = time >= timestamp(syminfo.timezone, 2020, 12, 15, 0, 0)
notintrade = strategy.position_size <= 0
if (goLongCondition1 and timeperiod and notintrade)
    stopLoss = low * 0.97
    takeProfit = high * 1.12
    strategy.entry("long", strategy.long)
    strategy.exit("exit", "long", stop=stopLoss, limit=takeProfit)

plot(fastEMA, color = color.blue)
plot(slowEMA, color = color.white)

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: No Trades executed

Hi Marc,

I had no problem at all with the code you sent. Were there any error messages? Here's the output

Image

Return to “Pine Script Q&A”