当价格达到高于或低于先前入场点的 % 时,我试图设置入场订单(多头或空头)。
现在我正在使用 limit
和 stop
strategy.exit("Exit Buy", from_entry = "Buy", stop=level_dn, limit=level_up)
我想要实现的是以完全相同的价格值输入新订单。
我读到在历史柱上是不可能实现的,因为即使使用 calc_on_order_fills
我们也只在 H、L、O、C 上执行
我想知道是否有任何方法可以在实时条上实现它。
答案 0 :(得分:0)
您可以将之前的入场价格保存在 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))