Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS1056

error this can only be used inside a method.

#What it means

this is the object a method works on. It exists only inside a method (method Zone.width() { return this.top - this.bottom }); in a function or at the top level there is no such object.

#Typical cause

  • this in a function declared with function or =>.
  • A method body copied out of a method.

#How to fix it

Turn the function into a method of the type it works on (method float.twice() => this * 2), or pass the value as a parameter. See User types, enums and methods.

#Example

ChartScriptError: CS1056
//@chartscript 1
indicator("Double")
function twice() {
    return this * 2
}
plot(twice())

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Double")
method float.twice() => this * 2
plot(close.twice())
  • CS1027 — name is reserved and cannot be used as a name.
  • CS2603 — A method needs the type of the object it works on: example.

The ChartScript documentation is in English for now; translations will follow.