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

//@version=4
strategy("Aphrodite", default_qty_type = strategy.percent_of_equity, default_qty_value = 1, overlay=true, commission_type = strategy.commission.percent, commission_value=0.075, calc_on_every_tick=false, pyramiding = 999)

// v4
//pump/dump trend following strategy idea added.

//Pseudo Random Number Generator Box Muller Normal Distribution Method - code from [RS]Function - Functions to generate Random values by RicardoSantos. Dots are calculated by an adaptation of the ideas
//in this script.

// volume accumulates when dots are green for buys, red for sells. This setup is just looking for buys but this is very easy to change 
//just go to trading day and swap all strategy.long commands for strategy.short commands

// Exits on minutes where OHLC all return 'primeness'

//Reinforced dots (with black) when last three dots are all of same colour






//==================================================================================================================================================================================================================
//UPDATE HISTORY:
// v2
// more workable version of yesterdays script. please still only use on assets $10 to $100 as scalability hasn't been added for all assets yet. BG colors are theres to show historic prevalence of "primeness".
// The table in the top right will flash purple when the open high low or close encounters "primeness". 
// When they all light up thats when you can potentially expect a reversal. Use on lower time frame to see the effect quickly. Note this still isn't a foolproof method for finding primes but I will be improving it in later editions

// v3
// added scaling for pairs from $0.10 up to $1000. May still be slight different in indicator performance betwwen the two extremes of that scale.
// Clear OHLC prime pivot points have been added
// Introducing the volumeometer. Pretty self explanatory.
//==================================================================================================================================================================================================================





day_of_month = input(3, "Day of Month", input.integer)
this_month =  input(10, "Month", input.integer)


randomhour1 = floor(random(0,271))

// randomflip = round(random(0,1))
// randomflip2 = round(random(0,1))
// randomflip3 = round(random(0,1))

// day_before1 = day_of_month - 1
// day_before2 = day_of_month - 2
// day_before3 = day_of_month - 3
// day_before4 = day_of_month - 4
// day_before5 = day_of_month - 5
// day_before6 = day_of_month - 6
// day_before7 = day_of_month - 7
// day_before8 = day_of_month - 8
// day_before9 = day_of_month - 9
// day_before10 = day_of_month - 10

f_close = close, f_low = low, f_high = high, f_open = open
flagc = 0, flagl = 0, flagh = 0, flago = 0




//SCALING (JUST USE ASSETS $10 to $1000 as this needs more work still)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Assets $0.10-1
if close >= 0.100 and close < 0.9999
    f_close := f_close * 100000
if low >= 0.100 and low < 0.9999
    f_low := f_low * 100000
if high >= 0.100 and high < 0.9999
    f_high := f_high * 100000
if open >= 0.100 and open < 0.9999
    f_open := f_open * 100000

//Assets $1-10
if close >= 1.000 and close < 9.999
    f_close := f_close * 10000
if low >= 1.000 and low < 9.999
    f_low := f_low * 10000
if high >= 1.000 and high < 9.999
    f_high := f_high * 10000
if open >= 1.000 and open < 9.999
    f_open := f_open * 10000

//Assets $10-100
if close >= 10.000 and close < 99.999
    f_close := f_close * 1000
if low >= 10.000 and low < 99.999
    f_low := f_low * 1000
if high >= 10.000 and high < 99.999
    f_high := f_high * 1000
if open >= 10.000 and open < 99.999
    f_open := f_open * 1000

//Assets $100-1000
if close >= 100.000 and close < 999.999
    f_close := f_close * 100
if low >= 100.000 and low < 999.999
    f_low := f_low * 100
if high >= 100.000 and high < 999.999
    f_high := f_high * 100
if open >= 100.000 and open < 999.999
    f_open := f_open * 100
    
//Assets $1000-10000
if close >= 1000.000 and close < 9999.999
    f_close := f_close * 10
if low >= 1000.000 and low < 9999.999
    f_low := f_low * 10
if high >= 1000.000 and high < 9999.999
    f_high := f_high * 10
if open >= 1000.000 and open < 9999.999
    f_open := f_open * 10

//Assets $10000-100000
if close >= 10000.000 and close < 99999.999
    f_close := f_close
if low >= 10000.000 and low < 99999.999
    f_low := f_low
if high >= 10000.000 and high < 99999.999
    f_high := f_high
if open >= 10000.000 and open < 99999.999
    f_open := f_open
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//Prime Checking
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if f_close > 1
    for  i = 2 to 3
        if (f_close % i) == 0
            flagc := 1
        for  i = 4 to 5
            if (f_close % i) == 0
                flagc := 1
            for  i = 6 to 7
                if (f_close % i) == 0
                    flagc := 1
                for  i = 8 to 9
                    if (f_close % i) == 0
                        flagc := 1

