Need a quick conversion of an indicator to MT4 indicator

MQL4 지표 전환

작업 종료됨

실행 시간 6 일

명시

//@version=5
indicator("The LI",overlay=true,max_lines_count = 500, max_labels_count = 500)

Mode2 = true
Mode3 = true
MaxLines = input(25)
RemoveLabelWhenLineIsBroken = input(true)

LineC1 = input.color(color.black,"High Line",inline='l1',group="UI Settings")
LineT1 = input.string("Solid","Style",options=["Solid","Dashed","Dotted"],inline='l1',group="UI Settings")
LineW1 = input.int(1,"Width",minval=1,inline='l1',group="UI Settings")

LineC2 = input.color(color.black,"Low Line",inline='l2',group="UI Settings")
LineT2 = input.string("Solid","Style",options=["Solid","Dashed","Dotted"],inline='l2',group="UI Settings")
LineW2 = input.int(1,"Width",minval=1,inline='l2',group="UI Settings")

HighLabel = input.string("xcross",options=["none","xcross","cross","circle","diamond","square","flag" ,"arrowdown","arrowup","triangleup","triangledown"],group="UI Settings",inline='hl1')
Color1 = input(color.red,"",inline='hl1',group="UI Settings")
LowLabel = input.string("xcross",options=["none","xcross","cross","circle","diamond","square","flag" ,"arrowdown","arrowup","triangleup","triangledown"],group="UI Settings",inline='hl2')
Color2 = input(color.red,"",inline='hl2',group="UI Settings")
LabelSize = input.string("Auto",options=["Auto","Huge","Large","Normal","Small","Tiny"],group="UI Settings")

LineText1 = input.string("","High Text",inline='lt1',group="Line Text")
LineTextColor1 = input.color(color.red,"",inline='lt1',group="Line Text")
LineTextAlign1 = input.string("Center","Align",options=['Center','Left','Right'],inline='lt1',group="Line Text")
LineTextSize1 = input.string("Normal","Size",options=["Auto","Huge","Large","Normal","Small","Tiny"],inline='lt1',group="Line Text")

LineText2 = input.string("","Low Text",inline='lt2',group="Line Text")
LineTextColor2 = input.color(color.red,"",inline='lt2',group="Line Text")
LineTextAlign2 = input.string("Center","Align",options=['Center','Left','Right'],inline='lt2',group="Line Text")
LineTextSize2 = input.string("Normal","Size",options=["Auto","Huge","Large","Normal","Small","Tiny"],inline='lt2',group="Line Text")

LabelSizesToEnum(s) =>
    switch s
        "Auto" => size.auto
        "Huge" => size.huge
        "Large" => size.large
        "Normal" => size.normal
        "Small" => size.small
        "Tiny" => size.tiny

LabelStylesToEnum(s) =>
    switch s
        "xcross" => label.style_xcross
        "cross" => label.style_cross
        "circle" => label.style_circle
        "diamond" => label.style_diamond
        "square" => label.style_square
        "flag" => label.style_flag
        "arrowdown" => label.style_arrowdown
        "arrowup" => label.style_arrowup
        "triangleup" => label.style_triangleup
        "triangledown" => label.style_triangledown
        "none" => label.style_none
        
StyleToEnum(s) =>
    switch s
        "Solid" => line.style_solid
        "Dashed" => line.style_dashed
        "Dotted" => line.style_dotted

RedCandle = close < open
GreenCandle = close > open

StandHigh = high[1] >= high and high[1] >= high[2]
StandLow = low[1] <= low and low[1] <= low[2]

TFUpdateNeeded(tf) =>
    if timeframe.period == '1'
        ta.barssince(ta.change(time(tf))) == 0
    else
        v_xx1 = ta.barssince(ta.change(time(tf)) != 0 ? true : false)
        var float v_xx2 = na
        if v_xx1 == 0
            v_xx2 := v_xx1[1]
        v_xx2==v_xx1
    
var Levels = array.new<float>()
var Levels_t = array.new<int>()
var Levels_c = array.new<int>()

dt = time - time[1]

AddLevel(p,t,c) =>
    array.push(Levels,p)
    array.push(Levels_t,t)
    array.push(Levels_c,c)

if Mode2
    if StandHigh
        AddLevel(high[1],time[1],1)
        label.new(time[1],high[1],yloc=yloc.abovebar,xloc=xloc.bar_time,style=LabelStylesToEnum(HighLabel),size=LabelSizesToEnum(LabelSize),color=Color1)
        
    if StandLow
        AddLevel(low[1],time[1],2)
        label.new(time[1],low[1],yloc=yloc.belowbar,xloc=xloc.bar_time,style=LabelStylesToEnum(LowLabel),size=LabelSizesToEnum(LabelSize),color=Color2)
    
    
