Tireless Coder
Tireless Coder

Reputation: 93

Pinescript: Compilation error. Script could not be translated from: |B|input length1 = 10|E||B|

Can someone explain what is wrong with this code? similar issues do not solve my problem

Issue: Compilation error. Script could not be translated from: |B|input length1 = 10|E||B|

Code:

// Define the input parameters
input length1 = 10
input length2 = 20

// Calculate the SMAs
sma1 = sma(close, length1)
sma2 = sma(close, length2)

// Calculate the current crossover
var crossover = sma1 > sma2

// Define the alert conditions
alertcondition(crossover, title="SMA Crossover", message="The 10 day SMA has crossed above the 20 day SMA.")

// Plot the SMAs on the chart
plot SMA1 = sma1
plot SMA2 = sma2

Upvotes: 0

Views: 535

Answers (1)

G.Lebret
G.Lebret

Reputation: 3118

You should read the pinescript manual, you could learn a lot and avoid the littles errors in your code.
On pinscript v5, your code should look like this :

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

//@version=5
indicator("My script")

// Define the input parameters
length1 = input.int(10,"Length 1")
length2 = input.int(20,"Length 2")

// Calculate the SMAs
sma1 = ta.sma(close, length1)
sma2 = ta.sma(close, length2)

// Calculate the current crossover
crossover = sma1 > sma2

// Define the alert conditions
alertcondition(crossover, title="SMA Crossover", message="The 10 day SMA has crossed above the 20 day SMA.")

// Plot the SMAs on the chart
plot(sma1, "SMA1")
plot(sma2, "SMA2")

Upvotes: 1

Related Questions