在 Pinescript 中编写此代码应遵循什么方法

发布于 2025-01-18 15:56:40 字数 186 浏览 1 评论 0原文

  1. 如果任何蜡烛线收盘价高于该线(例如 EMA20),则会生成买入信号。
  2. 仅当任何后续蜡烛线收盘价低于该线时(买入信号蜡烛),才应触发止损。
  3. 所有在“买入信号”蜡烛之前形成的蜡烛的收盘价均应低于 EMA20。

卖出信号也相反。 我不想知道代码,只需要逻辑就足以进行回测。
谢谢

  1. Buy signal to be generated if any candle closes above a line (let's say EMA20)
  2. Stoploss should get triggered only if any subsequent candle closes below it (buy signal candle).
  3. All candles formed prior to the "buy signal" candle should have a closing below EMA20.

Inversely for sell signal also.
I do not wish to know the code, only the logic would suffice for backtesting.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ〆星空下的拥抱 2025-01-25 15:56:40
  1. 您可以使用ta.crossover(关闭,EMA20)var中检查该
  2. 商店的输入价格,并在交易中检查价格是否下方
  3. 关闭当价格低于ema20

以下代码下方的价格应进行计数或至少给您一个想法

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

//@version=5
indicator("My script", overlay=true)

ema_len = input.int(20)
below_ema_no = input.int(4)

_ema = ta.ema(close, ema_len)
ema_co = ta.crossover(close, _ema)

var below_ema_cnt = 0
below_ema_cnt := close < _ema ? below_ema_cnt + 1 : 0   // Increase the counter if it closed below EMA20, reset oterwise

var is_long = false
var float buy_price = na

is_buy = not is_long and ema_co and (below_ema_cnt[1] >= below_ema_no)  // Buy when we are not already long, ema crossover takes place, last n candles below ema20
is_long := not is_long ? is_buy ? true : false : is_long                // Update is_long flag
buy_price := not is_long[1] and is_long ? close : buy_price             // New position: Store buy price (close price)

is_sl = is_long ? close < buy_price : false     // SL is hit if price closes below entry price
is_long := is_sl ? false : is_long              // Update is_long flag in case SL is hit
buy_price := is_sl ? na : buy_price             // Reset buy_price in case SL is hit

plot(_ema, "EMA", color.yellow, 2)
plotshape(is_buy, "Buy", shape.triangleup, location.belowbar, color.green, 0, "Buy", size=size.small)
plotshape(is_sl, "SL", shape.triangledown, location.abovebar, color.red, 0, "SL", size=size.small)
plot(buy_price, "Buy Price", color.white, 1, plot.style_circles)

src =“ https://i.sstatic.net/kksyx.png” alt =“在此处输入图像说明”>

  1. You can use ta.crossover(close, ema20) to check that
  2. Store entry price in a var, and check if the price closes below it when you are in a trade
  3. Use a counter to count when the price is below ema20

Below code should do it or at least give you an idea

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

//@version=5
indicator("My script", overlay=true)

ema_len = input.int(20)
below_ema_no = input.int(4)

_ema = ta.ema(close, ema_len)
ema_co = ta.crossover(close, _ema)

var below_ema_cnt = 0
below_ema_cnt := close < _ema ? below_ema_cnt + 1 : 0   // Increase the counter if it closed below EMA20, reset oterwise

var is_long = false
var float buy_price = na

is_buy = not is_long and ema_co and (below_ema_cnt[1] >= below_ema_no)  // Buy when we are not already long, ema crossover takes place, last n candles below ema20
is_long := not is_long ? is_buy ? true : false : is_long                // Update is_long flag
buy_price := not is_long[1] and is_long ? close : buy_price             // New position: Store buy price (close price)

is_sl = is_long ? close < buy_price : false     // SL is hit if price closes below entry price
is_long := is_sl ? false : is_long              // Update is_long flag in case SL is hit
buy_price := is_sl ? na : buy_price             // Reset buy_price in case SL is hit

plot(_ema, "EMA", color.yellow, 2)
plotshape(is_buy, "Buy", shape.triangleup, location.belowbar, color.green, 0, "Buy", size=size.small)
plotshape(is_sl, "SL", shape.triangledown, location.abovebar, color.red, 0, "SL", size=size.small)
plot(buy_price, "Buy Price", color.white, 1, plot.style_circles)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文