var int lastRed = 0
var int lastGreen = 0

if Mode3
    if GreenCandle[2]
        if high[2] > high[1] and low[2] > low
            i = 2
            label.new(time[i],high[i],yloc=yloc.abovebar,xloc=xloc.bar_time,style=LabelStylesToEnum(HighLabel),size=LabelSizesToEnum(LabelSize),color=Color1)
            array.push(Levels,high[i])
            array.push(Levels_t,time[i])
            array.push(Levels_c,1)
    
    
    if RedCandle[2]
        if low[2] < low[1] and high[2] < high
            i = 2
            label.new(time[i],low[i],yloc=yloc.belowbar,xloc=xloc.bar_time,style=LabelStylesToEnum(LowLabel),size=LabelSizesToEnum(LabelSize),color=Color2)
            array.push(Levels,low[i])
            array.push(Levels_t,time[i])
            array.push(Levels_c,2)


CandleIsTouching(x) =>
    low < x and high > x
    
DeleteLabelForline(l) =>
    bi = line.get_x1(l)
    a_allLabels = label.all
    if array.size(a_allLabels) > 0
    for i = 0 to array.size(a_allLabels) - 1
        lbl = array.get(a_allLabels, i)
        if label.get_x(lbl) == bi
        label.delete(lbl)

DrawText(t1,t2,p,txt,align,c,s) =>
    if str.length(txt) > 0
        len = math.abs(t1 - t2) / dt
        if align == 'Center'
            label.new(t1+len*dt/2,p,txt,xloc=xloc.bar_time,style=label.style_none,textcolor=c,textalign=text.align_center,size=s)
        else if align == 'Left'
            label.new(t1,p,txt,xloc=xloc.bar_time,style=label.style_none,textcolor=c,textalign=text.align_center,size=s)
        else if align == 'Right'
            label.new(t2,p,txt,xloc=xloc.bar_time,style=label.style_none,textcolor=c,textalign=text.align_center,size=s)

bool looper = true
varip int LastAlertT = 0
while looper
    looper := false
    if array.size(Levels) > 0
        for i = 0 to array.size(Levels) - 1
            lvl = array.get(Levels,i) 
            t = array.get(Levels_t,i) 
            c = array.get(Levels_c,i) 
            if CandleIsTouching(lvl)
                len = (time - t) / dt
                
                if len >= 1
                    ln = if c == 1
                        DrawText(t,time,lvl,LineText1,LineTextAlign1,LineTextColor1,LabelSizesToEnum(LineTextSize1))
                        line.new(t,lvl,time,lvl,xloc=xloc.bar_time,color=LineC1,style=StyleToEnum(LineT1),width=LineW1)
                    else if c == 2 
                        DrawText(t,time,lvl,LineText2,LineTextAlign2,LineTextColor2,LabelSizesToEnum(LineTextSize2))
                        line.new(t,lvl,time,lvl,xloc=xloc.bar_time,color=LineC2,style=StyleToEnum(LineT2),width=LineW2)
                    if RemoveLabelWhenLineIsBroken
                        DeleteLabelForline(ln)

                if time - LastAlertT > 1000*5
                    LastAlertT := time
                    if c == 1
                        alert(syminfo.ticker + " High Taken [" + timeframe.period + "]",alert.freq_all)
                    else
                        alert(syminfo.ticker + " Low Taken [" + timeframe.period + "]",alert.freq_all)
                    
                array.remove(Levels,i)
                array.remove(Levels_t,i)
                array.remove(Levels_c,i)
                looper := true
                break

if barstate.islast
    Arr = line.all
    
    while array.size(line.all) > MaxLines
        //remove the oldest line
        int oldT = na
        int OldIdx = na
        if array.size(Arr) > 0
            for i = 0 to array.size(Arr)-1
                l = array.get(Arr,i)
                lx1 = line.get_x1(l)
                if na(oldT)
                    oldT := lx1
                    OldIdx := i
                else
                    if oldT > lx1
                        oldT := lx1
                        OldIdx := i
            if not na(OldIdx)
                lbl = array.get(Arr,OldIdx)
                DeleteLabelForline(lbl)
                line.delete(lbl)

응답함

1
개발자 1
등급
(56)
프로젝트
92
62%
중재
0
기한 초과
4
4%
무료

프로젝트 정보

예산
30+ USD
기한
 1 일