Pine script 有人能告诉我如何在我的代码中实现这一点吗(我对此很陌生)

Pine script 有人能告诉我如何在我的代码中实现这一点吗(我对此很陌生),pine-script,Pine Script,嘿,希望你做得很好 总结一下我的脚本,它基本上是寻找吞没的蜡烛,一旦发现它检查13ema是否穿过两支蜡烛的主体。如果这是真的,那么下一支蜡烛的开口处会立即出现一个信号形状 因此,我试图实现的是,只有在信号出现之前,50均线距离蜡烛收盘至少10点时,信号形状才会出现。我会尽我所能举一些例子 (销售示例) (买的例子)顺便说一句,形状应该是朝上的,买的时候是绿色的 假设50均线正好是: -高于13均线的卖出信号 -低于买入信号的13均线 我希望它用上一支蜡烛的收盘价来计算至少10点,但它用的不是5

嘿,希望你做得很好

总结一下我的脚本,它基本上是寻找吞没的蜡烛,一旦发现它检查13ema是否穿过两支蜡烛的主体。如果这是真的,那么下一支蜡烛的开口处会立即出现一个信号形状

因此,我试图实现的是,只有在信号出现之前,50均线距离蜡烛收盘至少10点时,信号形状才会出现。我会尽我所能举一些例子

(销售示例)

(买的例子)顺便说一句,形状应该是朝上的,买的时候是绿色的


假设50均线正好是:

-高于13均线的卖出信号

-低于买入信号的13均线

我希望它用上一支蜡烛的收盘价来计算至少10点,但它用的不是50均线,而是200均线

(销售示例)

(购买示例)


假设50均线和200均线正好是:

-高于13均线的卖出信号

-低于买入信号的13均线

我希望它用上一支蜡烛的收盘价来计算至少10点,但不是用50均线或200均线,而是用800均线

(销售示例)

(购买示例)


如果出现买入信号,所有均线均低于买入,则不称其为卖出,反之亦然。我已经这样做了,所以不要担心这部分

我得到一个提示,我需要使用syminfo.pointvalue来完成这项工作,但我对这项工作非常陌生,所以我不确定如何在脚本中实现它

我试着读了这篇文章,但即使是这篇文章对我来说也有点难理解。

提前谢谢!!:)

