Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
26 kB
59
Indexable
Never
//@version=5
strategy("WiliAptal", shorttitle="PRMKNS", format=format.price, precision=0, overlay=true)
// Define "n" as the number of periods and keep a minimum value of 2 for error handling.
n = input.int(title="Periods", defval=34, minval=2)

// 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)

plotshape(downFractal, style=shape.triangledown, location=location.belowbar, offset=-n, color=#F44336, size = size.small, title="Down Fractal")
plotshape(upFractal, style=shape.triangleup,   location=location.abovebar, offset=-n, color=#009688, size = size.small, title="Up Fractal")

var float UST12 = na
var float UST11 = na
var float UST10 = na
var float UST9 = na
var float UST8 = na
var float UST7 = na
var float UST6 = na
var float UST5 = na
var float UST4 = na
var float UST3 = na
var float UST2 = na
var float UST1 = na
var float UST = na

var float ALT12 = na
var float ALT11 = na
var float ALT10 = na
var float ALT9 = na
var float ALT8 = na
var float ALT7 = na
var float ALT6 = na
var float ALT5 = na
var float ALT4 = na
var float ALT3 = na
var float ALT2 = na
var float ALT1 = na
var float ALT = na

if upFractal
    UST12 := UST11
    UST11 := UST10
    UST10 := UST9
    UST9 := UST8
    UST8 := UST7
    UST7 := UST6
    UST6 := UST5
    UST5 := UST4
    UST4 := UST3
    UST3 := UST2
    UST2 := UST1
    UST1 := UST
    UST := high[n]

if downFractal
    ALT12 := ALT11
    ALT11 := ALT10
    ALT10 := ALT9
    ALT9 := ALT8
    ALT8 := ALT7
    ALT7 := ALT6
    ALT6 := ALT5
    ALT5 := ALT4
    ALT4 := ALT3
    ALT3 := ALT2
    ALT2 := ALT1
    ALT1 := ALT
    ALT := low[n]

var float MUST12 = na
var float MUST11 = na
var float MUST10 = na
var float MUST9 = na
var float MUST8 = na
var float MUST7 = na
var float MUST6 = na
var float MUST5 = na
var float MUST4 = na
var float MUST3 = na
var float MUST2 = na
var float MUST1 = na
var float MUST = na

var float MALT12 = na
var float MALT11 = na
var float MALT10 = na
var float MALT9 = na
var float MALT8 = na
var float MALT7 = na
var float MALT6 = na
var float MALT5 = na
var float MALT4 = na
var float MALT3 = na
var float MALT2 = na
var float MALT1 = na
var float MALT = na

if UST12 > UST11 and UST12 > UST10 and UST12 > UST9 and UST12 > UST8 and UST12 > UST7 and UST12 > UST6 and
   UST12 > UST5 and UST12 > UST4 and UST12 > UST3 and UST12 > UST2 and UST12 > UST1 and UST12 > UST
    MUST12 := UST12
if UST11 > UST10 and UST11 > UST9 and UST11 > UST8 and UST11 > UST7 and UST11 > UST6 and
   UST11 > UST5 and UST11 > UST4 and UST11 > UST3 and UST11 > UST2 and UST11 > UST1 and UST11 > UST
    MUST11 := UST11
if UST10 > UST9 and UST10 > UST8 and UST10 > UST7 and UST10 > UST6 and UST10 > UST5 and
   UST10 > UST4 and UST10 > UST3 and UST10 > UST2 and UST10 > UST1 and UST10 > UST
    MUST10 := UST10
if UST9 > UST8 and UST9 > UST7 and UST9 > UST6 and UST9 > UST5 and
   UST9 > UST4 and UST9 > UST3 and UST9 > UST2 and UST9 > UST1 and UST9 > UST
    MUST9 := UST9
if UST8 > UST7 and UST8 > UST6 and UST8 > UST5 and UST8 > UST4 and
   UST8 > UST3 and UST8 > UST2 and UST8 > UST1 and UST8 > UST
    MUST8 := UST8
if UST7 > UST6 and UST7 > UST5 and UST7 > UST4 and
   UST7 > UST3 and UST7 > UST2 and UST7 > UST1 and UST7 > UST
    MUST7 := UST7
if UST6 > UST5 and UST6 > UST4 and
   UST6 > UST3 and UST6 > UST2 and UST6 > UST1 and UST6 > UST
    MUST6 := UST6
if UST5 > UST4 and
   UST5 > UST3 and UST5 > UST2 and UST5 > UST1 and UST5 > UST
    MUST5 := UST5
if UST4 > UST3 and UST4 > UST2 and UST4 > UST1 and UST4 > UST
    MUST4 := UST4
if UST3 > UST2 and UST3 > UST1 and UST3 > UST
    MUST3 := UST3
if UST2 > UST1 and UST2 > UST
    MUST2 := UST2
if UST1 > UST
    MUST1 := UST1
if UST > close
    MUST := UST

if ALT12 < ALT11 and ALT12 < ALT10 and ALT12 < ALT9 and ALT12 < ALT8 and ALT12 < ALT7 and
   ALT12 < ALT6 and ALT12 < ALT5 and ALT12 < ALT4 and ALT12 < ALT3 and ALT12 < ALT2 and ALT12 < ALT1 and ALT12 < ALT
    MALT12 := ALT12
if ALT11 < ALT10 and ALT11 < ALT9 and ALT11 < ALT8 and ALT11 < ALT7 and ALT11 < ALT6 and
   ALT11 < ALT5 and ALT11 < ALT4 and ALT11 < ALT3 and ALT11 < ALT2 and ALT11 < ALT1 and ALT11 < ALT
    MALT11 := ALT11
if ALT10 < ALT9 and ALT10 < ALT8 and ALT10 < ALT7 and ALT10 < ALT6 and ALT10 < ALT5 and
   ALT10 < ALT4 and ALT10 < ALT3 and ALT10 < ALT2 and ALT10 < ALT1 and ALT10 < ALT
    MALT10 := ALT10
if ALT9 < ALT8 and ALT9 < ALT7 and ALT9 < ALT6 and ALT9 < ALT5 and ALT9 < ALT4 and
   ALT9 < ALT3 and ALT9 < ALT2 and ALT9 < ALT1 and ALT9 < ALT
    MALT9 := ALT9
if ALT8 < ALT7 and ALT8 < ALT6 and ALT8 < ALT5 and ALT8 < ALT4 and ALT8 < ALT3 and
   ALT8 < ALT2 and ALT8 < ALT1 and ALT8 < ALT
    MALT8 := ALT8
if ALT7 < ALT6 and ALT7 < ALT5 and ALT7 < ALT4 and ALT7 < ALT3 and ALT7 < ALT2 and
   ALT7 < ALT1 and ALT7 < ALT
    MALT7 := ALT7
if ALT6 < ALT5 and ALT6 < ALT4 and ALT6 < ALT3 and ALT6 < ALT2 and ALT6 < ALT1 and ALT6 < ALT
    MALT6 := ALT6
if ALT5 < ALT4 and ALT5 < ALT3 and ALT5 < ALT2 and ALT5 < ALT1 and ALT5 < ALT
    MALT5 := ALT5
if ALT4 < ALT3 and ALT4 < ALT2 and ALT4 < ALT1 and ALT4 < ALT
    MALT4 := ALT4
if ALT3 < ALT2 and ALT3 < ALT1 and ALT3 < ALT
    MALT3 := ALT3
if ALT2 < ALT1 and ALT2 < ALT
    MALT2 := ALT2
if ALT1 < ALT
    MALT1 := ALT1
if ALT < close
    MALT := ALT


fibonacciLevels(MALT, MUST) =>
    length = MUST - MALT

    fib0 = MUST
    fib1_618 = MALT + length * 1.618
    fib34 = MALT + length * 0.34
    fib50 = MALT + length * 0.5
    fib66 = MALT + length * 0.666
    fib100 = MALT

    [fib0, fib1_618, fib34, fib50, fib66, fib100]

//MUST ve MALT için long short koşulları
if high > MUST
    var float long_entry = na
    [fib0, fib1_618, fib34, fib50, fib66, fib100] = fibonacciLevels(MALT, MUST)
    long_entry := fib34

    if not na(long_entry)
        strategy.entry("Long", strategy.long, limit=long_entry)
        strategy.exit("SL/TL", "Long", stop=fib100, limit=fib0)

if low < MALT
    var float short_entry = na
    [fib0, fib1_618, fib34, fib50, fib66, fib100] = fibonacciLevels(MALT, MUST)
    short_entry := fib66

    if not na (short_entry)
        strategy.entry("Short", strategy.short, limit=short_entry)
        strategy.exit("SS/TS", "Short", stop=fib0, limit=fib100)

// MUST1 ve MALT1 için long short koşulları
fibonacciLevels_1(MALT1, MUST1) =>
    length = MUST1 - MALT1

    Afib0 = MUST1
    Afib1_618 = MALT1 + length * 1.618
    Afib34 = MALT1 + length * 0.34
    Afib50 = MALT1 + length * 0.5
    Afib66 = MALT1 + length * 0.666
    Afib100 = MALT1

    [Afib0, Afib1_618, Afib34, Afib50, Afib66, Afib100]

if high > MUST1
    MALT1_K = math.min(MALT,MALT1,MALT2)
    var float long_entry_1 = na
    [Afib0, Afib1_618, Afib34, Afib50, Afib66, Afib100] = fibonacciLevels_1(MALT1_K, MUST1)
    long_entry_1 := Afib34

    if not na(long_entry_1)
        strategy.entry("Long_1", strategy.long, limit=long_entry_1)
        strategy.exit("SL_1/TL_1", "Long_1", stop=Afib100, limit=Afib0)

if low < MALT1
    MUST1_B = math.max(MUST,MUST1,MUST2)
    var float short_entry_1 = na
    [Afib0, Afib1_618, Afib34, Afib50, Afib66, Afib100] = fibonacciLevels_1(MALT1, MUST1_B)
    short_entry_1 := Afib66

    if not na (short_entry_1)
        strategy.entry("Short_1", strategy.short, limit=short_entry_1)
        strategy.exit("SS_1/TS_1", "Short_1", stop=Afib0, limit=Afib100)


// MUST2 ve MALT2 için long short koşulları
fibonacciLevels_2(MALT2, MUST2) =>
    length = MUST2 - MALT2

    Bfib0 = MUST2
    Bfib1_618 = MALT2 + length * 1.618
    Bfib34 = MALT2 + length * 0.34
    Bfib50 = MALT2 + length * 0.5
    Bfib66 = MALT2 + length * 0.666
    Bfib100 = MALT2

    [Bfib0, Bfib1_618, Bfib34, Bfib50, Bfib66, Bfib100]

if high > MUST2
    MALT2_K = math.min(MALT, MALT1, MALT2,MALT3)
    var float long_entry_2 = na
    [Bfib0, Bfib1_618, Bfib34, Bfib50, Bfib66, Bfib100] = fibonacciLevels_2(MALT2_K, MUST2)
    long_entry_2 := Bfib34

    if not na(long_entry_2)
        strategy.entry("Long_2", strategy.long, limit=long_entry_2)
        strategy.exit("SL_2/TL_2", "Long_2", stop=Bfib100, limit=Bfib0)


if low < MALT2
    MUST2_B = math.max(MUST, MUST1, MUST2,MUST3)
    var float short_entry_2 = na
    [Bfib0, Bfib1_618, Bfib34, Bfib50, Bfib66, Bfib100] = fibonacciLevels_2(MALT2, MUST2_B)
    short_entry_2 := Bfib66

    if not na (short_entry_2)
        strategy.entry("Short_2", strategy.short, limit=short_entry_2)
        strategy.exit("SS_2/TS_2", "Short_2", stop=Bfib0, limit=Bfib100)

// MUST3 ve MALT3 için long short koşulları
fibonacciLevels_3(MALT3, MUST3) =>
    length = MUST3 - MALT3

    Cfib0 = MUST3
    Cfib1_618 = MALT3 + length * 1.618
    Cfib34 = MALT3 + length * 0.34
    Cfib50 = MALT3 + length * 0.5
    Cfib66 = MALT3 + length * 0.666
    Cfib100 = MALT3

    [Cfib0, Cfib1_618, Cfib34, Cfib50, Cfib66, Cfib100]

if high > MUST3
    MALT3_K = math.min(MALT, MALT1, MALT2, MALT3,MALT4)
    var float long_entry_3 = na
    [Cfib0, Cfib1_618, Cfib34, Cfib50, Cfib66, Cfib100] = fibonacciLevels_3(MALT3_K, MUST3)
    long_entry_3 := Cfib34

    if not na(long_entry_3)
        strategy.entry("Long_3", strategy.long, limit=long_entry_3)
        strategy.exit("SL_3/TL_3", "Long_3", stop=Cfib100, limit=Cfib0)


if low < MALT3
    MUST3_B = math.max(MUST, MUST1, MUST2, MUST3,MUST4)
    var float short_entry_3 = na
    [Cfib0, Cfib1_618, Cfib34, Cfib50, Cfib66, Cfib100] = fibonacciLevels_3(MALT3, MUST3_B)
    short_entry_3 := Cfib66

    if not na (short_entry_3)
        strategy.entry("Short_3", strategy.short, limit=short_entry_3)
        strategy.exit("SS_3/TS_3", "Short_3", stop=Cfib0, limit=Cfib100)

// MUST4 ve MALT4 için long short koşulları
fibonacciLevels_4(MALT4, MUST4) =>
    length = MUST4 - MALT4

    Dfib0 = MUST4
    Dfib1_618 = MALT4 + length * 1.618
    Dfib34 = MALT4 + length * 0.34
    Dfib50 = MALT4 + length * 0.5
    Dfib66 = MALT4 + length * 0.666
    Dfib100 = MALT4

    [Dfib0, Dfib1_618, Dfib34, Dfib50, Dfib66, Dfib100]

if high > MUST4
    MALT4_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4,MALT5)
    var float long_entry_4 = na
    [Dfib0, Dfib1_618, Dfib34, Dfib50, Dfib66, Dfib100] = fibonacciLevels_4(MALT4_K, MUST4)
    long_entry_4 := Dfib34

    if not na(long_entry_4)
        strategy.entry("Long_4", strategy.long, limit=long_entry_4)
        strategy.exit("SL_4/TL_4", "Long_4", stop=Dfib100, limit=Dfib0)


if low < MALT4
    MUST4_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4,MUST5)
    var float short_entry_4 = na
    [Dfib0, Dfib1_618, Dfib34, Dfib50, Dfib66, Dfib100] = fibonacciLevels_4(MALT4, MUST4_B)
    short_entry_4 := Dfib66

    if not na (short_entry_4)
        strategy.entry("Short_4", strategy.short, limit=short_entry_4)
        strategy.exit("SS_4/TS_4", "Short_4", stop=Dfib0, limit=Dfib100)

