Jigga - Survival Level
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jigneshjc

//@version=5
strategy("Jigga - Survival Level", shorttitle='Jigga - Survival Level', overlay=true)

doBackTesting = input(false, 'Run Back Testing')

entryCondition = false
exitCondition = false


ab21 =  14,  gh41 = ab21
gh42 = ab21, ju51 = 14
ki61 = ju51
lkolkp = true ,ab22 = 58
cd31 = 5 , ab23 = 42
aa12 = 29, cd32 = 26
op71 = 5,  aa11 = 12
aa13 = 9, op72 = 2.0
movnwx = false


kahachale(byju, h, l) =>
    mika = ta.change(h)
    awer = -ta.change(l)
    uikmhDM = na(mika) ? na : mika > awer and mika > 0 ? mika : 0
    wrtdfcDM = na(awer) ? na : awer > mika and awer > 0 ? awer : 0
    bbct = ta.rma(ta.tr, byju)
    uikmh = fixnan(100 * ta.rma(uikmhDM, byju) / bbct)
    wrtdfc = fixnan(100 * ta.rma(wrtdfcDM, byju) / bbct)
    [uikmh, wrtdfc]

trial(gh42, gh41, h, l) =>
    [uikmh, wrtdfc] = kahachale(gh42, h, l)
    uuolop = uikmh + wrtdfc
    trial = 100 * ta.rma(math.abs(uikmh - wrtdfc) / (uuolop == 0 ? 1 : uuolop), gh41)
    trial

_pr(src, byjugth) =>
    max = ta.highest(byjugth)
    min = ta.lowest(byjugth)
    100 * (src - max) / (max - min)


kyukarna(khulmkhula, mikaarwala, nichewala, bandhwala, partiwala) =>

    sig = trial(gh42, gh41, mikaarwala, nichewala)
    trialIncreasing = sig > ta.ema(sig, 5) ? lkolkp : movnwx

    rolkmn = ta.ema(bandhwala, aa11)
    psolkmn = ta.ema(bandhwala, aa12)
    ujghd = rolkmn - psolkmn
    wrtycv = ta.ema(ujghd, aa13)
    kimnjg = ujghd - wrtycv


    mikalilo = ta.rma(math.max(ta.change(bandhwala), 0), ab21)
    awerlilo = ta.rma(-math.min(ta.change(bandhwala), 0), ab21)
    lilo = awerlilo == 0 ? 100 : mikalilo == 0 ? 0 : 100 - 100 / (1 + mikalilo / awerlilo)
    juylknlilo = ta.ema(lilo, 3)


    rjuylkn = ta.ema(bandhwala, cd31)
    psjuylkn = ta.ema(bandhwala, cd32)

    percentR = _pr(bandhwala, ju51)
    juylknpercentR = ta.ema(percentR, 3)


    ad = bandhwala == mikaarwala and bandhwala == nichewala or mikaarwala == nichewala ? 0 : (2 * bandhwala - nichewala - mikaarwala) / (mikaarwala - nichewala) * partiwala
    kiloValue = math.sum(ad, ki61) / math.sum(partiwala, ki61)



    liiopn = ta.atr(op71)
    mikaliiopn = (mikaarwala + nichewala) / 2 - op72 * liiopn
    mika1liiopn = nz(mikaliiopn[1], mikaliiopn)
    mikaliiopn := bandhwala[1] > mika1liiopn ? math.max(mikaliiopn, mika1liiopn) : mikaliiopn
    dnliiopn = (mikaarwala + nichewala) / 2 + op72 * liiopn
    dn1liiopn = nz(dnliiopn[1], dnliiopn)
    dnliiopn := bandhwala[1] < dn1liiopn ? math.min(dnliiopn, dn1liiopn) : dnliiopn
    omnerliiopn = 1
    omnerliiopn := nz(omnerliiopn[1], omnerliiopn)
    omnerliiopn := omnerliiopn == -1 and bandhwala > dn1liiopn ? 1 : omnerliiopn == 1 and bandhwala < mika1liiopn ? -1 : omnerliiopn

    fitur = ujghd > 0 ? ujghd > wrtycv ? 1 : 0 : ujghd > wrtycv ? 0 : -1
    mitur = kimnjg >= 0 ? kimnjg > kimnjg[1] ? 1 : 0 : kimnjg > kimnjg[1] ? 0 : -1
    ritur = juylknlilo > ab22 ? 1 : juylknlilo < ab23 ? -1 : 0
    circuits = rjuylkn > psjuylkn ? 1 : -1
    trialPoints = trialIncreasing ? close > ta.ema(close, 3) ? 1 : -1 : 0
    virar = juylknpercentR > -ab23 ? 1 : juylknpercentR < -ab22 ? -1 : 0
    chikar = kiloValue > 0.1 ? 1 : kiloValue < -0.1 ? -1 : 0
    sitar = omnerliiopn


    p = fitur + mitur + ritur + circuits + trialPoints + virar + chikar + sitar

    p

currentP = kyukarna(open, high, low, close, volume)
currentPNew = currentP >= 0 and currentP[1] <= 0 ? 0 : currentP <= 0 and currentP[1] >= 0 ? 0 : currentP
colorPNew = currentPNew == 0 ? color.black : currentPNew >= 0 ? color.green : color.red
//plot(currentPNew, color=colorPNew, title='CurrentTimeFrame')

LTN = 0.0
LTN := nz(LTN) ? 0.0 : (currentPNew[1] < 0 and currentPNew >= 0) ? high * 1.005 : (currentPNew[1] > 0 and currentPNew <= 0) ? low * 0.995 : LTN[1]

LClr = color.green
LClr :=  (currentPNew[1] < 0 and currentPNew >= 0) ? color.green : (currentPNew[1] > 0 and currentPNew <= 0) ? color.red : LClr[1]

plot(LTN,color=LClr,title="Level", style=plot.style_circles)


entryCondition:= high > LTN and LClr == color.green or(currentPNew[1] > 0 and currentPNew > 0) ? lkolkp : movnwx
exitCondition:= (low < LTN and LClr == color.red) or(currentPNew[1] < 0 and currentPNew < 0) ? lkolkp : movnwx

tradeRunning = movnwx
tradeRunning := nz(tradeRunning) ? movnwx :  (not tradeRunning[1]) and entryCondition ? lkolkp : tradeRunning[1] and exitCondition ? movnwx : tradeRunning[1]


plotshape(tradeRunning and (not tradeRunning[1]) and (not doBackTesting), style=shape.labelup, location=location.belowbar, color=color.new(#00FF00, 50), size=size.tiny, title='Buy wrtycv', text='➹', textcolor=color.new(color.black,0))
plotshape((not tradeRunning) and tradeRunning[1] and (not doBackTesting), style=shape.labeldown, location=location.abovebar, color=color.new(#FF0000, 50), size=size.tiny, title='Sell wrtycv', text='➷', textcolor=color.new(color.white, 0))


if  entryCondition  and doBackTesting
    strategy.entry(id="Buy",direction=strategy.long)

if exitCondition and doBackTesting
    strategy.close(id="Buy")