if f_low > 1
    for  i = 2 to 3
        if (f_low % i) == 0
            flagl := 1
        for  i = 4 to 5
            if (f_low % i) == 0
                flagl := 1
            for  i = 6 to 7
                if (f_low % i) == 0
                    flagl := 1
                for  i = 8 to 9
                    if (f_low % i) == 0
                        flagl := 1

if f_high > 1
    for  i = 2 to 3
        if (f_high % i) == 0
            flagh := 1
        for  i = 4 to 5
            if (f_high % i) == 0
                flagh := 1
            for  i = 6 to 7
                if (f_high % i) == 0
                    flagh := 1
                for  i = 8 to 9
                    if (f_high % i) == 0
                        flagh := 1

if f_open > 1
    for  i = 2 to 3
        if (f_open % i) == 0
            flago := 1
        for  i = 4 to 5
            if (f_open % i) == 0
                flago := 1
            for  i = 6 to 7
                if (f_open % i) == 0
                    flago := 1
                for  i = 8 to 9
                    if (f_open % i) == 0
                        flago := 1
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//Pseudo Random Number Generator Box Muller Normal Distribution Method - code from [RS]Function - Functions to generate Random values by RicardoSantos
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
f_pseudo_random_number(_range, _seed) =>
    _return = 1.0
    if na(_seed)
        _return := 3.14159 * nz(_return[1], 1) % bar_index
        _return
    else
        _return := 3.14159 * nz(_return[1], 1) % (bar_index + _seed)
        _return
    _return := _return % _range
    _return

f_nd_pseudo_random(_mean, _dev, _seed) =>
    _pi = 3.14159265359
    _random_1 = f_pseudo_random_number(1.0, _seed)
    _random_2 = f_pseudo_random_number(1.0, -_seed)
    _return = sqrt(-2 * log(_random_1)) * cos(2 * _pi * _random_2) * _dev + _mean
    _return

//My added code:
mean = sma(ohlc4, 27)
dev = stdev(ohlc4, 27)
rng = f_nd_pseudo_random(mean, dev, input(1.0))
absrng = abs(rng)
normalDistributionDots = abs(rng)

trd = 0, tgd = 0

if(abs(rng) > high) and (abs(rng)[1] > high[1]) and (abs(rng)[2] > high[2]) and bar_index
    trd := 1
    tgd := 0
    
if (abs(rng) < low) and (abs(rng)[1] < low[1]) and (abs(rng)[2] < low[2]) and bar_index
    tgd := 1
    trd := 0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




// CONDITION
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
piBear=0
if abs(rng) > high
    piBear := 1

piBull=0
if abs(rng) < low
    piBull := 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//MORE CALCS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
volumesBeaten = 0
for i = 1 to 1440
    if volume > volume[i]
        volumesBeaten := volumesBeaten + 1
volume_percent_class = (volumesBeaten / 1440) * 100

howManyreds = 0
for i = 1 to 100
    if open[i] > close[i]
        howManyreds := howManyreds + 1
        
howManygreens = 0
for i = 1 to 100
    if open[i] < close[i]
        howManygreens := howManygreens + 1

