Convertir indicateur Pinescript (tradingview) en MQL5

MQL5 Indicateurs

Tâche terminée

Temps d'exécution 11 jours

Spécifications

Bonjour,


Je voudrais convertir cet indicateur Pinescript en MQL5.

Le but étant d'avoir les bougies entourées d'orderblock comme sur Tradingview avec les mêmes options.

L'objectif étant de pouvoir utiliser cet indicateur dans un Expert Advisor et donc il me faudrait aussi des buffers des bougies étant entouré d'orderblock avec High et Low bougies, 0 sinon.


Pinescript : 

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © geneclash

//@version=5
indicator("Fractal Break Imbalance / Fair Value Gap (FVG) / Liquidity Void", format=format.price, precision=0, overlay=true)

showFractals = input(false,title="Show Fractals?",group="Fractals")
showBrekout = input(false,title="Show Market Structure Breakouts?",group="Fractals")
breakType = input.string("Body",title="Fractal Break Type:",options=["Wick+Body","Body"],group="Fractals")
n = input.int(title="Periods", defval=2, minval=2,group="Fractals")
lineStyle= input.string(line.style_dotted,title="Line Style:",options=[line.style_dotted,line.style_dashed,line.style_solid],group="Fractals")
upClr = input.color(color.teal,title="Up/Down Line Colors:",inline="b_1",group="Fractals")
downClr = input.color(color.maroon,title="-",inline="b_1",group="Fractals")

showImbalance = input(true,title="Show Breakout Imbalances",group="Imbalance")
showOtherImbalance = input(true,title="Show Other Imbalances",group="Imbalance")
hideFilled = input(false,title="Hide Filled Gaps",group="Imbalance")
imbGreenClr = input.color(color.new(color.green,65),title="Up:",inline="i_1",group="Imbalance")
imbRedClr = input.color(color.new(color.red,65),title="Down:",inline="i_1",group="Imbalance")
imbRestClr = input.color(color.new(color.yellow,65), title="Other:",inline="i_1",group="Imbalance")

showBoxes = input(false,title="Show OrderBlocks?",group="OrderBlock")
changeColor = input(false,title="Change OrderBlock Colors?",group="OrderBlock")
transGreenClr = input.color(color.new(color.green,80),title="Bg:",inline="a_1",group="OrderBlock")
greenClr = input.color(color.new(color.green,0),title="Border:",inline="a_1",group="OrderBlock")
transRedClr = input.color(color.new(color.red,80),title="Bg:",inline="b_1",group="OrderBlock")
redClr = input.color(color.new(color.red,0),title="Border:",inline="b_1",group="OrderBlock")

//Fractals{
// UpFractal
bool upflagDownFrontier = true
bool upflagUpFrontier0 = true
bool upflagUpFrontier1 = true
bool upflagUpFrontier2 = true
bool upflagUpFrontier3 = true
bool upflagUpFrontier4 = true

for i = 1 to n
    upflagDownFrontier := upflagDownFrontier and (high[n-i] < high[n])
    upflagUpFrontier0 := upflagUpFrontier0 and (high[n+i] < high[n])
    upflagUpFrontier1 := upflagUpFrontier1 and (high[n+1] <= high[n] and high[n+i + 1] < high[n])
    upflagUpFrontier2 := upflagUpFrontier2 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+i + 2] < high[n])
    upflagUpFrontier3 := upflagUpFrontier3 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+i + 3] < high[n])
    upflagUpFrontier4 := upflagUpFrontier4 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+4] <= high[n] and high[n+i + 4] < high[n])
flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4

upFractal = (upflagDownFrontier and flagUpFrontier)

//DownFractal
bool downflagDownFrontier = true
bool downflagUpFrontier0 = true
bool downflagUpFrontier1 = true
bool downflagUpFrontier2 = true
bool downflagUpFrontier3 = true
bool downflagUpFrontier4 = true

for i = 1 to n
    downflagDownFrontier := downflagDownFrontier and (low[n-i] > low[n])
    downflagUpFrontier0 := downflagUpFrontier0 and (low[n+i] > low[n])
    downflagUpFrontier1 := downflagUpFrontier1 and (low[n+1] >= low[n] and low[n+i + 1] > low[n])
    downflagUpFrontier2 := downflagUpFrontier2 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+i + 2] > low[n])
    downflagUpFrontier3 := downflagUpFrontier3 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+i + 3] > low[n])
    downflagUpFrontier4 := downflagUpFrontier4 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+4] >= low[n] and low[n+i + 4] > low[n])
flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4

downFractal = (downflagDownFrontier and flagDownFrontier)
//}

var float topValue = na, var float bottomValue = na
var int lastRedIndex = na, var float lastRedLow = na, var float lastRedHigh = na
var int lastGreenIndex = na, var float lastGreenLow = na, var float lastGreenHigh = na

var line topLine = na, var line bottomLine = na
var box demandBox = na, var box supplyBox = na

var box imbalanceBox = na
var bool checkUpImbalance = false
var bool checkDownImbalance = false

var topBreakBlock = false, var bottomBreakBlock = false
var isLongBreak = false, var isShortBreak = false
var arrBoxes = array.new_box(0)
var arrImbBoxes = array.new_box(0)

topBreakCheckSource = breakType == "Wick+Body" ? high : close
bottomBreakCheckSource = breakType == "Wick+Body" ? low : close

//IMBALANCE
//Data
L1 = low
H3 = high[2]

H1 = high
L3 = low[2]


