首页 > 解决方案 > Pinescript 基本问题:每天在设定的时间进行交易

问题描述

我想创建一个 Pinescript 策略,每天在东部时间下午 6 点开始交易。SL:2xATR。TP:2x 止损。

如果酒吧的收盘时间是东部时间下午 6 点,我正在努力将布尔变量设置为 TRUE。

我(显然)对 Pinescript 很陌生,希望能提供任何帮助。

最好的,

——克里斯

标签: pine-script

解决方案


这可以通过 time() 函数实现。您可以传递所需的必要会话并创建一个仅在会话开始时输入的条件。这是代码:

//@version=4
study("buy-first-bar-session", overlay=true)
sessionTime = input("1800-1800", "Session Time", type=input.session)
t = time("D", sessionTime) // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
is_first = na(t[1]) and not na(t) or t[1] < t

bgcolor(t ? color.blue : na)
plotshape(is_first, "Buy", style=shape.labelup, location=location.belowbar, textcolor=color.white, color=color.green, text="Buy")

在此处输入图像描述


推荐阅读