You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

连接FTX时无法发送限价单,求TradingView Pine Script解决方案

问题描述

我编写了一个小型TradingView Pine Script脚本,用于向FTX发送入场限价单,平仓操作手动完成。TradingView面板连接FTX后其他功能正常,但无法生成限价单。已查阅官方文档未解决,尝试过strategy.entry方法也无变化,FTX账户流动性充足,脚本代码如下:

//@version=5
strategy(title=" PERPETUAL STRATEGY)", overlay=true, shorttitle="Perpetual", default_qty_value = 0.001)
import TradingView/Strategy/3

//Get Current Price
Current_Price = request.security(syminfo.ticker, "1", close)

//Input 
distance_form_price = input.float(defval =0.6, step=0.1, title = "Distant from price") / 100


// Create SMA levels

periods = input.int(title = "Periods", defval = 4)
sma_buy = ta.sma((Current_Price * (1 - distance_form_price)), periods)
sma_sell = ta.sma((Current_Price * (1 + distance_form_price)), periods)

Buy_Limit= true
Sell_Limit= true

// Entry Strategy
if Buy_Limit
    strategy.order("Buy (Limit)", strategy.long, limit = sma_buy)

if Sell_Limit
    strategy.entry("Sell (Limit)", strategy.short, limit = sma_sell)

// Get Limit Price Line

plot(sma_buy, title = "long", color = color.aqua)
plot(sma_sell, title = "short", color = color.lime)
问题排查与解决建议
  • 修正条件触发逻辑
    你直接将Buy_Limit和Sell_Limit赋值为true,会导致脚本在每一根K线重复发送限价单。TradingView策略引擎会限制重复下单请求,甚至可能被FTX接口拒绝。需要设置单次触发的有效条件,例如当价格突破某个阈值或指标出现交叉信号时才触发下单,示例:

    // 示例:当当前价格上穿sma_buy时触发多单(仅一次)
    Buy_Limit = ta.crossover(close, sma_buy)
    // 示例:当当前价格下穿sma_sell时触发空单(仅一次)
    Sell_Limit = ta.crossunder(close, sma_sell)
    
  • 验证限价价格合理性
    当前用1分钟周期收盘价计算SMA再叠加比例,可能导致限价偏离市场价格过远,从未被触发。可以添加标签打印价格值验证:

    // 添加到脚本末尾
    label.new(bar_index, high, str.tostring(sma_buy) + "\n" + str.tostring(sma_sell), color=color.white, textcolor=color.black)
    
  • 优化策略配置与代码冗余

    • 移除未使用的import TradingView/Strategy/3,避免干扰策略逻辑。
    • 检查default_qty_value = 0.001是否符合FTX对应合约的最小下单量要求,部分合约最小下单量可能更高。
    • 确认TradingView策略设置中未勾选"仅回测",且实盘下单权限已开启。
  • 规范下单方法
    使用strategy.entry时建议配合when参数控制触发,替代单独的if判断,同时避免同时发送反向限价单(除非策略明确需要):

    strategy.entry("Buy (Limit)", strategy.long, limit=sma_buy, when=Buy_Limit)
    strategy.entry("Sell (Limit)", strategy.short, limit=sma_sell, when=Sell_Limit)
    
  • 验证API权限
    再次确认TradingView绑定的FTX API密钥是否包含下单权限,部分密钥可能仅设置了只读权限,导致无法发送订单。

内容的提问来源于stack exchange,提问作者ManekyNeko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 17:35:25