// MUST5 ve MALT5 için long short koşulları
fibonacciLevels_5(MALT5, MUST5) =>
    length = MUST5 - MALT5

    Efib0 = MUST5
    Efib1_618 = MALT5 + length * 1.618
    Efib34 = MALT5 + length * 0.34
    Efib50 = MALT5 + length * 0.5
    Efib66 = MALT5 + length * 0.666
    Efib100 = MALT5

    [Efib0, Efib1_618, Efib34, Efib50, Efib66, Efib100]

if high > MUST5
    MALT5_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5,MALT6)
    var float long_entry_5 = na
    [Efib0, Efib1_618, Efib34, Efib50, Efib66, Efib100] = fibonacciLevels_5(MALT5_K, MUST5)
    long_entry_5 := Efib34

    if not na(long_entry_5)
        strategy.entry("Long_5", strategy.long, limit=long_entry_5)
        strategy.exit("SL_5/TL_5", "Long_5", stop=Efib100, limit=Efib0)


if low < MALT5
    MUST5_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5,MUST6)
    var float short_entry_5 = na
    [Efib0, Efib1_618, Efib34, Efib50, Efib66, Efib100] = fibonacciLevels_5(MALT5, MUST5_B)
    short_entry_5 := Efib66

    if not na (short_entry_5)
        strategy.entry("Short_5", strategy.short, limit=short_entry_5)
        strategy.exit("SS_5/TS_5", "Short_5", stop=Efib0, limit=Efib100)

