gpt4 book ai didi

pine-script - PineScript : Close a daytrade position at specific time of day

转载 作者:行者123 更新时间:2023-12-03 08:44:28 25 4
gpt4 key购买 nike

使用 TradingView 的 Pinescript,我如何编写回测策略以(在 1 天柱分辨率上):

1) 如果前一天的收盘价标志着买入条件,则使用市价单在开盘时建立多头头寸。 (买入条件是,RSI(7)高于50,MACD线位于信号线上方)

2) 将止损设置为平均日范围的 1 倍 (14)

3) 在东部时间 15:55:00 下达卖单,在收市前平仓。

4) 止损触发取消另一个卖单,反之亦然(例如,这是一个 OCO 订单)

5) 每次平仓后出现买入条件时都重复此操作。

换句话说,通过这种策略,我希望在开盘时以 1 倍 ADR 止损进入日内交易,并在收盘前关闭交易。这将避免盘后时段。

感谢您慷慨地投入时间!

Edit:
here's what I have so far (as requested)
//@version=4
strategy("Trendability Strategy", overlay=true)
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
rsiLine = rsi(close, 7)
stochLine = sma(sma(stoch(close, high, low, 14),3),3)
signal = histLine > -0.05 and rsiLine > 40 and stochLine > 40 ? "buy" :
histLine <= -0.05 and rsiLine <= 40 and stochLine <= 40 ? "sell" : "none"
palette = signal == "buy" ? color.lime : signal == "sell" ? color.red :
color.black
plotbar(open, high, low, close, color=palette)

strategy.entry("Long", strategy.long, when = signal == "buy")
strategy.close("Long", when = signal == "none")

最佳答案

我不确定PineScript是否有这个功能。我有 Quantopian 的 python 代码。我不确定这是否有任何帮助。大多数经纪商都可以选择为日内交易者平掉所有(或部分)头寸,所以我认为这将是相当标准的功能。

def initialize(context):
# Algorithm will call myfunc every day 15 minutes before the market closes
schedule_function(
myfunc,
date_rules.every_day(),
time_rules.market_close(minutes=15)
)

def myfunc(context,data):
pass

如果您只是想避免盘后交易,这里是用户手册中的示例

strategy("closeEntry Demo", overlay=false)
strategy.entry("buy", true, when = open > close)
strategy.close("buy", when = open < close, qty_percent = 50, comment = "close buy entry for 50%")
plot(strategy.position_size)

关于pine-script - PineScript : Close a daytrade position at specific time of day,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61997508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com