交易视图 Pine 回测脚本 - 基于开仓 4 根蜡烛的当日交易

问题描述 投票:0回答:1

一般问题,我正在尝试编写一个回测 Pine 脚本,该脚本将根据交易日的前四 (4) 根蜡烛出售期权 - 这里的想法是,出售的期权将在当天结束时亏钱。

所以我的第一个问题是只能使用前 4 根蜡烛来启动交易,然后使用日收盘价来查看交易是否成功?

第二个问题是,当交易从技术上讲是“卖出”开始时,我如何才能触发交易?

这里是概念 - 所以我还没有编码。

pine-script trading
1个回答
0
投票
//@version=5
strategy("First 4 Candles Strategy", shorttitle="F4C", overlay=true)

// Define your conditions for entering the trade
shouldEnterTrade() =>
    // Replace this condition with your logic
    // For example, check if it's the first 4 candles of the day
    hour < 4

// Define your conditions for exiting the trade
shouldExitTrade() =>
    // Replace this condition with your logic
    // For example, check if it's the end of the day
    hour == 14 and minute == 30

// Entry condition
if (shouldEnterTrade())
    strategy.entry("Sell", strategy.short)

// Exit condition
if (shouldExitTrade())
    strategy.close("Sell")

// Plot a shape on the chart to visualize entry points
plotshape(shouldEnterTrade(), color=color.red, style=shape.triangledown, size=size.small)

请记住将检测前四根蜡烛并计算何时退出交易的真实理由替换为占位符情况。考虑更改时区设置(

timezone
参数)以对应您的交易时间。

© www.soinside.com 2019 - 2024. All rights reserved.