// MUST6 ve MALT6 için long short koşulları
fibonacciLevels_6(MALT6, MUST6) =>
    length = MUST6 - MALT6

    Ffib0 = MUST6
    Ffib1_618 = MALT6 + length * 1.618
    Ffib34 = MALT6 + length * 0.34
    Ffib50 = MALT6 + length * 0.5
    Ffib66 = MALT6 + length * 0.666
    Ffib100 = MALT6

    [Ffib0, Ffib1_618, Ffib34, Ffib50, Ffib66, Ffib100]

if high > MUST6
    MALT6_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6,MALT7)
    var float long_entry_6 = na
    [Ffib0, Ffib1_618, Ffib34, Ffib50, Ffib66, Ffib100] = fibonacciLevels_6(MALT6_K, MUST6)
    long_entry_6 := Ffib34

    if not na(long_entry_6)
        strategy.entry("Long_6", strategy.long, limit=long_entry_6)
        strategy.exit("SL_6/TL_6", "Long_6", stop=Ffib100, limit=Ffib0)


if low < MALT6
    MUST6_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6,MUST7)
    var float short_entry_6 = na
    [Ffib0, Ffib1_618, Ffib34, Ffib50, Ffib66, Ffib100] = fibonacciLevels_6(MALT6, MUST6_B)
    short_entry_6 := Ffib66

    if not na (short_entry_6)
        strategy.entry("Short_6", strategy.short, limit=short_entry_6)
        strategy.exit("SS_6/TS_6", "Short_6", stop=Ffib0, limit=Ffib100)

