//@version=5
indicator('我的策略', overlay = true)

// 计算EMA
ema6 = ta.ema(close, 6)
ema36 = ta.ema(close, 36)
ema50 = ta.ema(close, 50)
ema7 = ta.ema(close, 7)
ema100 = ta.ema(close, 100)
ema168 = ta.ema(close, 168)
ema62 = ta.ema(close, 62)

// 定义变量以跟踪最低价格及其对应的bar
var float lowestLow = na
var int lowestLowBar = na

// 定义变量以跟踪最高价格及其对应的bar
var float highestHigh = na
var int highestHighBar = na

// 定义变量以跟踪K线收盘价格低于或高于EMA7的次数
var int countLow = 0
var int countHigh = 0

// 定义线条
var line lowLine = na
var line highLine = na

// 定义A点
var float lastHighA = na
var float lastLowA = na
var int countHighA = 1
var int countLowA = 1
var bool isAbove = na
var float highAXn = na
var int Xn = 1

// 新增B点计数和标识
var int countLowB = 1
var int countHighB = 1
var bool isBelow = na

// 定义Y标签相关变量
var float YPrice = na
var int YCount = 0

// 新增U标签相关变量
var int UCount = 0
var bool TFlag = false

// 新增K标签相关变量
var int KCount = 0
var bool EFlag = false

// 新增F标签相关变量
var int FCount = na
var bool FFlag = false

// 新增G标签相关变量
var int GCount = na
var bool GFlag = false

// 当K线收盘价小于EMA7时
if close < ema7
    countLow := countLow + 1
    if countLow >= 1
        if na(lowestLow) or low < lowestLow
            lowestLow := low
            lowestLowBar := bar_index
// 当K线收盘价大于EMA7时
else if close > ema7
    countHigh := countHigh + 1
    if countHigh >= 1
        if na(highestHigh) or high > highestHigh
            highestHigh := high
            highestHighBar := bar_index

// 当K线收盘价大于EMA7时,标注出这段行情中价格的最低点并用一条水平射线显示在K线上,并在水平线下方标注出价格
if close > ema7 and countLow >= 1 and not na(lowestLow) and barstate.isconfirmed
    if na(lowLine) == false
        line.delete(lowLine)
    lowLine := line.new(x1=lowestLowBar, y1=lowestLow, x2=bar_index, y2=lowestLow, color=color.red, width = 1)
    if lowestLow < ema62
        if na(isBelow) or isBelow == false
            countLowB := 1
            isBelow := true
            YCount := 1
            TFlag := true
            UCount := 0
            FCount := na
            FFlag := false
            label.new(x=lowestLowBar, y=lowestLow, text=str.tostring(lowestLow) + ' V' + str.tostring(countLowB) + ' Y' + str.tostring(YCount) + ' T', color=color.purple, yloc=yloc.belowbar)
            YPrice := lowestLow
            line.new(x1=lowestLowBar, y1=lowestLow, x2=bar_index, y2=lowestLow, color=color.red, width = 1)
        else
            countLowB := countLowB + 1
            if lowestLow < YPrice
                YCount := YCount + 1
                FCount := na
                FFlag := false
                label.new(x=lowestLowBar, y=lowestLow, text=str.tostring(lowestLow) + ' V' + str.tostring(countLowB) + ' Y' + str.tostring(YCount) + ' T', color=color.purple, yloc=yloc.belowbar)
                YPrice := lowestLow
                TFlag := true
                UCount := 0
            else
                if TFlag
                    UCount := UCount + 1
                    if na(FCount)
                        FCount := 1
                        FFlag := true
                    else if FFlag
                        FCount := FCount + 1
                        label.new(x=lowestLowBar, y=lowestLow, text=str.tostring(lowestLow) + ' V' + str.tostring(countLowB) + ' U' + str.tostring(UCount) + ' F' + str.tostring(FCount), color=color.red, yloc=yloc.belowbar)
    else if lowestLow > ema62
        if na(isBelow) or isBelow == true
            countHighB := 1
            isBelow := false
        else
            countHighB := countHighB + 1
        label.new(x=lowestLowBar, y=lowestLow, text=str.tostring(lowestLow) + ' W' + str.tostring(countHighB), color=color.gray, yloc=yloc.belowbar)
    countLow := 0
    lowestLow := na
    lowestLowBar := na

// 当K线收盘价格小于EMA7时,标注出这段行情中价格的最高点并用一条水平射线显示在K线上,并在水平线上面标注出价格
else if close < ema7 and countHigh >= 1 and not na(highestHigh) and barstate.isconfirmed
    if na(highLine) == false
        line.delete(highLine)
    highLine := line.new(x1=highestHighBar, y1=highestHigh, x2=bar_index, y2=highestHigh, color=color.green, width = 1)
    if highestHigh > ema62
        if na(isAbove) or isAbove == false
            countHighA := 1
            isAbove := true
            Xn := 1
            highAXn := highestHigh
            EFlag := true
            KCount := 0
            FCount := na
            FFlag := false
            label.new(x=highestHighBar, y=highestHigh, text=str.tostring(highestHigh) + ' H' + str.tostring(countHighA) + ' X' + str.tostring(Xn) + ' E', color=color.blue, yloc=yloc.abovebar)
        else
            countHighA := countHighA + 1
            if highestHigh > highAXn
                Xn := Xn + 1
                highAXn := highestHigh
                EFlag := true
                KCount := 0
                FCount := na
                FFlag := false
                label.new(x=highestHighBar, y=highestHigh, text=str.tostring(highestHigh) + ' H' + str.tostring(countHighA) + ' X' + str.tostring(Xn) + ' E', color=color.blue, yloc=yloc.abovebar)
            else if EFlag
                KCount := KCount + 1
                label.new(x=highestHighBar, y=highestHigh, text=str.tostring(highestHigh) + ' H' + str.tostring(countHighA) + ' K' + str.tostring(KCount), color=color.green, yloc=yloc.abovebar)
    else if highestHigh < ema62
        if na(isAbove) or isAbove == true
            countLowA := 1
            isAbove := false
        else
            countLowA := countLowA + 1
        label.new(x=highestHighBar, y=highestHigh, text=str.tostring(highestHigh) + ' D' + str.tostring(countLowA), color=color.yellow, yloc=yloc.abovebar)
    countHigh := 0
    highestHigh := na
    highestHighBar := na

// 新增F标签至K标签的1/2位置
if not na(FCount) and not na(KCount) and FCount == KCount
    var int halfBarIndex = lowestLowBar + round((highestHighBar - lowestLowBar) / 2)
    label.new(x=halfBarIndex, y=lowestLow, text='G', color=color.black, yloc=yloc.belowbar)

// 在K线上绘制EMA
plot(ema6, color=color.rgb(240, 243, 33))
plot(ema36, color=color.orange)
plot(ema50, color=color.rgb(184, 41, 5))
plot(ema7, color=color.rgb(151, 7, 86))
plot(ema100, color=color.rgb(17, 163, 73))
plot(ema168, color=color.rgb(31, 137, 223))
plot(ema62, color=color.rgb(1, 8, 8))
Pine Script 交易策略:EMA交叉和多指标分析

原文地址: https://www.cveoy.top/t/topic/bEVL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录