Smart Money Setup 04 [TradingFinder] Three Drive (Harmonic) & OB Proof

TradingFinder · study · 665 行 · 点赞 3,780 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TFlab
//@version=5
 
/////////////////////////////////////////////////////////
//    {Vectorize Code Version(Without using loop!)}    //
/////////////////////////////////////////////////////////
indicator("Smart Money Setup 04 [TradingFinder] Three Drive (Harmonic) & OB Proof"," OB Finder | 3 Drive | TFlab", overlay = true, max_bars_back = 5000 , max_boxes_count = 500, max_labels_count = 500 , max_lines_count = 500)
 
//User Settings
    // Three Drive
PP = input.int(2 , 'Three Drice Pivot Period' , minval = 2 , group = '3 Drive Setting')
 
 
//BoX Color
DemBxColor = input.color(color.rgb(38, 240, 189, 50) , 'Demand Zone Color', group =  ' Color Setting')
SupBxColor = input.color(color.rgb(242, 117, 34, 60) , 'Supply Zone Color' , group =  ' Color Setting')
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Candle Range
Candle_Range = high - low
//Candle Trend and Candle Body
Candle_Body = close - open
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Candle Trend Detector
Candle_Trend = if Candle_Body > 0
    "Candle Positive"
else if Candle_Body < 0
    "Candle Negative"
else
    "Candle no Trend"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Candle Break Detector
Candle_Break = if close > high[1]
    "Candle Bull Break"
else if close < low[1]
    "Candle Bear Break"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//High and Low Detector
 
bar_index_bull = ta.valuewhen(close > high[1] , bar_index,0)
bar_index_bear = ta.valuewhen(close < low[1] , bar_index,0)
 
var int start_bar_index_high = 0 
var int start_bar_index_low = 0
 
lenHighest = bar_index - bar_index_bear + 5
lenLowest = bar_index - bar_index_bull + 5
 
lenHighest1 = bar_index - bar_index_bear + 3
lenLowest1 = bar_index - bar_index_bull + 3
///////////////
HighestLen =if not na(lenHighest)
    lenHighest
else
    1
LowestLen = if not na (lenLowest)
    lenLowest
else
    1
 
///////////////
HighestLen1 =if not na(lenHighest1)
    lenHighest1
else
    1
LowestLen1 = if not na (lenLowest1)
    lenLowest1
else
    1
 
 
//All High and Low Detector
High_first = ta.highest(high, HighestLen)
Low_first = ta.lowest(low, LowestLen)
 
High_first1 = ta.highest(high, HighestLen1)
Low_first1 = ta.lowest(low, LowestLen1)
 
//All Correct High and Low Detector
var float High_Correct = 0.0 
var float Low_Correct = 0.0
High_sec = if Candle_Break == "Candle Bear Break" and Candle_Break[1] =="Candle Bull Break"
    start_bar_index_high := bar_index
    if High_Correct[1] == High_first 
        High_first1
    else 
        High_first
 
Low_sec = if (Candle_Break == "Candle Bull Break" and Candle_Break[1] =="Candle Bear Break") 
    start_bar_index_low := bar_index
    if Low_Correct[1] == Low_first
        Low_first1
    else
        Low_first
 
 
High_Correct := if not na(High_sec)
    High_sec
else
    High_sec[1]
 
Low_Correct := if not na(Low_sec)
    Low_sec
else 
    Low_sec[1]
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
var int bar_index_bull_BoS = 0
var int bar_index_bear_BoS = 0
var string BoS = "Hi"
 
var float High_Correct_f = 0.0
var float Low_Correct_f = 0.0
 
 
//Major Correct High and Low Detector
High_Correct_f := if High_Correct_f == 0
    High_Correct
else if High_Correct > High_Correct_f[1] and High_Correct_f != 0
    High_Correct
else if High_Correct < High_Correct_f[1]
    if BoS == 'Bear BoS' and (bar_index_bear_BoS >= start_bar_index_high)
        High_Correct
    else 
        High_Correct_f
else if High_Correct_f == High_Correct_f[1] and High_Correct_f != 0
    High_Correct_f
 
else 
    High_Correct
 
 
 
Low_Correct_f := if Low_Correct_f == 0 
    Low_Correct
else if Low_Correct < Low_Correct_f[1] and Low_Correct_f != 0
    Low_Correct