// MUST7 ve MALT7 için long short koşulları
fibonacciLevels_7(MALT7, MUST7) =>
    length = MUST7 - MALT7

    Gfib0 = MUST7
    Gfib1_618 = MALT7 + length * 1.618
    Gfib34 = MALT7 + length * 0.34
    Gfib50 = MALT7 + length * 0.5
    Gfib66 = MALT7 + length * 0.666
    Gfib100 = MALT7

    [Gfib0, Gfib1_618, Gfib34, Gfib50, Gfib66, Gfib100]

if high > MUST7
    MALT7_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6, MALT7,MALT8)
    var float long_entry_7 = na
    [Gfib0, Gfib1_618, Gfib34, Gfib50, Gfib66, Gfib100] = fibonacciLevels_7(MALT7_K, MUST7)
    long_entry_7 := Gfib34

    if not na(long_entry_7)
        strategy.entry("Long_7", strategy.long, limit=long_entry_7)
        strategy.exit("SL_7/TL_7", "Long_7", stop=Gfib100, limit=Gfib0)


if low < MALT7
    MUST7_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6, MUST7,MUST8)
    var float short_entry_7 = na
    [Gfib0, Gfib1_618, Gfib34, Gfib50, Gfib66, Gfib100] = fibonacciLevels_7(MALT7, MUST7_B)
    short_entry_7 := Gfib66

    if not na (short_entry_7)
        strategy.entry("Short_7", strategy.short, limit=short_entry_7)
        strategy.exit("SS_7/TS_7", "Short_7", stop=Gfib0, limit=Gfib100)

