首页 > 解决方案 > 强制策略仅在蜡烛收盘时进入交易

问题描述

在实际交易中,如何强制策略仅在蜡烛收盘时或蜡烛结束前的最后 5 秒内进行交易?添加什么条件或做什么?

标签: pine-script

解决方案


尝试这个:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov

//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100, calc_on_every_tick=true)

// some random entry
if barstate.islast and strategy.position_size==0 and strategy.closedtrades == 0
    strategy.entry("My Long Entry Id", strategy.long)

if time_close - timenow <= 5*1000
    strategy.close_all()

推荐阅读