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

//@version=5
indicator("IU Probability Calculator", overlay=false)

///////////////////////////////////////// USER INPUTS ////////////////////////////////////////

//// BULLISH AND BEARISH FILTER 

fliter = input.string("Bullish", "Enter the directions ", options = ["Bullish", "Bearish"])

lenght = input.int(14, title = " ATR / Std lenght", minval = 1, tooltip = "Enter the ATR period ")

a = input.float(defval=27000,title="price level", tooltip = "Write the level from where you want to calculate the probabilty")

calculation_method = input.string("ATR", title="Calculation Method", options=["ATR", "Standard Deviation"])

////////////////////////////////////////// CALCULATIONS///////////////////////////////////////////////
b = close 

c = ta.atr(lenght)
std_deviation = ta.stdev(close, length = lenght)

z = 0.0

//// CHECKING THE VALUE IN NORMAL DISTRIBUTION TABLE 
float value = 0.00000

if fliter == "Bullish"
    if calculation_method ==  "ATR"  
        z := (a - b)/ c 
    else 
        z := (a - b)/ std_deviation
    
    if z <= 0.01
        value := 0.5040
    else if z <= 0.02
        value := 0.5080
    else if z <= 0.03
        value := 0.5120
    else if z <= 0.04
        value := 0.5160
    else if z <= 0.05
        value := 0.5199
    else if z <= 0.06
        value := 0.5239
    else if z <= 0.07
        value := 0.5279
    else if z <= 0.08
        value := 0.5319
    else if z <= 0.09
        value := 0.5359
    else if z <= 0.10
        value := 0.5398
    else if z <= 0.11
        value := 0.5438
    else if z <= 0.12
        value := 0.5478
    else if z <= 0.13
        value := 0.5517
    else if z <= 0.14
        value := 0.5557
    else if z <= 0.15
        value := 0.5596
    else if z <= 0.16
        value := 0.5636
    else if z <= 0.17
        value := 0.5675
    else if z <= 0.18
        value := 0.5714
    else if z <= 0.19
        value := 0.5753
    else if z <= 0.20
        value := 0.5793
    else if z <= 0.21
        value := 0.5832
    else if z <= 0.22
        value := 0.5871
    else if z <= 0.23
        value := 0.5910
    else if z <= 0.24
        value := 0.5948
    else if z <= 0.25
        value := 0.5987
    else if z <= 0.26
        value := 0.6026
    else if z <= 0.27
        value := 0.6064
    else if z <= 0.28
        value := 0.6103
    else if z <= 0.29
        value := 0.6141
    else if z <= 0.30
        value := 0.6179
    else if z <= 0.31
        value := 0.6217
    else if z <= 0.32
        value := 0.6255
    else if z <= 0.33
        value := 0.6293
    else if z <= 0.34
        value := 0.6331
    else if z <= 0.35
        value := 0.6368
    else if z <= 0.36
        value := 0.6406
    else if z <= 0.37
        value := 0.6443
    else if z <= 0.38
        value := 0.6480
    else if z <= 0.39
        value := 0.6517    
    else if z <= 0.40
        value := 0.6554   
    else if z <= 0.41
        value := 0.6591
    else if z <= 0.42
        value := 0.6628
    else if z <= 0.43
        value := 0.6664
    else if z <= 0.44
        value := 0.6700
    else if z <= 0.45
        value := 0.6736
    else if z <= 0.46
        value := 0.6772
    else if z <= 0.47
        value := 0.6808
    else if z <= 0.48
        value := 0.6844
    else if z <= 0.49
        value := 0.6879
    else if z <= 0.50
        value := 0.6915
    else if z <= 0.51
        value := 0.6968
    else if z <= 0.52
        value := 0.7020
    else if z <= 0.53
        value := 0.7071
    else if z <= 0.54
        value := 0.7123
    else if z <= 0.55
        value := 0.7174
    else if z <= 0.56
        value := 0.7224
    else if z <= 0.57
        value := 0.7274
    else if z <= 0.58
        value := 0.7324
    else if z <= 0.59
        value := 0.7374
    else if z <= 0.60
        value := 0.7424
    else if z <= 0.61
        value := 0.7472
    else if z <= 0.62
        value := 0.7521
    else if z <= 0.63
        value := 0.7569
    else if z <= 0.64
        value := 0.7617
    else if z <= 0.65
        value := 0.7664
    else if z <= 0.66
        value := 0.7712
    else if z <= 0.67
        value := 0.7759
    else if z <= 0.68
        value := 0.7806
    else if z <= 0.69
        value := 0.7852
    else if z <= 0.70
        value := 0.7897
    else if z <= 0.71
        value := 0.7942
    else if z <= 0.72
        value := 0.7986
    else if z <= 0.73
        value := 0.8029
    else if z <= 0.74
        value := 0.8072
    else if z <= 0.75
        value := 0.8115
    else if z <= 0.76
        value := 0.8156
    else if z <= 0.77
        value := 0.8198
    else if z <= 0.78
        value := 0.8238
    else if z <= 0.79
        value := 0.8279
    else if z <= 0.80
        value := 0.8319
    else if z <= 0.81
        value := 0.8357
    else if z <= 0.82
        value := 0.8396
    else if z <= 0.83
        value := 0.8434
    else if z <= 0.84
        value := 0.8471
    else if z <= 0.85
        value := 0.8508
    else if z <= 0.86
        value := 0.8544
    else if z <= 0.87
        value := 0.8580        
    else if z <= 0.88
        value := 0.8615
    else if z <= 0.8900
        value := 0.8649
    else if z <= 0.9000
        value := 0.8683
    else if z <= 0.9100
        value := 0.8717
    else if z <= 0.9200
        value := 0.8749
    else if z <= 0.9300
        value := 0.8781
    else if z <= 0.9400
        value := 0.8812
    else if z <= 0.9500
        value := 0.8842
    else if z <= 0.9600
        value := 0.8872
    else if z <= 0.9700
        value := 0.8901
    else if z <= 0.9800
        value := 0.8929
    else if z <= 0.9900
        value := 0.8957
    else if z <= 1.0000
        value := 0.8983
    else if z <= 1.0100
        value := 0.9008
    else if z <= 1.0200
        value := 0.9025
    else if z <= 1.0300
        value := 0.9040
    else if z <= 1.0400
        value := 0.9055
    else if z <= 1.0500
        value := 0.9069
    else if z <= 1.0600
        value := 0.9082
    else if z <= 1.0700
        value := 0.9094
    else if z <= 1.0800
        value := 0.9106
    else if z <= 1.0900
        value := 0.9117
    else if z <= 1.1000
        value := 0.9129
    else if z <= 1.1100
        value := 0.9139
    else if z <= 1.1200
        value := 0.9149
    else if z <= 1.1300
        value := 0.9159
    else if z <= 1.1400
        value := 0.9168
    else if z <= 1.1500
        value := 0.9177
    else if z <= 1.1600
        value := 0.9186
    else if z <= 1.1700
        value := 0.9194
    else if z <= 1.1800
        value := 0.9202
    else if z <= 1.1900
        value := 0.9210
    else if z <= 1.2000
        value := 0.9217
    else if z <= 1.2100
        value := 0.9224
    else if z <= 1.2200
        value := 0.9230
    else if z <= 1.2300
        value := 0.9236
    else if z <= 1.2400
        value := 0.9243
    else if z <= 1.2500
        value := 0.9249
    else if z <= 1.2600
        value := 0.9254
    else if z <= 1.2700
        value := 0.9260
    else if z <= 1.2800
        value := 0.9265
    else if z <= 1.2900
        value := 0.9270
    else if z <= 1.3000
        value := 0.9274
    else if z <= 1.3100
        value := 0.9279
    else if z <= 1.3200
        value := 0.9283
    else if z <= 1.3300
        value := 0.9287
    else if z <= 1.3400
        value := 0.9291
    else if z <= 1.3500
        value := 0.9295
    else if z <= 1.3600
        value := 0.9299
    else if z <= 1.3700
        value := 0.9302
    else if z <= 1.3800
        value := 0.9306
    else if z <= 1.3900
        value := 0.9309
    else if z <= 1.4000
        value := 0.9312
    else if z <= 1.4100
        value := 0.9315
    else if z <= 1.4200
        value := 0.9319
    else if z <= 1.4300
        value := 0.9322
    else if z <= 1.4400
        value := 0.9325
    else if z <= 1.4500
        value := 0.9327
    else if z <= 1.4600
        value := 0.9330
    else if z <= 1.4700
        value := 0.9332
    else if z <= 1.4800
        value := 0.9335
    else if z <= 1.4900
        value := 0.9338
    else if z <= 1.5000
        value := 0.9340
    else if z <= 1.5100
        value := 0.9342
    else if z <= 1.5200
        value := 0.9345
    else if z <= 1.5300
        value := 0.9348
    else if z <= 1.5400
        value := 0.9351
    else if z <= 1.5500
        value := 0.9354
    else if z <= 1.5600
        value := 0.9357
    else if z <= 1.5700
        value := 0.9359
    else if z <= 1.5800
        value := 0.9362
    else if z <= 1.5900
        value := 0.9365
    else if z <= 1.6000
        value := 0.9367
    else if z <= 1.6100
        value := 0.9370
    else if z <= 1.6200
        value := 0.9372
    else if z <= 1.6300
        value := 0.9374
    else if z <= 1.6400
        value := 0.9377
    else if z <= 1.6500
        value := 0.9379
    else if z <= 1.6600
        value := 0.9381
    else if z <= 1.6700
        value := 0.9384
    else if z <= 1.6800
        value := 0.938
    else if z <= 1.6900
        value := 0.9388
    else if z <= 1.7000
        value := 0.9390
    else if z <= 1.7100
        value := 0.9392
    else if z <= 1.7200
        value := 0.9394
    else if z <= 1.7300
        value := 0.9396
    else if z <= 1.7400
        value := 0.9398
    else if z <= 1.7500
        value := 0.9400
    else if z <= 1.7600
        value := 0.9402
    else if z <= 1.7700
        value := 0.9404
    else if z <= 1.7800
        value := 0.9406
    else if z <= 1.7900
        value := 0.9408
    else if z <= 1.8000
        value := 0.9410
    else if z <= 1.8100
        value := 0.9411
    else if z <= 1.8200
        value := 0.9413
    else if z <= 1.8300
        value := 0.9415
    else if z <= 1.8400
        value := 0.9416
    else if z <= 1.8500
        value := 0.9418
    else if z <= 1.8600
        value := 0.9420
    else if z <= 1.8700
        value := 0.9421
    else if z <= 1.8800
        value := 0.9423
    else if z <= 1.8900
        value := 0.9424




