Candle Color Ratio
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LeafAlgo

//@version=5
indicator("Candle Color Ratio", overlay=false)

//Scoring Syntax
float greenScore1 = 0
float greenScore2 = 0
float greenScore3 = 0
float greenScore4 = 0
float greenScore5 = 0
float greenScore6 = 0
float greenScore7 = 0
float greenScore8 = 0
float greenScore9 = 0
float greenScore10 = 0

float redScore1 = 0
float redScore2 = 0
float redScore3 = 0
float redScore4 = 0
float redScore5 = 0
float redScore6 = 0
float redScore7 = 0
float redScore8 = 0
float redScore9 = 0
float redScore10 = 0

if close[1] > open[1]
    greenScore1 := 1
    redScore1 := 0

if close[1] < open[1]
    greenScore1 := 0
    redScore1 := 1

if close[2] > open[2]
    greenScore2 := 1
    redScore2 := 0

if close[2] < open[2]
    greenScore2 := 0
    redScore2 := 0

if close[3] > open[3]
    greenScore3 := 1
    redScore3 := 0

if close[3] < open[3]
    greenScore3 := 0
    redScore3 := 1

if close[4] > open[4]
    greenScore4 := 1
    redScore4 := 0

if close[4] < open[4]
    greenScore4 := 0
    redScore4 := 1

if close[5] > open[5]
    greenScore5 := 1
    redScore5 := 0

if close[5] < open[5]
    greenScore5 := 0
    redScore5 := 1

if close[6] > open[6]
    greenScore6 := 1
    redScore6 := 0

if close[6] < open[6]
    greenScore6 := 0
    redScore6 := 1

if close[7] > open[7]
    greenScore7 := 1
    redScore7 := 0

if close[7] < open[7]
    greenScore7 := 0
    redScore7 := 1

if close[8] > open[8]
    greenScore8 := 1
    redScore8 := 0

if close[8] < open[8]
    greenScore8 := 0
    redScore8 := 1

if close[9] > open[9]
    greenScore9 := 1
    redScore9 := 0

if close[9] < open[9]
    greenScore9 := 0
    redScore9 := 1

if close[10] > open[10]
    greenScore10 := 1
    redScore10 := 0

if close[10] < open[10]
    greenScore10 := 0
    redScore10 := 1

greenScore = greenScore1 + greenScore2 + greenScore3 + greenScore4 + greenScore5 + greenScore6 + greenScore7 + greenScore8 + greenScore9 + greenScore10
redScore = redScore1 + redScore2 + redScore3 + redScore4 + redScore5 + redScore6 + redScore7 + redScore8 + redScore9 + redScore10
GRratioScore = greenScore / redScore
RGratioScore = redScore / greenScore

//Plotting
threshold = input.int(2, title='Ratio Threshold')

plot(greenScore, color = color.new(color.green, 50), style=plot.style_histogram, title='Number of Green')
plot(redScore, color=color.new(color.red, 50), style=plot.style_histogram, title='Number of Red')
plot(GRratioScore, color=color.lime, linewidth=3, title='Green to Red Ratio')
plot(RGratioScore, color=color.fuchsia, linewidth=3, title='Red to Green Ratio')
plot(threshold, linewidth=3, color=color.white, title='Ratio Threshold')