// MUST8 ve MALT8 için long short koşulları
fibonacciLevels_8(MALT8, MUST8) =>
    length = MUST8 - MALT8

    Hfib0 = MUST8
    Hfib1_618 = MALT8 + length * 1.618
    Hfib34 = MALT8 + length * 0.34
    Hfib50 = MALT8 + length * 0.5
    Hfib66 = MALT8 + length * 0.666
    Hfib100 = MALT8

    [Hfib0, Hfib1_618, Hfib34, Hfib50, Hfib66, Hfib100]

if high > MUST8
    MALT8_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6, MALT7, MALT8,MALT9)
    var float long_entry_8 = na
    [Hfib0, Hfib1_618, Hfib34, Hfib50, Hfib66, Hfib100] = fibonacciLevels_8(MALT8_K, MUST8)
    long_entry_8 := Hfib34

    if not na(long_entry_8)
        strategy.entry("Long_8", strategy.long, limit=long_entry_8)
        strategy.exit("SL_8/TL_8", "Long_8", stop=Hfib100, limit=Hfib0)


if low < MALT8
    MUST8_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6, MUST7, MUST8,MUST9)
    var float short_entry_8 = na
    [Hfib0, Hfib1_618, Hfib34, Hfib50, Hfib66, Hfib100] = fibonacciLevels_8(MALT8, MUST8_B)
    short_entry_8 := Hfib66

    if not na (short_entry_8)
        strategy.entry("Short_8", strategy.short, limit=short_entry_8)
        strategy.exit("SS_8/TS_8", "Short_8", stop=Hfib0, limit=Hfib100)

