Strategy · Pine Script v4 · On the chart

Aphrodite

by hasnocool· code credited to Eliza123123

This Pine Script strategy overlays signals directly on the price chart, combining pseudo-random normal distribution calculations with price primeness detection.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code293
Settings2inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

293 lines of Pine Script v4 from Aphrodite.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Aphrodite.pine
// 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")
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand (379 lines)

Overview

Aphrodite sizes positions using a fixed percentage of equity and accumulates long entries with heavy pyramiding when generated dot signals turn green. Positions exit when open, high, low, and close prices simultaneously meet primeness conditions. Inputs allow users to set specific calendar dates, including the day of the month and month. Notable limitations include extensive pyramiding up to 999 orders, asset price scaling constraints, and the complete absence of a defined stop loss.

Details

Published by

hasnocool on GitHub

Code credit

Eliza123123, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Day of Monthint3day_of_month
Monthint10this_month
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout

Omar Edited WF

by Alorse
330 stars

Omar Edited WF is a trading strategy overlay built around Williams Fractals and multiple Exponential Moving Averages. It detects high and low fractal pivot points over configurable lookback periods alongside three adjustable EMA trendlines. Long entries are ma

Strategy v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Omar Edited WF
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar
104 stars

This strategy combines three Exponential Moving Averages with Williams Fractals to execute trend-following or mean-reverting trades. It analyzes price structure using short, medium, and long-term EMAs along with fractal highs and lows. Entries trigger when fra

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of 3MA and Fractals Strategy

This trend breakout strategy plots Donchian Channels consisting of upper, lower, and middle bands directly on the main price chart. Long positions enter when price touches the upper channel and pulls back to or below the middle band, placing a stop loss at the

Strategy v6 TrendBreakout
Updated 2 months ago · MPL-2.0 GitHub repository of Donchian Strategy - Dynamic TP, Fixed SL, 1% Risk, Daily Target

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers