0

所以我对松树很陌生,并试图绕着它转

我不知道如何获取我设置的多头订单的入场价格,所以我尝试了这个,但我得到了不正确的结果,我假设因为平均头寸价格在 longcond 为真时不断变化

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
4

1 回答 1

0

默认情况下,策略订单将在柱线打开时下达。您可以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)

在此处输入图像描述

于 2021-12-07T09:34:42.307 回答