// MUST9 ve MALT9 için long short koşulları
fibonacciLevels_9(MALT9, MUST9) =>
    length = MUST9 - MALT9

    Ifib0 = MUST9
    Ifib1_618 = MALT9 + length * 1.618
    Ifib34 = MALT9 + length * 0.34
    Ifib50 = MALT9 + length * 0.5
    Ifib66 = MALT9 + length * 0.666
    Ifib100 = MALT9

    [Ifib0, Ifib1_618, Ifib34, Ifib50, Ifib66, Ifib100]

if high > MUST9
    MALT9_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6, MALT7, MALT8, MALT9,MALT10)
    var float long_entry_9 = na
    [Ifib0, Ifib1_618, Ifib34, Ifib50, Ifib66, Ifib100] = fibonacciLevels_9(MALT9_K, MUST9)
    long_entry_9 := Ifib34

    if not na(long_entry_9)
        strategy.entry("Long_9", strategy.long, limit=long_entry_9)
        strategy.exit("SL_9/TL_9", "Long_9", stop=Ifib100, limit=Ifib0)


if low < MALT9
    MUST9_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6, MUST7, MUST8, MUST9,MUST10)
    var float short_entry_9 = na
    [Ifib0, Ifib1_618, Ifib34, Ifib50, Ifib66, Ifib100] = fibonacciLevels_9(MALT9, MUST9_B)
    short_entry_9 := Ifib66

    if not na (short_entry_9)
        strategy.entry("Short_9", strategy.short, limit=short_entry_9)
        strategy.exit("SS_9/TS_9", "Short_9", stop=Ifib0, limit=Ifib100)

// MUST10 ve MALT10 için long short koşulları
fibonacciLevels_10(MALT10, MUST10) =>
    length = MUST10 - MALT10

    Jfib0 = MUST10
    Jfib1_618 = MALT10 + length * 1.618
    Jfib34 = MALT10 + length * 0.34
    Jfib50 = MALT10 + length * 0.5
    Jfib66 = MALT10 + length * 0.666
    Jfib100 = MALT10

    [Jfib0, Jfib1_618, Jfib34, Jfib50, Jfib66, Jfib100]

if high > MUST10
    MALT10_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6, MALT7, MALT8, MALT9, MALT10,MALT11)
    var float long_entry_10 = na
    [Jfib0, Jfib1_618, Jfib34, Jfib50, Jfib66, Jfib100] = fibonacciLevels_10(MALT10_K, MUST10)
    long_entry_10 := Jfib34

    if not na(long_entry_10)
        strategy.entry("Long_10", strategy.long, limit=long_entry_10)
        strategy.exit("SL_10/TL_10", "Long_10", stop=Jfib100, limit=Jfib0)


if low < MALT10
    MUST10_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6, MUST7, MUST8, MUST9, MUST10,MUST11)
    var float short_entry_10 = na
    [Jfib0, Jfib1_618, Jfib34, Jfib50, Jfib66, Jfib100] = fibonacciLevels_10(MALT10, MUST10_B)
    short_entry_10 := Jfib66

    if not na (short_entry_10)
        strategy.entry("Short_10", strategy.short, limit=short_entry_10)
        strategy.exit("SS_10/TS_10", "Short_10", stop=Jfib0, limit=Jfib100)

// MUST11 ve MALT11 için long short koşulları
fibonacciLevels_11(MALT11, MUST11) =>
    length = MUST11 - MALT11

    Kfib0 = MUST11
    Kfib1_618 = MALT11 + length * 1.618
    Kfib34 = MALT11 + length * 0.34
    Kfib50 = MALT11 + length * 0.5
    Kfib66 = MALT11 + length * 0.666
    Kfib100 = MALT11

    [Kfib0, Kfib1_618, Kfib34, Kfib50, Kfib66, Kfib100]