/////////////////////////////////////// FOR BEARISH CALCULATIONS /////////////////////////////////



if fliter == "Bearish"
    if calculation_method ==  "ATR"  
        z := (b - a)/ c 
    else 
        z := (b - a)/ std_deviation

    if z <= 0.01
        value := 0.5040
    else if z <= 0.02
        value := 0.5080
    else if z <= 0.03
        value := 0.5120
    else if z <= 0.04
        value := 0.5160
    else if z <= 0.05
        value := 0.5199
    else if z <= 0.06
        value := 0.5239
    else if z <= 0.07
        value := 0.5279
    else if z <= 0.08
        value := 0.5319
    else if z <= 0.09
        value := 0.5359
    else if z <= 0.10
        value := 0.5398
    else if z <= 0.11
        value := 0.5438
    else if z <= 0.12
        value := 0.5478
    else if z <= 0.13
        value := 0.5517
    else if z <= 0.14
        value := 0.5557
    else if z <= 0.15
        value := 0.5596
    else if z <= 0.16
        value := 0.5636
    else if z <= 0.17
        value := 0.5675
    else if z <= 0.18
        value := 0.5714
    else if z <= 0.19
        value := 0.5753
    else if z <= 0.20
        value := 0.5793
    else if z <= 0.21
        value := 0.5832
    else if z <= 0.22
        value := 0.5871
    else if z <= 0.23
        value := 0.5910
    else if z <= 0.24
        value := 0.5948
    else if z <= 0.25
        value := 0.5987
    else if z <= 0.26
        value := 0.6026
    else if z <= 0.27
        value := 0.6064
    else if z <= 0.28
        value := 0.6103
    else if z <= 0.29
        value := 0.6141
    else if z <= 0.30
        value := 0.6179
    else if z <= 0.31
        value := 0.6217
    else if z <= 0.32
        value := 0.6255
    else if z <= 0.33
        value := 0.6293
    else if z <= 0.34
        value := 0.6331
    else if z <= 0.35
        value := 0.6368
    else if z <= 0.36
        value := 0.6406
    else if z <= 0.37
        value := 0.6443
    else if z <= 0.38
        value := 0.6480
    else if z <= 0.39
        value := 0.6517    
    else if z <= 0.40
        value := 0.6554   
    else if z <= 0.41
        value := 0.6591
    else if z <= 0.42
        value := 0.6628
    else if z <= 0.43
        value := 0.6664
    else if z <= 0.44
        value := 0.6700
    else if z <= 0.45
        value := 0.6736
    else if z <= 0.46
        value := 0.6772
    else if z <= 0.47
        value := 0.6808
    else if z <= 0.48
        value := 0.6844
    else if z <= 0.49
        value := 0.6879
    else if z <= 0.50
        value := 0.6915
    else if z <= 0.51
        value := 0.6968
    else if z <= 0.52
        value := 0.7020
    else if z <= 0.53
        value := 0.7071
    else if z <= 0.54
        value := 0.7123
    else if z <= 0.55
        value := 0.7174
    else if z <= 0.56
        value := 0.7224
    else if z <= 0.57
        value := 0.7274
    else if z <= 0.58
        value := 0.7324
    else if z <= 0.59
        value := 0.7374
    else if z <= 0.60
        value := 0.7424
    else if z <= 0.61
        value := 0.7472
    else if z <= 0.62
        value := 0.7521
    else if z <= 0.63
        value := 0.7569
    else if z <= 0.64
        value := 0.7617
    else if z <= 0.65
        value := 0.7664
    else if z <= 0.66
        value := 0.7712
    else if z <= 0.67
        value := 0.7759
    else if z <= 0.68
        value := 0.7806
    else if z <= 0.69
        value := 0.7852
    else if z <= 0.70
        value := 0.7897
    else if z <= 0.71
        value := 0.7942
    else if z <= 0.72
        value := 0.7986
    else if z <= 0.73
        value := 0.8029
    else if z <= 0.74
        value := 0.8072
    else if z <= 0.75
        value := 0.8115
    else if z <= 0.76
        value := 0.8156
    else if z <= 0.77
        value := 0.8198
    else if z <= 0.78
        value := 0.8238
    else if z <= 0.79
        value := 0.8279
    else if z <= 0.80
        value := 0.8319
    else if z <= 0.81
        value := 0.8357
    else if z <= 0.82
        value := 0.8396
    else if z <= 0.83
        value := 0.8434
    else if z <= 0.84
        value := 0.8471
    else if z <= 0.85
        value := 0.8508
    else if z <= 0.86
        value := 0.8544
    else if z <= 0.87
        value := 0.8580 
    else if z <= 0.88
        value := 0.8615
    else if z <= 0.8900
        value := 0.8649
    else if z <= 0.9000
        value := 0.8683
    else if z <= 0.9100
        value := 0.8717
    else if z <= 0.9200
        value := 0.8749
    else if z <= 0.9300
        value := 0.8781
    else if z <= 0.9400
        value := 0.8812
    else if z <= 0.9500
        value := 0.8842
    else if z <= 0.9600
        value := 0.8872
    else if z <= 0.9700
        value := 0.8901
    else if z <= 0.9800
        value := 0.8929
    else if z <= 0.9900
        value := 0.8957
    else if z <= 1.0000
        value := 0.8983
    else if z <= 1.0100
        value := 0.9008
    else if z <= 1.0200
        value := 0.9025
    else if z <= 1.0300
        value := 0.9040
    else if z <= 1.0400
        value := 0.9055
    else if z <= 1.0500
        value := 0.9069
    else if z <= 1.0600
        value := 0.9082
    else if z <= 1.0700
        value := 0.9094
    else if z <= 1.0800
        value := 0.9106
    else if z <= 1.0900
        value := 0.9117
    else if z <= 1.1000
        value := 0.9129
    else if z <= 1.1100
        value := 0.9139
    else if z <= 1.1200
        value := 0.9149
    else if z <= 1.1300
        value := 0.9159
    else if z <= 1.1400
        value := 0.9168
    else if z <= 1.1500
        value := 0.9177
    else if z <= 1.1600
        value := 0.9186
    else if z <= 1.1700
        value := 0.9194
    else if z <= 1.1800
        value := 0.9202
    else if z <= 1.1900
        value := 0.9210
    else if z <= 1.2000
        value := 0.9217
    else if z <= 1.2100
        value := 0.9224
    else if z <= 1.2200
        value := 0.9230
    else if z <= 1.2300
        value := 0.9236
    else if z <= 1.2400
        value := 0.9243
    else if z <= 1.2500
        value := 0.9249
    else if z <= 1.2600
        value := 0.9254
    else if z <= 1.2700
        value := 0.9260
    else if z <= 1.2800
        value := 0.9265
    else if z <= 1.2900
        value := 0.9270
    else if z <= 1.3000
        value := 0.9274
    else if z <= 1.3100
        value := 0.9279
    else if z <= 1.3200
        value := 0.9283
    else if z <= 1.3300
        value := 0.9287
    else if z <= 1.3400
        value := 0.9291
    else if z <= 1.3500
        value := 0.9295
    else if z <= 1.3600
        value := 0.9299
    else if z <= 1.3700
        value := 0.9302
    else if z <= 1.3800
        value := 0.9306
    else if z <= 1.3900
        value := 0.9309
    else if z <= 1.4000
        value := 0.9312
    else if z <= 1.4100
        value := 0.9315
    else if z <= 1.4200
        value := 0.9319
    else if z <= 1.4300
        value := 0.9322
    else if z <= 1.4400
        value := 0.9325
    else if z <= 1.4500
        value := 0.9327
    else if z <= 1.4600
        value := 0.9330
    else if z <= 1.4700
        value := 0.9332
    else if z <= 1.4800
        value := 0.9335
    else if z <= 1.4900
        value := 0.9338
    else if z <= 1.5000
        value := 0.9340
    else if z <= 1.5100
        value := 0.9342
    else if z <= 1.5200
        value := 0.9345
    else if z <= 1.5300
        value := 0.9348
    else if z <= 1.5400
        value := 0.9351
    else if z <= 1.5500
        value := 0.9354
    else if z <= 1.5600
        value := 0.9357
    else if z <= 1.5700
        value := 0.9359
    else if z <= 1.5800
        value := 0.9362
    else if z <= 1.5900
        value := 0.9365
    else if z <= 1.6000
        value := 0.9367
    else if z <= 1.6100
        value := 0.9370
    else if z <= 1.6200
        value := 0.9372
    else if z <= 1.6300
        value := 0.9374
    else if z <= 1.6400
        value := 0.9377
    else if z <= 1.6500
        value := 0.9379
    else if z <= 1.6600
        value := 0.9381
    else if z <= 1.6700
        value := 0.9384
    else if z <= 1.6800
        value := 0.938
    else if z <= 1.6900
        value := 0.9388
    else if z <= 1.7000
        value := 0.9390
    else if z <= 1.7100
        value := 0.9392
    else if z <= 1.7200
        value := 0.9394
    else if z <= 1.7300
        value := 0.9396
    else if z <= 1.7400
        value := 0.9398
    else if z <= 1.7500
        value := 0.9400
    else if z <= 1.7600
        value := 0.9402
    else if z <= 1.7700
        value := 0.9404
    else if z <= 1.7800
        value := 0.9406
    else if z <= 1.7900
        value := 0.9408
    else if z <= 1.8000
        value := 0.9410
    else if z <= 1.8100
        value := 0.9411
    else if z <= 1.8200
        value := 0.9413
    else if z <= 1.8300
        value := 0.9415
    else if z <= 1.8400
        value := 0.9416
    else if z <= 1.8500
        value := 0.9418
    else if z <= 1.8600
        value := 0.9420
    else if z <= 1.8700
        value := 0.9421
    else if z <= 1.8800
        value := 0.9423
    else if z <= 1.8900
        value := 0.9424
            

//// PLOTING THE VALUES 
correct_value = value * 100
plot( (100 - correct_value) == 49.60  ? 0 : (100 - correct_value)   , title="Probability of not happing ", color=color.green, linewidth=2, style = plot.style_stepline_diamond)
plot( (correct_value) == 50.40 ? 0 : correct_value , title="Probability of happing ", color=color.red, linewidth=2, style = plot.style_stepline_diamond)

//////////// CREATIING LABLE 
var label lable = na 
if barstate.islast 
    lable := label.new( chart.point.from_index( bar_index[10], 50) , text = "Green menas Probability of happing" + "\n" + "Red means Probability of not happing ", color = color.green, style = label.style_label_lower_left)
    label.delete(lable[1])


