繁体   English   中英

在同一时刻执行限价(止盈)或止损(止损)后入场

[英]Executing Entry after Limit(take profit) or Stop (Stop loss) at the exact same moment

当价格达到高于或低于先前入场点的 % 时,我试图设置入场订单(多头或空头)。

现在我正在设置退出订单以在该确切值触发退出,使用limitstop

strategy.exit("Exit Buy", from_entry = "Buy", stop=level_dn, limit=level_up)

我想要实现的是以完全相同的价格值输入新订单。

我读到在历史calc_on_order_fills是不可能实现的,因为即使使用calc_on_order_fills我们也只在 H、L、O、C 上calc_on_order_fills

我想知道是否有任何方法可以在实时条上实现它。

您可以将之前的入场价格保存在var变量中。 这种类型的变量保持柱之间的值。

var float last_order_price = an

然后您通过将last_order_price除以当前价格来检查价格是否上涨了 2%,如果该值超过 1.02,则您卖出。

这是当两条 SMA 线交叉时首先购买的一些代码。 然后当它有 2% 的利润时卖出。 有趣的是, Precent Profitable为 94%, Profit Factor为 72。这是一种非常安全的交易方式。

显示交易视图窗口

代码:

// This source code is subject to the terms of the Mozilla Public License 2.0 at 

https://mozilla.org/MPL/2.0/
// © CanYouCatchMe

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

var float last_order_price = na

if (crossover(sma(close, 14), sma(close, 28)) and na(last_order_price)) //Need to check if "last_order_price" is "na", else it would change the "last_order_price" value
    strategy.entry("Long", strategy.long)
    last_order_price := open

if (open / last_order_price >= 1.02) //2% or more profit
    strategy.close("Long")
    last_order_price := na

plot(sma(close, 14))
plot(sma(close, 28))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM