首页 > 解决方案 > strategy.entry 上的 Pine Script 版本 4 限制参数不运行

问题描述

我正在尝试实施我的策略。策略需要下限价单(在某个价格平仓,我之前的脚本计算出来的strategy.entry)。

这是我的片段:

strategy.entry("Long " + unique_name, long=true, limit=long_take_profit, comment=tostring(long_take_profit, '#.##'), when = window())

使用这段代码,回测让我的第一个位置永远保持打开状态。

我试图以另一种方式解决下一个限价单strategy.exit

strategy.exit("TP Long", "Long " + unique_name, limit=long_take_profit)

它运行!但是... 我不满意,因为我正在寻求实施一个金字塔策略,在同一方向上有多个条目。我想为每个人下多个具有特定限制的订单。不幸的是,strategy.exit接缝忽略from_entry参数(也许是另一个问题?)。无论如何,我想控制我的代码,我想知道为什么更简单strategy.entry的 withlimit参数不能按预期运行

感谢您的贡献

[更新] 这是我的完整脚本

//@version=4
strategy(title="Cross Checks", pyramiding=5, shorttitle="CC", max_bars_back=200, default_qty_type=strategy.percent_of_equity, default_qty_value=5, initial_capital=100000, calc_on_every_tick=true, calc_on_order_fills=true, process_orders_on_close=true, commission_type=strategy.commission.percent, commission_value=0.00, slippage = 2, overlay=false)

// Getting inputs
   
window() => true 

fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
src = input(title="Source", type=input.source, defval=close)

// Calculating
fast_ema = ema(src, fast_length)
slow_ma = sma(src, slow_length)

ema = ema(close, 100)
rsi = rsi(close, 14)
cci = cci(close, 14)

spread = 0.0009  
profit_perc = 0.0100

cross_long = crossover(fast_ema, slow_ma)
check_ema_long = low > ema and ema > ema[1]
check_rsi_long = rsi < 90 and rsi > 40 and rsi > rsi[1]
check_cci_long = cci < 180 and cci > -50 and cci > cci[1]
check_security_long = hist_security[1] > hist_security[2]

cross_short = crossunder(fast_ema, slow_ma)
check_ema_short = high < ema and ema < ema[1]
check_rsi_short = rsi < 60 and rsi > 20 and rsi < rsi[1]
check_cci_short = cci > -180 and cci < 50 and cci < cci[1]

check_spread = spread < profit_perc

condition_entry_long = cross_long and check_rsi_long and check_cci_long and check_ema_long and check_spread
condition_entry_short = cross_short and check_rsi_short and check_cci_short and check_ema_short and check_spread

unique_name = tostring(timenow)

// take profit strategy
long_take_profit = close * (1 + profit_perc - spread)
short_take_profit = close * (1 - profit_perc + spread)

if condition_entry_long
    strategy.entry("Long " + unique_name, long=true, limit=long_take_profit, comment=tostring(long_take_profit, '#.##'), when = window())

if condition_entry_short
    strategy.entry("Short " + unique_name, long=false, limit=short_take_profit, comment=tostring(short_take_profit, '#.##'), when = window())

标签: pine-script

解决方案


推荐阅读