else if Low_Correct > Low_Correct_f[1]
    if BoS == 'Bull BoS' and  (bar_index_bull_BoS >= start_bar_index_low)
        Low_Correct
    else 
        Low_Correct_f
else if Low_Correct_f == Low_Correct_f[1] and Low_Correct_f != 0
    Low_Correct_f
else 
    Low_Correct
   
 
 
 
 
    
 
 
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//High and Low Drawing
color_High = High_Correct_f == High_Correct_f[1]   ? color.rgb(5, 148, 10) : na 
color_Low = Low_Correct_f == Low_Correct_f[1]   ? color.rgb(184, 0, 0) : na
 
 
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//BoS Detector
 
if close > High_Correct_f and close[1] <= High_Correct_f
    BoS := "Bull BoS"
    bar_index_bull_BoS := bar_index
    //label.set_text(id=Bull_BoS_Label, text="Bull BoS")
else if close < Low_Correct_f and close[1] >= Low_Correct_f
    BoS := "Bear BoS"
    bar_index_bear_BoS := bar_index
    //label.set_text(id=Bear_BoS_Label, text="Bear BoS")
else
    BoS := '0'
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Trend Detector
var string Trend = "Hi"
 
if BoS == "Bull BoS" and bar_index_bull_BoS[1] > bar_index_bear_BoS
    Trend := "Up Trend"
else if BoS == "Bear BoS" and bar_index_bear_BoS[1] >  bar_index_bull_BoS 
    Trend := "Down Trend"
else if Trend == "Up Trend" and close < Low_Correct_f or Trend == "Down Trend" and close > High_Correct_f
    Trend := "No Trend"
else 
    Trend := Trend
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Order Block Detector
bar_index_Supply_OB = ta.valuewhen(High_Correct != High_Correct[1], bar_index[1],0)
bar_index_Demand_OB=ta.valuewhen(Low_Correct != Low_Correct[1], bar_index[1],0)
/////////////////////////////////
var DOB_index = 0
var SOB_index = 0
 
var PerDOB_index = 0
var PerSOB_index = 0
 
var int DemandCheck =0
var int SupplyCheck =0
 
DOB_index := ta.valuewhen((BoS == "Bull BoS" and bar_index_bull_BoS[1] > bar_index_bear_BoS ) or
 (BoS =="Bull BoS" and bar_index_bull_BoS > bar_index_bear_BoS ), bar_index, 0)
 
SOB_index := ta.valuewhen((BoS == "Bear BoS" and bar_index_bear_BoS[1] >  bar_index_bull_BoS ) or
 (BoS == "Bear BoS" and bar_index_bear_BoS >  bar_index_bull_BoS ), bar_index, 0)
 
PerDOB_index := ta.valuewhen((BoS == "Bull BoS" and bar_index_bull_BoS[1] > bar_index_bear_BoS ) or
 (BoS =="Bull BoS" and bar_index_bull_BoS > bar_index_bear_BoS ), bar_index, 1)
 
PerSOB_index := ta.valuewhen((BoS == "Bear BoS" and bar_index_bear_BoS[1] >  bar_index_bull_BoS ) or
 (BoS == "Bear BoS" and bar_index_bear_BoS >  bar_index_bull_BoS ), bar_index, 1)
 
Demand_OB_Condition = (((BoS == "Bull BoS" and bar_index_bull_BoS[1] > bar_index_bear_BoS ) or
     (BoS =="Bull BoS" and bar_index_bull_BoS > bar_index_bear_BoS ))) and
     DemandCheck != bar_index_Demand_OB
 
Supply_OB_Condition = (((BoS == "Bear BoS" and bar_index_bear_BoS[1] >  bar_index_bull_BoS ) or
     (BoS == "Bear BoS" and bar_index_bear_BoS >  bar_index_bull_BoS))) and 
     SupplyCheck != bar_index_Supply_OB
//BOX Drawing///////////////////////////////////////////////////////////////
 
//Zones Data
    //Demand Zone
        //Proximal Line 
var float YDp12 = 0.0
var int XDp1    = 0
var int XDp2    = 0
 
        //Distal Line
var float YDd12 = 0.0
var int XDd1    = 0
var int XDd2    = 0
 
    //Supply Zone 
        //Proximal Line 
var float YSp12 = 0.0
var int XSp1    = 0
var int XSp2    = 0
 
        //Distal Line
