首页 > 解决方案 > 监控实时价格行为的 Tradingview Fakeout 指标

问题描述

我正在尝试创建一个监控实时价格的指标。假设当前 eth/usd 的市场价格为 110,并且价格仍呈下降趋势,但我认为 100 是一个重要的价格,因为它至少是一个主要的摆动低点,可以成为至少反弹的潜在支撑或即使是反转,好的,现在我添加我的 fakeout 指标,输入摆动最低价:100,然后输入入场价:103,我想要指标做的是开始监控价格,当价格跌破 100 时,回升至 103 以上,将触发我的多头入场。而且我们都知道价格不会一直跌破100直线上升到103以上,在上破103之前可能会有一些盘整,我只关心价格第一次跌破100,以及第一次价格超过103,

fakeout 或 stophunt,随便你,它包含两个部分,fakeout 向上,我们可以牛市陷阱,fakeout 向下,我们可以承受陷阱,虽然我在我的代码中包含了多头和空头条件,但实际上,当我为指标添加警报时,我只会选择一个条件,无论是多头还是空头。我包括了一个熊陷阱示例的屏幕截图。

在此处输入图像描述

请看看我的代码伙计们,这些代码代表了我想要做的事情,但我似乎无法让它工作,没有任何有用的结果告诉我哪里出了问题,所以我请求你的帮助.

太感谢了!

//@version=4
study("Fakeout Indicator", overlay=true)

// Define Swing Price to monitor, and Entry Price to monitor
Swing_Price = input(100, title="Enter the swing price", type=input.float, confirm=true)
Entry_Price = input(103,title="Entry Price", type=input.float, confirm=true)


// Draw lines for Swing Price and Entry Price
plot(Swing_Price , title="Swing Price", style=plot.style_circles, linewidth=2, color=color.gray, trackprice=true,offset=-9999)
plot(Entry_Price , title="Entry Price", style=plot.style_circles, linewidth=2, color=color.gray, trackprice=true,offset=-9999)


// Initial variable that stores status for long condition
break_below_long = false
break_above_long = false

// Store the status when the first time price breaks above Swing Price, and the status when the first time price breaks below Entry_Price
break_below_long := nz(break_above_long[1]) or not crossunder(close, Swing_Price) ? false : true
break_above_long := nz(break_below_long[1]) and crossover(close, Entry_Price) ? true : false


// Initial variable that stores status for short condition
break_above_short = false
break_below_short = false

// Store the status when the first time price breaks above Swing Price, and the status when the first time price breaks below Entry_Price

break_above_short := nz(break_below_short[1]) or not crossover(close, Swing_Price) ? false : true
break_below_short := nz(break_above_short[1]) and crossunder(close, Entry_Price) ? true : false

// Long Condition
longCondition = break_above_long

// Short Condition
shortCondition = break_below_short

// alert Condition
alertcondition(shortCondition, title="shortCondition for Bull Trap", message="Bull Trap Occurs!")
alertcondition(longCondition, title="longCondition for Bear Trap", message="Bear Trap Occurs!")

标签: pine-scripttrading

解决方案


你能试试这些吗?

longCondition = crossunder(close[1], Swing_Price) and crossover(close, Entry_Price) and min(close, 2) > Swing_Price

同样简称:

shortCondition = crossover(close[1], Swing_Price) and crossunder(close, Entry_Price) and max(close, 2) < Swing_Price

推荐阅读