Ahsan Abbasi
Ahsan Abbasi

Reputation: 1

how to define "Current price crosses above Ema"...?

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

//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)

ema1 =ta.ema(close, 14)
price1 =input.price(defval=0)

plot(ema1, color=color.new(color.red, 14), linewidth=2, offset=2)
plot(price1)

longCondition = ta.crossover(input.price(defval=0), ta.ema(close, 14))
if (longCondition)
    strategy.entry("Long", strategy.long)

shortCondition = ta.crossunder(input.price(defval=0), ta.ema(close, 14))
if (shortCondition)
    strategy.entry("Short", strategy.short)

Upvotes: 0

Views: 3419

Answers (1)

vitruvius
vitruvius

Reputation: 21292

The built-in variable close refers to current price in real time. You can see that on your chart if you hover your mouse over the last bar and check the close price.

Upvotes: 1

Related Questions