var float YSd12 = 0.0
var int XSd1    = 0
var int XSd2    = 0
 
 
////////////////////////
if Demand_OB_Condition 
    DemandCheck := bar_index_Demand_OB 
    YDp12   := high[bar_index - bar_index_Demand_OB]
    XDp1    := bar_index_Demand_OB
    XDp2    := bar_index_Demand_OB + 1
    YDd12   := low[bar_index - bar_index_Demand_OB]
    XDd1    := bar_index_Demand_OB
    XDd2    := bar_index_Demand_OB + 1
 
if Supply_OB_Condition
    SupplyCheck := bar_index_Supply_OB
    YSp12   := low[bar_index - bar_index_Supply_OB]
    XSp1    := bar_index_Supply_OB
    XSp2    := bar_index_Supply_OB + 1
    YSd12   := high[bar_index - bar_index_Supply_OB]
    XSd1    := bar_index_Supply_OB
    XSd2    := bar_index_Supply_OB + 1
 
//Dynamic Drawing Zone
LinerFunctionDem(Xd1, Yd1, Xd2, Yd2 ,Xp1, Yp1, Xp2, Yp2 , Xn) =>
    //y = mx + b
    //m = (y2 - y1) / (x2 - x1)
    //b = y - mx
    xd1 = Xd1
    xd2 = Xd2
    yd1 = Yd1
    yd2 = Yd2
    xdn = Xn 
    xdnz = Xn 
    md =  (yd2 - yd1) / (xd2 - xd1)
    bd = yd1 - md*xd1 //or b = y2 - m*x2
    Ydnz = md*(xdnz) + bd
    Ydn = md*(xdn) + bd
    xp1 = Xp1
    xp2 = Xp2
    yp1 = Yp1
    yp2 = Yp2
    xpn = Xn 
    xpnz = Xn 
    mp =  (yp2 - yp1) / (xp2 - xp1)
    bp = yp1 - mp*xp1 //or b = y2 - m*x2
    Ypnz = mp*(xpnz) + bp
    Ypn = mp*(xpn) + bp
    var bool DemCheck = true
    var int DemCounter = 1
    var line Distal = na
    var line Proximal = na
    var line DLine50per = na
    var linefill fillline = na
    if Demand_OB_Condition
        Distal := line.new(xd1, yd1, xd2  , yd1 , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
        Proximal := line.new(xp1, yp1, xd2 , yp1 , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
        DLine50per := line.new(xp1, (yp1+yd1) / 2 , xd2 , (yp1+yd1) / 2  , color = color.rgb(0, 0, 0) , 
         style = line.style_dotted , width = 1)
        fillline := linefill.new(Distal ,Proximal ,color = DemBxColor )
    if ((low > YDp12) or xd1 == YDp12[1]) and (DemCheck == true)
        DemCounter := DemCounter + 1
        line.set_x2(Distal, bar_index + 1 )
        line.set_x2(Proximal,  bar_index + 1)
        line.set_x2(DLine50per,  bar_index + 1)
 
    if (low < YDd12) and (low[1] > YDd12)
        DemCounter := DemCounter
        DemCheck := false
        
    if Demand_OB_Condition
        DemCounter := 1
        DemCheck := true
    [xd1, xd2, yd1, yd2, xdnz, md, bd, Ydnz, xdn, Ydn,    xp1, xp2, yp1, yp2, xpnz, mp, bp, Ypnz, xpn, Ypn]
 
 
LinerFunctionSup(Xd1, Yd1, Xd2, Yd2 , Xp1, Yp1, Xp2, Yp2 , Xn) =>
    //y = mx + b
    //m = (y2 - y1) / (x2 - x1)
    //b = y - mx
    xd1 = Xd1
    xd2 = Xd2 
    yd1 = Yd1
    yd2 = Yd2
    xdn = Xn 
    xdnz = Xn 
    md =  (yd2 - yd1) / (xd2 - xd1)
    bd = yd1 - md*xd1 //or b = y2 - m*x2
    Ydnz = md*(xdnz) + bd
    Ydn = md*(xdn) + bd
    xp1 = Xp1
    xp2 = Xp2 
    yp1 = Yp1
    yp2 = Yp2
    xpn = Xn 
    xpnz = Xn 
    mp =  (yp2 - yp1) / (xp2 - xp1)
    bp = yp1 - mp*xp1 //or b = y2 - m*x2
    Ypnz = mp*(xpnz) + bp
    Ypn = mp*(xpn) + bp
    var bool SupCheck = true
    var int SupCounter = 1
    var line Distal = na
    var line Proximal = na
    var line  SLine50per = na
    var linefill fillline = na
    if Supply_OB_Condition
        Distal := line.new(xd1, yd1, xdnz , yd1 , color = color.rgb(0, 0, 0, 45) , style = line.style_dashed , width = 1)
        Proximal := line.new(xp1, yp1, xpnz  , yp1 , color = color.rgb(0, 0, 0 , 45) , style = line.style_dashed , width = 1)
        SLine50per :=line.new(xp1, (yp1+yd1) / 2 , xpnz  , (yp1+yd1) / 2  , color = color.rgb(0, 0, 0) , 
         style = line.style_dotted , width = 1)
        fillline := linefill.new(Distal ,Proximal ,color = SupBxColor )
    if ((high < YSp12) or (xd1 == YSp12[1])) and (SupCheck == true)
        SupCounter := SupCounter + 1
        line.set_x2(Distal, bar_index + 1 )
        line.set_x2(Proximal,  bar_index + 1)
        line.set_x2(SLine50per,  bar_index + 1)
 
    if (high > YSd12) and (high[1] < YSd12)
        SupCounter := SupCounter
        SupCheck := false
 
    if Supply_OB_Condition
        SupCounter := 1
        SupCheck := true
    [xd1, xd2, yd1, yd2, xdnz, md, bd, Ydnz, xdn, Ydn ,   xp1, xp2, yp1, yp2, xpnz, mp, bp, Ypnz, xpn, Ypn]
 
 
[DDx1 , DDx2 , DDy1, DDy2, DDxz, DDm, DDb, DDyz, DDxn, DDyn,    DPx1 , DPx2 , DPy1, DPy2, DPxz, DPm, DPb, DPyz, DPxn, DPyn] = LinerFunctionDem(XDd1, YDd12, XDd2, YDd12,    XDp1, YDp12, XDp2, YDp12 , bar_index) 
[SDx1 , SDx2 , SDy1, SDy2, SDxz, SDm, SDb, SDyz, SDxn, SDyn,    SPx1 , SPx2 , SPy1, SPy2, SPxz, SPm, SPb, SPyz, SPxn, SPyn] = LinerFunctionSup(XSd1, YSd12, XSd2, YSd12 ,   XSp1, YSp12, XSp2, YSp12, bar_index) 
 
 
 
//3 Drive Logic
 
Open = open
High = high
Low = low
Close = close 
Bar_Index = bar_index
 
var ArrayType = array.new_string()
var ArrayValue = array.new_float()
var ArrayIndex =  array.new_int()
var Line = array.new_line()
 
 
HighPivot = ta.pivothigh(PP,PP)
LowPivot = ta.pivotlow(PP,PP)
 
HighValue = ta.valuewhen(HighPivot ,high[PP], 0)
LowValue = ta.valuewhen(LowPivot ,low[PP], 0)
 
HighIndex = ta.valuewhen(HighPivot ,bar_index[PP], 0)
LowIndex = ta.valuewhen(LowPivot ,bar_index[PP], 0)
 
 
Correct_HighPivot = 0.0
Correct_LowPivot =  0.0
 
 
PASS = 0
 
if HighPivot  and  LowPivot
    if ArrayType.size() == 0
        PASS := 1
    else if ArrayType.size() >= 1
        if ((ArrayType.get(ArrayType.size() - 1)) == "L" or
             (ArrayType.get(ArrayType.size() - 1)) == "LL")
            if LowPivot < ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue
            else 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
            Correct_HighPivot := HighValue  
        else if (ArrayType.get(ArrayType.size() - 1)) == "H" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HH"
            if HighPivot > ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue  
            else 
                array.push(ArrayType,ArrayType.size()>2?  ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
            Correct_LowPivot :=  LowValue    
        else if (ArrayType.get(ArrayType.size() - 1)) == "LH"
            if HighPivot < ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2?  ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue 
            else if HighPivot > ArrayValue.get(ArrayType.size() - 1)
                if close < ArrayValue.get(ArrayType.size() - 1)
                    array.remove(ArrayType,ArrayType.size() - 1)
                    array.remove(ArrayValue,ArrayValue.size() - 1)
                    array.remove(ArrayIndex,ArrayIndex.size() - 1)
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                    array.push(ArrayValue, HighValue)
                    array.push(ArrayIndex, HighIndex)
                    Correct_HighPivot := HighValue  
                else if close > ArrayValue.get(ArrayType.size() - 1)
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                    array.push(ArrayValue, LowValue)
                    array.push(ArrayIndex, LowIndex)
                    Correct_LowPivot :=  LowValue
        else if (ArrayType.get(ArrayType.size() - 1)) == "HL"
            if LowPivot > ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue                       
            else if LowPivot < ArrayValue.get(ArrayType.size() - 1)
                if close > ArrayValue.get(ArrayType.size() - 1)
                    array.remove(ArrayType,ArrayType.size() - 1)
                    array.remove(ArrayValue,ArrayValue.size() - 1)
                    array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                    array.push(ArrayValue, LowValue)
                    array.push(ArrayIndex, LowIndex)
                    Correct_LowPivot :=  LowValue
                else if close < ArrayValue.get(ArrayType.size() - 1)
                    array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                    array.push(ArrayValue, HighValue)
                    array.push(ArrayIndex, HighIndex)
                    Correct_HighPivot := HighValue                         
else if  HighPivot 
    if ArrayType.size() == 0
        array.insert(ArrayType, 0, "H")
        array.insert(ArrayValue, 0, HighValue)
        array.insert(ArrayIndex, 0, HighIndex)
        Correct_HighPivot := HighValue
    else if ArrayType.size() >= 1
        if ((ArrayType.get(ArrayType.size() - 1)) == "L" or
             (ArrayType.get(ArrayType.size() - 1)) == "HL" or
             (ArrayType.get(ArrayType.size() - 1)) == "LL")
            if HighPivot > ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H" ) ///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue
            else if  HighPivot < ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue                         
        else if (ArrayType.get(ArrayType.size() - 1)) == "H" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HH" or 
             (ArrayType.get(ArrayType.size() - 1)) == "LH"
            if (ArrayValue.get(ArrayValue.size() - 1)) < HighValue
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue               
else if LowPivot 
    if ArrayType.size() == 0
        array.insert(ArrayType, 0, "L")
        array.insert(ArrayValue, 0, LowValue)
        array.insert(ArrayIndex, 0, LowIndex)
        Correct_LowPivot :=  LowValue
    else if ArrayType.size() >= 1
        if (ArrayType.get(ArrayType.size() - 1)) == "H" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HH" or 
             (ArrayType.get(ArrayType.size() - 1)) == "LH"
            if LowPivot < ArrayValue.get(ArrayType.size() - 1)
                array.push(ArrayType,ArrayType.size()>2?  ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue
            else if LowPivot > ArrayValue.get(ArrayType.size() - 1)
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1)
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < HighValue ? "HH" : "LH" : "H")///////////////////////////////Here
                array.push(ArrayValue, HighValue)
                array.push(ArrayIndex, HighIndex)
                Correct_HighPivot := HighValue                        
        else if (ArrayType.get(ArrayType.size() - 1)) == "L" or 
             (ArrayType.get(ArrayType.size() - 1)) == "HL" or 
             (ArrayType.get(ArrayType.size() - 1)) == "LL"
            if (ArrayValue.get(ArrayValue.size() - 1)) > LowValue
                array.remove(ArrayType,ArrayType.size() - 1)
                array.remove(ArrayValue,ArrayValue.size() - 1)
                array.remove(ArrayIndex,ArrayIndex.size() - 1) 
                array.push(ArrayType,ArrayType.size()>2? ArrayValue.get(ArrayType.size() - 2) < LowValue ? "HL" : "LL" : "L")///////////////////////////////Here
                array.push(ArrayValue, LowValue)
                array.push(ArrayIndex, LowIndex)
                Correct_LowPivot :=  LowValue
 
 
// get data
 
 
var bool Bearish3Drive = false
var bool Be3Druntime = true
 
var bool Bullish3Drive = false
var bool Bu3Druntime = true
 
var string PT1 = ''
var string PT2 = ''
var string PT3 = ''
var string PT4 = ''
var string PT5 = ''
 
var float PV1 = 0.0
var float PV2 = 0.0
var float PV3 = 0.0
var float PV4 = 0.0
var float PV5 = 0.0
 
var int PI1 = 0
var int PI3 = 0
var int PI5 = 0
 
if ArrayType.size() > 6 
    PT1 := ArrayType.get(ArrayType.size() - 1)
    PT2 := ArrayType.get(ArrayType.size() - 2)
    PT3 := ArrayType.get(ArrayType.size() - 3)
    PT4 := ArrayType.get(ArrayType.size() - 4)
    PT5 := ArrayType.get(ArrayType.size() - 5)
    PV1 := ArrayValue.get(ArrayType.size() - 1)
    PV2 := ArrayValue.get(ArrayType.size() - 2)
    PV3 := ArrayValue.get(ArrayType.size() - 3)
    PV4 := ArrayValue.get(ArrayType.size() - 4)
    PV5 := ArrayValue.get(ArrayType.size() - 5)
    PI1 := ArrayIndex.get(ArrayType.size() - 1)
    PI3 := ArrayIndex.get(ArrayType.size() - 3)
    PI5 := ArrayIndex.get(ArrayType.size() - 5)
 
//global condition
X = math.ceil((PI1 - PI5))
INF = math.floor((PI5 + X*0.375))
SUP = math.ceil((PI5 + X*0.625))
global_condition = PI3 > INF and PI3 < SUP
// Bearish 3 Drive
 
 
BeCondition1 = PT1 == 'HH' and  PT2 == 'HL' and  PT3 == 'HH' and  PT4 == 'HL' and  PT5 == 'HH'
BeCondition2 = (PV3-PV2) / (PV1-PV3) > 1  and
 (PV5-PV4) / (PV3-PV5)  > 1 and 
 (PV1 - PV3) / (PV3 - PV5) > 1 and 
 global_condition
 
 
if BeCondition1 and BeCondition2 and Be3Druntime
    Bearish3Drive := true
    Be3Druntime := false
else if PI1 != PI1[1] and PT1 == 'HH'
    Be3Druntime := true
else
    Bearish3Drive := false
    
// Bullish 3 Drive
BuCondition1 = PT1 == 'LL' and  PT2 == 'LH' and  PT3 == 'LL' and  PT4 == 'LH' and  PT5 == 'LL'
BuCondition2 = (PV2-PV3) / (PV3-PV1) > 1  and 
 (PV4-PV5) / (PV5-PV3)  > 1 and 
 (PV3 - PV1) / (PV5 - PV3) > 1 and 
 global_condition
 
 
if BuCondition1 and BuCondition2 and Bu3Druntime
    Bullish3Drive := true
    Bu3Druntime := false
else if PI1 != PI1[1] and PT1 == 'LL'
    Bu3Druntime := true
else
    Bullish3Drive := false
 
plotshape(Bearish3Drive , 
 'Bearish 3 Drive' , 
 style = shape.arrowdown , 
 location = location.abovebar ,
 color   = color.red ,
 textcolor = color.red)
 
plotshape(Bullish3Drive , 
 'Bullish 3 Drive' , 
 style = shape.arrowup , 
 location = location.belowbar ,
 color = color.green , 
 textcolor = color.green )
 
 
Drawing(bullCond , bearCond) =>
    var line BullLine = na
    var line BearLine = na
    BullCond = bullCond
    BearCond = bearCond
 
    if BullCond 
        BullLine := line.new(PI5 , PV5 , PI1 , PV1 , color = color.rgb(35, 124, 38) , style = line.style_dashed)
        label.new(PI5 , PV5 , '1' , color =  color.rgb(35, 124, 38) , textcolor = color.white , size = size.small , style = label.style_label_up)
        label.new(PI3 , line.get_price(BullLine, PI3) , '2' , color =  color.rgb(35, 124, 38) , textcolor = color.white , size = size.small , style = label.style_label_up)
        label.new(PI1 , PV1 , '3' , color =  color.rgb(35, 124, 38) , textcolor = color.white , size = size.small , style = label.style_label_up)
    
    if BearCond
        BearLine := line.new(PI5 , PV5 , PI1 , PV1 , color = color.rgb(212, 16, 16) , style = line.style_dashed)
        label.new(PI5 , PV5 , '1' , color =  color.rgb(212, 16, 16) , textcolor = color.white , size = size.small , style = label.style_label_down)
        label.new(PI3 , line.get_price(BearLine, PI3) , '2' , color =  color.rgb(212, 16, 16) , textcolor = color.white , size = size.small , style = label.style_label_down)
        label.new(PI1 , PV1 , '3' , color =  color.rgb(212, 16, 16) , textcolor = color.white , size = size.small , style = label.style_label_down)
 
 
Drawing(Bullish3Drive , Bearish3Drive)

← 返回列表