简体   繁体   English

CROSSOVER 和 CROSSUNDER 之间的最高值和最低值

[英]Highest and Lowest values between CROSSOVER AND CROSSUNDER

My objective is to conduct a technical analysis of the MACD line and signal line.我的目标是对 MACD 线和信号线进行技术分析。 To achieve this, the following methodology has been established:为实现这一目标,制定了以下方法:

1.Upon the occurrence of a bullish crossover between the MACD line and signal line, the minimum value of the closing price within the defined range should be plotted. 1.MACD 线和信号线出现看涨交叉时,应绘制定义范围内收盘价的最小值。 The range is identified as the interval between the preceding bearish cross-under, which serves as the start point, and the current bullish crossover, which serves as the end point.该范围被确定为作为起点的先前看跌交叉与作为终点的当前看涨交叉之间的间隔。 2.In the event of a bearish cross-under between the MACD line and signal line, the highest value of the closing price within the specified range should be plotted. 2.如果MACD线和信号线出现看跌交叉,则应绘制指定范围内收盘价的最高值。 The range is determined as the interval between the preceding bullish crossover, which serves as the start point, and the current bearish cross-under, which serves as the end point.该范围被确定为作为起点的先前看涨交叉与作为终点的当前看跌交叉之间的间隔。

//I tried this code, however, the code sets lowprice and highPrice to low 1 and high 1 in the //global scope, so it will always be set to these values, regardless of the outcome of the if //statements. //我试过这段代码,但是,代码在 //global scope 中将 lowprice 和 highPrice 设置为 low 1和 high 1 ,因此无论 if // 语句的结果如何,它都将始终设置为这些值。 I also tried replacing the '=' with ':=" in the if statement and ended up with an //error saying invalid value of the 'length' argument in the "lowest" function. it must be >0. THE IMAGE IS AN EXAMPLE OF WHAT I WANT This //is my code. Any help would be appreciated as I am losing my mind.我还尝试在 if 语句中将“=”替换为“:=”,结果以 //error 表示“最低”function 中“长度”参数的无效值。它必须 >0。图像是我想要什么的一个例子这是//我的代码。任何帮助将不胜感激,因为我正在失去理智。

//@version=4
study("Ultimate Code3", overlay=true)

// MACD Calculation
macdLine = ema(close, 12) - ema(close, 26)
signalLine = sma(macdLine, 9)

// MACD Crossover Detection
crossOver = crossover(macdLine, signalLine)
crossUnder = crossunder(macdLine, signalLine)

// Initialize variables for lowPrice and orange line
lowPrice = low[1]
highPrice = high[1]
var line lowLine = na
var line highLine = na

// Check for crossover and set lowPrice and orange line
if crossUnder
    barsSinceCrossOver = barssince(crossOver)
    if barsSinceCrossOver == 0
        highPrice = high
    else
        lowPrice = lowest(low, barsSinceCrossOver)
        highPrice = highest(high, barsSinceCrossOver)
    line.delete(lowLine)
    line.delete(highLine)
    highLine := line.new(bar_index, highPrice, bar_index+1, highPrice, width=2, color=color.red, extend=extend.both, style=line.style_dashed)

if crossOver
    barsSinceCrossUnder = barssince(crossUnder)
    if barsSinceCrossUnder == 0
        lowPrice = low
    else
        lowPrice = lowest(low, barsSinceCrossUnder)
        highPrice = highest(high, barsSinceCrossUnder)
    line.delete(lowLine)
    line.delete(highLine)
    lowLine := line.new(bar_index, lowPrice, bar_index+1, lowPrice, width=2, color=color.green, extend=extend.both, style=line.style_dashed)

bgcolor(crossOver  ? color.green : na, transp=80)
bgcolor(crossUnder ? color.red   : na, transp=80)

This works.这行得通。 Important to make sure bars_count can never be zero or less than zero, so that the ta.lowest & ta.highest functions work properly.确保 bars_count 永远不会为零或小于零很重要,这样 ta.lowest 和 ta.highest 函数才能正常工作。

//@version=5
indicator('Ultimate Code3', overlay=true, max_lines_count = 10)

// MACD Calculation
macdLine = ta.ema(close, 12) - ta.ema(close, 26)
signalLine = ta.sma(macdLine, 9)

// MACD Crossover Detection
crossOver = ta.crossover(macdLine, signalLine)
crossUnder = ta.crossunder(macdLine, signalLine)
cross = ta.cross(macdLine, signalLine)
_sinceCross = ta.barssince(cross[1])

bars_count = ta.barssince(cross[1] )
bars_count:=nz(bars_count)
if bars_count<=0
    bars_count:=1
Highest = ta.highest(bars_count)

crossOverTime=ta.valuewhen(crossOver, time, 0)
crossUnderTime=ta.valuewhen(crossUnder, time, 0)

bool underToOver = time>= crossUnderTime and time<= crossOverTime
bool overToUnder = time>= crossOverTime and time<= crossUnderTime

float lowest = ta.lowest(bars_count)
float highest = ta.highest(bars_count)
_line1 = line(na)
_line2 = line(na)
if underToOver  
    if overToUnder[1]
        line.delete(_line1[1])
    _line1:=line.new(crossUnderTime, lowest, crossOverTime, lowest, xloc=xloc.bar_time, color = color.red, width = 2, extend = extend.none)

if overToUnder  
    if underToOver[1]
        line.delete(_line2[1])
    _line2:=line.new(crossOverTime, highest, crossUnderTime, highest, xloc=xloc.bar_time, color = color.blue, width = 2)

bgcolor(crossOver ? color.new(color.green, 80):na)
bgcolor(crossUnder ? color.new(color.red, 80):na)

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

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