研究(“测试1”,叠加=true)
//颜色
_颜色5=#ffff00
_颜色13=#ff0000
_颜色50=#00ffff
_颜色200=#434651
_颜色800=#0000ff
//EMA值
_均线5=均线(闭合,5)
_ema13=ema(关闭,13)
_均线50=均线(收盘,50)
_ema200=ema(关闭,200)
_ema800=ema(关闭,800)
//图EMAs
//绘图(ema5,颜色=#ffff00,传输=100)
//绘图(_ema13,颜色=#ff0000,传输=100)
//绘图(_ema50,颜色=#00ffff,传输=100)
//绘图(ema200,颜色=434651,传输=100)
//绘图(_ema800,颜色=#0000ff,传输=100)
//_如果ema
_c13=交叉(闭合,_ema13)
_c50=交叉(闭合,_ema50)
//EMA实际穿过的线
打印(关闭,样式=plot.style\u行,颜色=color.black,传输=100)
//b2是蜡烛1,b1是蜡烛2(在松树中,从当前蜡烛向后数蜡烛)
//给我们蜡烛的大小(不管是公牛还是熊)
_b1size=最大值(打开[1],关闭[1])-最小值(打开[1],关闭[1])
_b2size=max(打开[2],关闭[2])-min(打开[2],关闭[2]))
//蜡烛大小的比例,以便您可以过滤出不同大小的蜡烛
_szRatio=_b2size/_b1size
_szCondition=_szRatio>=0.01和_szRatio=max(打开[2],关闭[2])和min(打开[1],关闭[1])_ema13//bearsignal
_交叉50低于13 EMA=_交叉50和_ema50<_ema13//bullsignal
//显示信号显示看涨的条件
_emaCondbull=(打开_ema50)
_bullSignal=_Englishingand _Crossed13and close[1]>max(打开[2],关闭[2])和_SzConditionand _emaCondbull
//如果条件为真,则绘制信号
plotshape(_bullSignal?close:na,location=location.belowbar,style=shape.triangleup,size=size.tiny,color=#00ff73)
//显示信号显示为熊市的条件

_emaCondbear=(打开>ema200或打开>ema800或(打开>ema50或交叉50高于13EMA))和非(打开pip取决于您如何定义它。
对于
EUR/CAD
,pip定义为0.0001(逗号后4位)

但是,TradingView显示为0.00001(逗号后5位)
这是在
syminfo.mintick
中找到的值

这意味着TradingView上的1点等于10个刻度。
请参见下面我对您的代码的添加。
您可以在输入变量
ticks\u per\u pip
中设置1个pip中的刻度数
您还可以在输入变量
pip\u threshold
中设置一个以pips表示的阈值

这就是你要找的吗

//@version=4
study("SO 64839720", "SO", overlay=true)

//Colors
_color5 = #ffff00
_color13 = #ff0000
_color50 = #00ffff
_color200 = #434651
_color800 = #0000ff

//EMA value
_ema5 = ema(close, 5)
_ema13 = ema(close, 13)
_ema50 = ema(close, 50)
_ema200 = ema(close, 200)
_ema800 = ema(close, 800)


//Plots EMAs
//plot(_ema5, color=#ffff00, transp=100 )
//plot(_ema13, color=#ff0000, transp=100)
//plot(_ema50, color=#00ffff, transp=100)
//plot(_ema200, color=#434651, transp=100)
//plot(_ema800, color=#0000ff, transp=100)

//_c13 and _c50 is true if the ema
_c13 = cross(close, _ema13)
_c50 = cross(close, _ema50)

//Line that the EMAs actually cross
plot(close, style=plot.style_line, color=color.black, transp=100)

//b2 is candle 1 and b1 is candle 2 (IN PINE YOU COUNT CANDLES BACKWARDS FORM THE CURRENT CANDLE)
//Gives us the size of the candles (Regardless of bull or bear) 
_b1size = max(open[1], close[1]) - min(open[1], close[1])
_b2size = max(open[2], close[2]) - min(open[2], close[2])

//Ratios of the candle size so you can filter out different sized candles
_szRatio = _b2size/_b1size
_szCondition = _szRatio >= 0.01 and _szRatio<=0.99

//Compares the MAX of candle 1 body against MAX of candle 2 body (same with min)
_engulfing = max(open[1], close[1]) >= max(open[2], close[2]) and min(open[1], close[1]) <= min(open[2], close[2])

//Check the conditions here is true for the EMA to cross candles
_crossed13 = _c13[1] and _c13[2]
_crossed50 = _c50[1] or _c50[2]

//if ema cuts either candle but is also above/below (bear/bull) the 13ema
_crossed50above13ema = _crossed50 and _ema50 > _ema13 //bearsignal
_crossed50below13ema = _crossed50 and _ema50 < _ema13 //bullsignal

//Shows the condidtions for the Signal to Show BULLISH
_emaCondbull =  (open<_ema200 or open<_ema800 or (open<_ema50 or _crossed50below13ema)) and not (open>_ema200 and open>_ema800 and open>_ema50)
_bullSignal = _engulfing  and _crossed13 and close[1] > max(open[2], close[2]) and _szCondition and _emaCondbull


// ----------------------------------
// STACKOVERFLOW CODE ADDED - [START]
// ----------------------------------
var int     ticks_per_pip           = input(10, "1 pip = ... ticks (A tick is the smallest value increment on the chart = syminfo.mintick)",    input.integer)
var int     pip_threshold           = input(10, "ema is at least ... pips away from the close of the candle right before the signal appears",   input.integer)

var float   ema_to_compare          = na
var float   distance_in_ticks       = na
var float   distance_in_pips        = na
var bool    pip_threshold_broken    = na


// Extended version (to explain each calculation step)
if _ema50[1] < _ema13[1] and _ema200[1] < _ema13[1]
    ema_to_compare := _ema800
else if _ema50[1] < _ema13[1]
    ema_to_compare := _ema200
else
    ema_to_compare := _ema50

distance_in_ticks       := abs(ema_to_compare[1] - close[1])    // Distance measured on the chart
distance_in_pips        := distance_in_ticks / ticks_per_pip    // Converte that distance to pips
pip_threshold_broken    := distance_in_pips > pip_threshold     // Compare that pip-distance to the threshold distance


// Short version
pip_threshold_broken    := (abs((_ema50[1] < _ema13[1] and _ema200[1] < _ema13[1] ? _ema800[1] : _ema50[1] < _ema13[1] ? _ema200[1] : _ema50[1]) - close[1]) / ticks_per_pip) > pip_threshold

// --------------------------------
// STACKOVERFLOW CODE ADDED - [END]
// --------------------------------
/@version=4
研究(“SO 64839720”,“SO”,叠加=真)
//颜色
_颜色5=#ffff00
_颜色13=#ff0000
_颜色50=#00ffff
_颜色200=#434651
_颜色800=#0000ff
//EMA值
_均线5=均线(闭合,5)
_ema13=ema(关闭,13)
_均线50=均线(收盘,50)
_ema200=ema(关闭,200)
_ema800=ema(关闭,800)
//图EMAs
//绘图(ema5,颜色=#ffff00,传输=100)
//绘图(_ema13,颜色=#ff0000,传输=100)
//绘图(_ema50,颜色=#00ffff,传输=100)
//绘图(ema200,颜色=434651,传输=100)
//绘图(_ema800,颜色=#0000ff,传输=100)
//_如果ema
_c13=交叉(闭合,_ema13)
_c50=交叉(闭合,_ema50)
//EMA实际穿过的线
打印(关闭,样式=plot.style\u行,颜色=color.black,传输=100)
//b2是蜡烛1,b1是蜡烛2(在松树中,从当前蜡烛向后数蜡烛)
//给我们蜡烛的大小(不管是公牛还是熊)
_b1size=最大值(打开[1],关闭[1])-最小值(打开[1],关闭[1])
_b2size=max(打开[2],关闭[2])-min(打开[2],关闭[2]))
//蜡烛大小的比例,以便您可以过滤出不同大小的蜡烛
_szRatio=_b2size/_b1size
_szCondition=_szRatio>=0.01和_szRatio=max(打开[2],关闭[2])和min(打开[1],关闭[1])_ema13//bearsignal
_交叉50低于13 EMA=_交叉50和_ema50<_ema13//bullsignal
//显示信号显示看涨的条件
_emaCondbull=(打开_ema50)
_bullSignal=_Englishingand _Crossed13and close[1]>max(打开[2],关闭[2])和_SzConditionand _emaCondbull
// ----------------------------------
//已添加STACKOVERFLOW代码-[开始]
// ----------------------------------
var int ticks_per_pip=input(10,“1 pip=…ticks(tick是图表上最小的值增量=syminfo.mintick)”,input.integer)
var int pip_阈值
//@version=4
study("SO 64839720", "SO", overlay=true)

//Colors
_color5 = #ffff00
_color13 = #ff0000
_color50 = #00ffff
_color200 = #434651
_color800 = #0000ff

//EMA value
_ema5 = ema(close, 5)
_ema13 = ema(close, 13)
_ema50 = ema(close, 50)
_ema200 = ema(close, 200)
_ema800 = ema(close, 800)


//Plots EMAs
//plot(_ema5, color=#ffff00, transp=100 )
//plot(_ema13, color=#ff0000, transp=100)
//plot(_ema50, color=#00ffff, transp=100)
//plot(_ema200, color=#434651, transp=100)
//plot(_ema800, color=#0000ff, transp=100)

//_c13 and _c50 is true if the ema
_c13 = cross(close, _ema13)
_c50 = cross(close, _ema50)

//Line that the EMAs actually cross
plot(close, style=plot.style_line, color=color.black, transp=100)

//b2 is candle 1 and b1 is candle 2 (IN PINE YOU COUNT CANDLES BACKWARDS FORM THE CURRENT CANDLE)
//Gives us the size of the candles (Regardless of bull or bear) 
_b1size = max(open[1], close[1]) - min(open[1], close[1])
_b2size = max(open[2], close[2]) - min(open[2], close[2])

//Ratios of the candle size so you can filter out different sized candles
_szRatio = _b2size/_b1size
_szCondition = _szRatio >= 0.01 and _szRatio<=0.99

//Compares the MAX of candle 1 body against MAX of candle 2 body (same with min)
_engulfing = max(open[1], close[1]) >= max(open[2], close[2]) and min(open[1], close[1]) <= min(open[2], close[2])

//Check the conditions here is true for the EMA to cross candles
_crossed13 = _c13[1] and _c13[2]
_crossed50 = _c50[1] or _c50[2]

//if ema cuts either candle but is also above/below (bear/bull) the 13ema
_crossed50above13ema = _crossed50 and _ema50 > _ema13 //bearsignal
_crossed50below13ema = _crossed50 and _ema50 < _ema13 //bullsignal

//Shows the condidtions for the Signal to Show BULLISH
_emaCondbull =  (open<_ema200 or open<_ema800 or (open<_ema50 or _crossed50below13ema)) and not (open>_ema200 and open>_ema800 and open>_ema50)
_bullSignal = _engulfing  and _crossed13 and close[1] > max(open[2], close[2]) and _szCondition and _emaCondbull


// ----------------------------------
// STACKOVERFLOW CODE ADDED - [START]
// ----------------------------------
var int     ticks_per_pip           = input(10, "1 pip = ... ticks (A tick is the smallest value increment on the chart = syminfo.mintick)",    input.integer)
var int     pip_threshold           = input(10, "ema is at least ... pips away from the close of the candle right before the signal appears",   input.integer)

var float   ema_to_compare          = na
var float   distance_in_ticks       = na
var float   distance_in_pips        = na
var bool    pip_threshold_broken    = na


// Extended version (to explain each calculation step)
if _ema50[1] < _ema13[1] and _ema200[1] < _ema13[1]
    ema_to_compare := _ema800
else if _ema50[1] < _ema13[1]
    ema_to_compare := _ema200
else
    ema_to_compare := _ema50

distance_in_ticks       := abs(ema_to_compare[1] - close[1])    // Distance measured on the chart
distance_in_pips        := distance_in_ticks / ticks_per_pip    // Converte that distance to pips
pip_threshold_broken    := distance_in_pips > pip_threshold     // Compare that pip-distance to the threshold distance


// Short version
pip_threshold_broken    := (abs((_ema50[1] < _ema13[1] and _ema200[1] < _ema13[1] ? _ema800[1] : _ema50[1] < _ema13[1] ? _ema200[1] : _ema50[1]) - close[1]) / ticks_per_pip) > pip_threshold

// --------------------------------
// STACKOVERFLOW CODE ADDED - [END]
// --------------------------------
//@version=4
study("SO 64839720", "SO", overlay=true)

//Colors
_color5 = #ffff00
_color13 = #ff0000
_color50 = #00ffff
_color200 = #434651
_color800 = #0000ff

//EMA value
_ema5 = ema(close, 5)
_ema13 = ema(close, 13)
_ema50 = ema(close, 50)
_ema200 = ema(close, 200)
_ema800 = ema(close, 800)


//Plots EMAs
//plot(_ema5, color=#ffff00, transp=100 )
//plot(_ema13, color=#ff0000, transp=100)
//plot(_ema50, color=#00ffff, transp=100)
//plot(_ema200, color=#434651, transp=100)
//plot(_ema800, color=#0000ff, transp=100)

//_c13 and _c50 is true if the ema
_c13 = cross(close, _ema13)
_c50 = cross(close, _ema50)

//Line that the EMAs actually cross
plot(close, style=plot.style_line, color=color.black, transp=100)

//b2 is candle 1 and b1 is candle 2 (IN PINE YOU COUNT CANDLES BACKWARDS FORM THE CURRENT CANDLE)
//Gives us the size of the candles (Regardless of bull or bear) 
_b1size = max(open[1], close[1]) - min(open[1], close[1])
_b2size = max(open[2], close[2]) - min(open[2], close[2])

//Ratios of the candle size so you can filter out different sized candles
_szRatio = _b2size/_b1size
_szCondition = _szRatio >= 0.01 and _szRatio<=0.99

//Compares the MAX of candle 1 body against MAX of candle 2 body (same with min)
_engulfing = max(open[1], close[1]) >= max(open[2], close[2]) and min(open[1], close[1]) <= min(open[2], close[2])

//Check the conditions here is true for the EMA to cross candles
_crossed13 = _c13[1] and _c13[2]
_crossed50 = _c50[1] or _c50[2]

//if ema cuts either candle but is also above/below (bear/bull) the 13ema
_crossed50above13ema = _crossed50 and _ema50 > _ema13 //bearsignal
_crossed50below13ema = _crossed50 and _ema50 < _ema13 //bullsignal



// ----------------------------------
// STACKOVERFLOW CODE ADDED - [START]
// ----------------------------------
var int     ticks_per_pip           = input(10, "1 pip = ... ticks (A tick is the smallest value increment on the chart = syminfo.mintick)",    input.integer)
var int     pip_threshold           = input(10, "ema is at least ... pips away from the close of the candle right before the signal appears",   input.integer)
var bool    use_pip_treshold        = input(true, "Use pip treshold",                                                                           input.bool)

var float   ema_to_compare          = na
var float   distance_in_ticks       = na
var float   distance_in_pips        = na
var bool    pip_threshold_broken    = na


// Extended version (to explain each calculation step)
if _ema50[1] < _ema13[1] and _ema200[1] < _ema13[1]
    ema_to_compare := _ema800
else if _ema50[1] < _ema13[1]
    ema_to_compare := _ema200
else
    ema_to_compare := _ema50

distance_in_ticks       := abs(ema_to_compare[1] - close[1]) / syminfo.mintick   // Distance measured on the chart
distance_in_pips        := distance_in_ticks / ticks_per_pip    // Converte that distance to pips
pip_threshold_broken    := distance_in_pips > pip_threshold     // Compare that pip-distance to the threshold distance


// Short version
// pip_threshold_broken    := (abs((_ema50[1] < _ema13[1] and _ema200[1] < _ema13[1] ? _ema800[1] : _ema50[1] < _ema13[1] ? _ema200[1] : _ema50[1]) - close[1]) / ticks_per_pip) > pip_threshold


plotshape(distance_in_ticks, "distance_in_ticks", "")
plotshape(distance_in_pips, "distance_in_pips", "")
plotshape(pip_threshold, "pip_threshold", "")
plotshape(pip_threshold_broken, "pip_threshold_broken", "")

plot(_ema13, "_ema13", color.red)
plot(_ema50, "_ema50", color.green)
plot(_ema200, "_ema200", color.blue)

// --------------------------------
// STACKOVERFLOW CODE ADDED - [END]
// --------------------------------

pip_threshold_broken := use_pip_treshold ? pip_threshold_broken : true

//Shows the condidtions for the Signal to Show BULLISH
_emaCondbull =  (open<_ema200 or open<_ema800 or (open<_ema50 or _crossed50below13ema)) and not (open>_ema200 and open>_ema800 and open>_ema50)
_bullSignal = pip_threshold_broken and _engulfing and _crossed13 and close[1] > max(open[2], close[2]) and _szCondition and _emaCondbull

//Plots the Signal if Conditions are true
plotshape(_bullSignal?close:na, style=shape.triangleup, size=size.tiny, color=#00ff00)