尝试在tradingview中使用跟踪止损

2024-10-04 03:28:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让tradingview正确地进行尾随止损,但我正在努力找出如何计算止损。即使价格没有回落,它似乎也太快地退出了交易(下一小节)

以下是我对oanda v20所做的

                response = api.order.market(account,
                                    instrument=instrument,
                                    units=units,
                                    takeProfitOnFill={
                                        'distance': tp.PriceValue(df['M5']['atr'][-1] * 16).value},
                                    trailingStopLossOnFill={
                                        'distance': tp.PriceValue(df['M5']['atr'][-1] * 2).value})

正如你所看到的,我以16*atr的回吐利润购买 我正在做一个2*atr的尾随停止

从交易角度来看,我目前有以下几点:


strategy.entry("LONG", strategy.long, when = crossover(rsi, 10) and close > ema100)
strategy.close("LONG", (low < (strategy.position_avg_price - (atrval * 4))) or (high > (strategy.position_avg_price + (atrval * 16))))
strategy.entry("SHORT", strategy.short, when = crossunder(rsi, 90) and close < ema100)
strategy.close("SHORT", (high > (strategy.position_avg_price + (atrval * 4))) or (low < (strategy.position_avg_price - (atrval *16))))

这是我的静态停止和tp,我知道我需要使用strategy.exit进行跟踪,所以我尝试使用类似的方法

strategy.entry("LONG", strategy.long, when = crossover(rsi, 10) and close > ema100)
strategy.close("LONG", (high > (strategy.position_avg_price + (atrval * 16))))
strategy.exit("Long tsl", "LONG", trail_points = atrval * 2, trail_offset = atrval * 2 )
strategy.entry("SHORT", strategy.short, when = crossunder(rsi, 90) and close < ema100)
strategy.close("SHORT", (low < (strategy.position_avg_price - (atrval *16))))
strategy.exit("Short tsl", "SHORT", trail_points = atrval * 2, trail_offset = atrval * 2 )

但它似乎不起作用,你知道如何正确地进行尾随停止吗


Tags: andclosepositionpricelongavgshortwhen