if high > MUST11
    MALT11_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6, MALT7, MALT8, MALT9, MALT10, MALT11,MALT12)
    var float long_entry_11 = na
    [Kfib0, Kfib1_618, Kfib34, Kfib50, Kfib66, Kfib100] = fibonacciLevels_11(MALT11_K, MUST11)
    long_entry_11 := Kfib34

    if not na(long_entry_11)
        strategy.entry("Long_11", strategy.long, limit=long_entry_11)
        strategy.exit("SL_11/TL_11", "Long_11", stop=Kfib100, limit=Kfib0)


if low < MALT11
    MUST11_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6, MUST7, MUST8, MUST9, MUST10, MUST11,MUST12)
    var float short_entry_11 = na
    [Kfib0, Kfib1_618, Kfib34, Kfib50, Kfib66, Kfib100] = fibonacciLevels_11(MALT11, MUST11_B)
    short_entry_11 := Kfib66

    if not na (short_entry_11)
        strategy.entry("Short_11", strategy.short, limit=short_entry_11)
        strategy.exit("SS_11/TS_11", "Short_11", stop=Kfib0, limit=Kfib100)

// MUST12 ve MALT12 için long short koşulları
fibonacciLevels_12(MALT12, MUST12) =>
    length = MUST12 - MALT12

    Lfib0 = MUST12
    Lfib1_618 = MALT12 + length * 1.618
    Lfib34 = MALT12 + length * 0.34
    Lfib50 = MALT12 + length * 0.5
    Lfib66 = MALT12 + length * 0.666
    Lfib100 = MALT12

    [Lfib0, Lfib1_618, Lfib34, Lfib50, Lfib66, Lfib100]

if high > MUST12
    MALT12_K = math.min(MALT, MALT1, MALT2, MALT3, MALT4, MALT5, MALT6, MALT7, MALT8, MALT9, MALT10, MALT11, MALT12)
    var float long_entry_12 = na
    [Lfib0, Lfib1_618, Lfib34, Lfib50, Lfib66, Lfib100] = fibonacciLevels_12(MALT12_K, MUST12)
    long_entry_12 := Lfib34

    if not na(long_entry_12)
        strategy.entry("Long_12", strategy.long, limit=long_entry_12)
        strategy.exit("SL_12/TL_12", "Long_12", stop=Lfib100, limit=Lfib0)


if low < MALT12
    MUST12_B = math.max(MUST, MUST1, MUST2, MUST3, MUST4, MUST5, MUST6, MUST7, MUST8, MUST9, MUST10, MUST11, MUST12)
    var float short_entry_12 = na
    [Lfib0, Lfib1_618, Lfib34, Lfib50, Lfib66, Lfib100] = fibonacciLevels_12(MALT12, MUST12_B)
    short_entry_12 := Lfib66

    if not na (short_entry_12)
        strategy.entry("Short_12", strategy.short, limit=short_entry_12)
        strategy.exit("SS_12/TS_12", "Short_12", stop=Lfib0, limit=Lfib100)





// plot(MUST, title="MUST", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST1, title="MUST1", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST2, title="MUST2", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST3, title="MUST3", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST4, title="MUST4", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST5, title="MUST5", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST6, title="MUST6", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST7, title="MUST7", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST8, title="MUST8", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST9, title="MUST9", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST10, title="MUST10", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST11, title="MUST11", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)
// plot(MUST12, title="MUST12", color=color.rgb(129, 141, 130), linewidth=2, style=plot.style_line, show_last=13)

// plot(MALT, title="MALT", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT1, title="MALT1", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT2, title="MALT2", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT3, title="MALT3", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT4, title="MALT4", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT5, title="MALT5", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT6, title="MALT6", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT7, title="MALT7", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT8, title="MALT8", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT9, title="MALT9", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT10, title="MALT10", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT11, title="MALT11", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
// plot(MALT12, title="MALT12", color=color.red, linewidth=2, style=plot.style_line, show_last=13)
Leave a Comment