FVGUp = H3 < L1 ? 1 : 0
plotFVGU = FVGUp ? H3 : na
plotFVGUL = FVGUp ? L1 : na

FVGDown = L3 > H1 ? 1 : 0
plotFVGD = FVGDown ? L3 : na
plotFVGH = FVGDown ? H1 : na

if FVGUp and showOtherImbalance and checkUpImbalance == false
    imbalanceBox := box.new(bar_index-2, plotFVGU,bar_index,plotFVGUL, bgcolor=imbRestClr, border_color=imbRestClr)
    array.push(arrImbBoxes,imbalanceBox)    

if FVGDown and showOtherImbalance and checkDownImbalance == false
    imbalanceBox :=  box.new(bar_index-2, plotFVGH,bar_index,plotFVGD, bgcolor=imbRestClr, border_color=imbRestClr)
    array.push(arrImbBoxes,imbalanceBox)

//Last red check
if close < open
    lastRedIndex := bar_index
    lastRedLow := low
    lastRedHigh := high
   
//Last green check
if close > open
    lastGreenIndex := bar_index
    lastGreenLow := low
    lastGreenHigh := high

//Check Imbalance
if checkUpImbalance
    checkUpImbalance := false
    imbTop = low
    imbBottom = high[2]
    if imbTop > imbBottom and showImbalance
        imbalanceBox := box.new(bar_index-2, imbTop,bar_index,imbBottom, bgcolor=imbGreenClr, border_color=imbGreenClr)
        array.push(arrImbBoxes,imbalanceBox)
        alert("Bullish Imbalance Detected!",freq=alert.freq_once_per_bar_close)
 
if checkDownImbalance
    checkDownImbalance := false
    imbTop = low[2]
    imbBottom = high
    if imbTop > imbBottom and showImbalance
        imbalanceBox := box.new(bar_index-2, imbTop,bar_index,imbBottom, bgcolor=imbRedClr, border_color=imbRedClr)
        array.push(arrImbBoxes,imbalanceBox)
        alert("Bearish Imbalance Detected!",freq=alert.freq_once_per_bar_close)

//Top break
if ta.crossover(topBreakCheckSource,topValue) and topBreakBlock == false
    topBreakBlock := true
    isLongBreak := true
    checkUpImbalance := true
    if showBrekout
        line.set_x2(topLine,bar_index)
    if showBoxes
        demandBox := box.new(lastRedIndex-1, lastRedHigh,lastRedIndex+1,lastRedLow, bgcolor=transGreenClr, border_color=greenClr)
        array.push(arrBoxes,demandBox)

//Bottom break
if ta.crossunder(bottomBreakCheckSource,bottomValue) and bottomBreakBlock == false
    bottomBreakBlock := true
    isShortBreak := true
    checkDownImbalance := true
    if showBrekout
        line.set_x2(bottomLine,bar_index)
    if showBoxes
        supplyBox := box.new(lastGreenIndex-1, lastGreenHigh,lastGreenIndex+1,lastGreenLow, bgcolor=transRedClr, border_color=redClr)
        array.push(arrBoxes,supplyBox)

//New up fractal
if upFractal
    topBreakBlock := false
    isLongBreak := false
    topValue := high[n]
    if showBrekout
        topLine := line.new(bar_index[n],topValue,bar_index,topValue, color=upClr, style=lineStyle, width=2)
        if isLongBreak[1] == false
            line.delete(topLine[1])
   
//New down fractal
if downFractal
    bottomBreakBlock := false
    isShortBreak := false
    bottomValue := low[n]
    if showBrekout
        bottomLine := line.new(bar_index[n],bottomValue,bar_index,bottomValue, color=downClr, style=lineStyle, width=2)
        if isShortBreak[1] == false
            line.delete(bottomLine[1])

//Imbalance Box Update
activeImbBoxes = arrImbBoxes
if array.size(activeImbBoxes) > 0 and hideFilled
    for i = 0 to array.size(activeImbBoxes) - 1
        bVal = box.get_bottom(array.get(activeImbBoxes, i))
        tVal = box.get_top(array.get(activeImbBoxes, i))

        if open > tVal and low < tVal
            box.delete(array.get(activeImbBoxes, i))
        if open < bVal and high > bVal
            box.delete(array.get(activeImbBoxes, i))

//OB Box state update
activeBoxes = arrBoxes
if array.size(activeBoxes) > 0 and changeColor
    for i = 0 to array.size(activeBoxes) - 1
        bVal = box.get_bottom(array.get(activeBoxes, i))
        tVal = box.get_top(array.get(activeBoxes, i))
        if close < bVal
            box.set_bgcolor(array.get(activeBoxes, i),transRedClr)
            box.set_border_color(array.get(activeBoxes, i),redClr)
        if close > tVal
            box.set_bgcolor(array.get(activeBoxes, i),transGreenClr)
            box.set_border_color(array.get(activeBoxes, i),greenClr)

//PLOTS
plotshape(showFractals ? downFractal : na,style=shape.triangleup, location=location.belowbar, offset=-n, color=color.new(color.gray,80), size = size.tiny)
plotshape(showFractals ? upFractal : na, style=shape.triangledown,   location=location.abovebar, offset=-n, color=color.new(color.gray,80), size = size.tiny)


Répondu

1
Développeur 1
Évaluation
(850)
Projets
1455
72%
Arbitrage
122
29% / 48%
En retard
356
24%
Travail
Publié : 3 articles

Informations sur le projet

Budget
45+ USD