// howManygreendots = 0
// for i = 1 to 100
//     if abs(rng)[i] < low[i]
//         howManygreendots := howManygreendots + 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//OUTPUTS
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
plot(series = normalDistributionDots, title="BLACK DOT", color = trd == 1 ? #000000 : na, linewidth=4, style=plot.style_circles, transp=0)
plot(series = normalDistributionDots, title="BLACK DOT", color = tgd == 1 ? #000000 : na, linewidth=4, style=plot.style_circles, transp=0)
plot(series = normalDistributionDots, title="Normally Distributed Pseudo Random Value", color = abs(rng) > high ? #fa0000 : #0efa00, linewidth=1, style=plot.style_circles, transp=0)

plotcandle(open, high, low, close, color = abs(rng) > high ? #fa0000 : #0efa00, wickcolor= color.white)
    
bgcolor(color = abs(rng) > high ?  #fa0000 : na)
bgcolor(color = trd == 1 ?  #fa0000 : na)

bgcolor(color = abs(rng) < low ? #0efa00 : na)
bgcolor(color = tgd == 1 ?  #0efa00 : na)


bgcolor(color = flagc == 0 ? color.yellow : na, transp = 99)
bgcolor(color = flagl == 0 ? color.yellow : na, transp = 99)
bgcolor(color = flagh == 0 ? color.yellow : na, transp = 99)
bgcolor(color = flago == 0 ? color.yellow : na, transp = 99)

bgcolor(color = flago == 0 and flagh == 0 ? color.purple : na, transp = 98)
bgcolor(color = flago == 0 and flagl == 0 ? color.purple : na, transp = 98)
bgcolor(color = flago == 0 and flagc == 0 ? color.purple : na, transp = 98)
bgcolor(color = flagl == 0 and flagc == 0 ? color.purple : na, transp = 98)
bgcolor(color = flagl == 0 and flagh == 0 ? color.purple : na, transp = 98)
bgcolor(color = flagc == 0 and flagh == 0 ? color.purple : na, transp = 98)

bgcolor(color = flagc == 0 and flagh == 0 and flago == 0 ? color.fuchsia : na, transp = 97)
bgcolor(color = flagc == 0 and flagh == 0 and flagl == 0 ? color.fuchsia : na, transp = 97)
bgcolor(color = flago == 0 and flagc == 0 and flagl == 0 ? color.fuchsia : na, transp = 97)
bgcolor(color = flago == 0 and flagh == 0 and flagl == 0 ? color.fuchsia : na, transp = 97)

var testTable = table.new(position = position.bottom_right, columns = 2, rows = 4, bgcolor = color.white, border_width = 1)
if barstate.islast
    table.cell(table_id = testTable, column = 0, row = 0, text = "Open is " + tostring(open), bgcolor = flago == 0 ? color.fuchsia : na, text_color = #000000)
    table.cell(table_id = testTable, column = 1, row = 0, text = "Close is " + tostring(close), bgcolor = flagc == 0 ? color.fuchsia : na, text_color = #000000)
    table.cell(table_id = testTable, column = 0, row = 1, text = "High is " + tostring(high), bgcolor = flagh == 0 ? color.fuchsia : na, text_color = #000000)
    table.cell(table_id = testTable, column = 1, row = 1, text = "Low is " + tostring(low), bgcolor = flagl == 0 ? color.fuchsia : na, text_color = #000000)
    table.cell(table_id = testTable, column = 0, row = 2, text = " Volume higher than " + tostring(volume_percent_class) + "% of recent data", bgcolor = #000000, text_color = color.white)
    table.cell(table_id = testTable, column = 1, row = 2, text = "Reds " + tostring(howManyreds), bgcolor = #9f0000, text_color = color.white)
    table.cell(table_id = testTable, column = 0, row = 3, text = "HOPE THIS HELPS! ELIZA x", bgcolor = #fc03a5, text_color = #d5ff03)
    table.cell(table_id = testTable, column = 1, row = 3, text = "Greens " + tostring(howManygreens), bgcolor = #1e9f00, text_color = color.white)


plotshape(flagc == 0 and flagh == 0 and flago == 0 and flagl == 0, location = location.belowbar, color = color.purple, text = "Piv", textcolor = color.white)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//TRADING DAY
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//1st order Buy Entries
if abs(rng) < low and (month == (this_month) and dayofmonth == 3)
    strategy.entry(id = "buy",
                 long = strategy.long,
                 comment = "buy",
                 alert_message = "Long("  + syminfo.ticker + "): Started"
                 )
else if flagc == 0 and flagh == 0 and flago == 0 and flagl == 0
    strategy.close_all(comment = "close")

//2nd order Buy entries
if tgd == 1 and (month == (this_month) and dayofmonth == 3)
    strategy.entry(id = "buy2",
                 long = strategy.long,
                 comment = "buy",
                 alert_message = "Long("  + syminfo.ticker + "): Started"
                 )
else if flagc == 0 and flagh == 0 and flago == 0 and flagl == 0
    strategy.close_all(comment = "close")

if tgd == 1 and (month == (this_month) and dayofmonth == 3)
    strategy.entry(id = "buy3",
                 long = strategy.long,
                 comment = "buy",
                 alert_message = "Long("  + syminfo.ticker + "): Started"
                 )
else if flagc == 0 and flagh == 0 and flago == 0 and flagl == 0
    strategy.close_all(comment = "close")
if tgd == 1 and (month == (this_month) and dayofmonth == 3)
    strategy.entry(id = "buy4",
                 long = strategy.long,
                 comment = "buy",
                 alert_message = "Long("  + syminfo.ticker + "): Started"
                 )
else if flagc == 0 and flagh == 0 and flago == 0 and flagl == 0
    strategy.close_all(comment = "close")

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////








