在第一个多头交易的 30 点以下进入多头条件

问题描述 投票:0回答:1
var float entryPrice = na
if (long_condition)
strategy.entry("Long", strategy.long)

if (long_condition)
entryPrice := close // Set entry price when the long condition is met

// Check if the price is below 30 pips from the initial entry
if (not na(entryPrice) and close < entryPrice - 0.0030)
strategy.entry("Long2", strategy.long)

嗨,我正在研究 pinescript。我是编码新手。我的职业是化学工程师。但制定我自己的策略。我需要这个帮助。例如,我的多头交易已在(1.0850 欧元兑美元)执行。现在价格比我的入场价格低 30 点 (1.0820)。我如何从此时开始进行另一笔多头交易。 30 点之后。请指导我,可以是入场价格的 30 点之后,也可以是进入长线后收盘,谢谢。

pine-script alpine-linux algorithmic-trading
1个回答
0
投票

默认情况下,Tradginview 将下市价订单。这意味着,只要一根柱线关闭或下一根柱线开盘(取决于您的设置),您就可以进行交易。

现在,如果你这样做:

if (not na(entryPrice) and close < entryPrice - 0.0030)
    strategy.entry("Long2", strategy.long)

这是有条件的市场准入。您实质上是在说,如果收盘价比首次入场价低 30 点,则进行交易。您并不是说以比第一次入场低 30 点的价格进行交易。它们是有区别的。您所做的方式将使用市价订单。但是,您需要使用limit订单指定入场价格。 为此,您可以使用

stop

函数的

limit
strategy.entry()
参数。

strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message, disable_alert) → void

limit(系列 int/float) 可选参数。订单的限价。如果指定,则订单类型为“限价”,或 “止损限价”。对于任何其他订单类型均应指定“NaN”。

stop (series int/float) 可选参数。订单的止损价。如果指定,则订单类型为“停止”,或 “止损限价”。对于任何其他订单类型均应指定“NaN”。

以下是针对您的情况如何执行此操作:

entry_target = entryPrice - 0.0030 if (not na(entryPrice)) strategy.entry("Long2", strategy.long, limit=entry_target)

注意:

您需要在某个时刻重置 entryPrice(每当交易平仓或做空等时)。

第二个注意事项是,默认情况下,您只能在同一方向进行一笔未平仓交易。如果您想要进行多笔交易(同一方向),您应该通过 

Properties

选项卡增加您的 pyramiding 数量,或在 strategy() 调用中添加设置。

strategy("My strategy", overlay=true, pyramiding=2)

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