我看不懂pine脚本(超过3000个订单)
I can't understand pine script (over 3000 order)
所以我对 pine 还很陌生,并试图围绕它展开思考
我不知道如何获取我正在设置的多头订单的入场价所以我尝试了这个但是我得到了不正确的结果,我假设是因为当 longcond 为 true 时平均头寸价格不断变化
strategy("wtf", overlay = true, initial_capital = 100)
ema50 = ema(close, 50)
ema200 = ema(close, 200)
plot(ema50)
plot(ema200)
TP = 0.0
SL = 0.0
longCond = (ema50 > ema200)
if (longCond)
strategy.entry("long", strategy.long)
TP := strategy.position_avg_price * 1.2
SL := strategy.position_avg_price * 0.8
strategy.exit("close", "long", limit = TP, stop = SL)```
how can I set an order and take the entry price to then set a limit and stop order for TP and SL
默认情况下,策略订单将在开盘时放置。您可以将 strategy.position_size
与其之前的值进行比较,以了解您是否已开新的多头头寸并存储开仓价。
//@version=5
strategy("wtf", overlay = true, initial_capital = 100)
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
TP = 0.0
SL = 0.0
longCond = (ema50 > ema200)
if (longCond)
strategy.entry("long", strategy.long)
TP := strategy.position_avg_price * 1.2
SL := strategy.position_avg_price * 0.8
var buyPrice = 0.0
buyPrice := ta.valuewhen((strategy.position_size > strategy.position_size[1]), open, 0)
strategy.exit("close", "long", limit = TP, stop = SL)
plot(buyPrice)
所以我对 pine 还很陌生,并试图围绕它展开思考
我不知道如何获取我正在设置的多头订单的入场价所以我尝试了这个但是我得到了不正确的结果,我假设是因为当 longcond 为 true 时平均头寸价格不断变化
strategy("wtf", overlay = true, initial_capital = 100)
ema50 = ema(close, 50)
ema200 = ema(close, 200)
plot(ema50)
plot(ema200)
TP = 0.0
SL = 0.0
longCond = (ema50 > ema200)
if (longCond)
strategy.entry("long", strategy.long)
TP := strategy.position_avg_price * 1.2
SL := strategy.position_avg_price * 0.8
strategy.exit("close", "long", limit = TP, stop = SL)```
how can I set an order and take the entry price to then set a limit and stop order for TP and SL
默认情况下,策略订单将在开盘时放置。您可以将 strategy.position_size
与其之前的值进行比较,以了解您是否已开新的多头头寸并存储开仓价。
//@version=5
strategy("wtf", overlay = true, initial_capital = 100)
ema50 = ta.ema(close, 50)
ema200 = ta.ema(close, 200)
TP = 0.0
SL = 0.0
longCond = (ema50 > ema200)
if (longCond)
strategy.entry("long", strategy.long)
TP := strategy.position_avg_price * 1.2
SL := strategy.position_avg_price * 0.8
var buyPrice = 0.0
buyPrice := ta.valuewhen((strategy.position_size > strategy.position_size[1]), open, 0)
strategy.exit("close", "long", limit = TP, stop = SL)
plot(buyPrice)