Came across this skimming through old archives (2015) - An interesting Risk Reward Continuation/Fade script from the old ThinkScripter forum. Attribution is documented in the code.
It identifies bars with a X:1 trading opportunity either fading or continuing the existing price action. Stats labels also included. See hints for a thorough overview.
A scanner version might provide additional utility. I'm jammed for time at present, and it might be a while before I can get to it, so posting it here for anyone to play with or modify if so inclined.
Have fun.
Code:
#fl_rr_mapSTUDY.ts
#
#Fil Lorinc
#Creation date: 8/27/2015
#Edit Log (Date/Editor):
#
#
#
#hint: Identifies bars with a X:1 trading opportunity either fading or continuing the existing price action
#hint i_print_labels: Toggles chart labels
#hint i_print_bubbles: Toggles chart bubbles (display the RR above/below entry bar)
#hint i_rr: The Reward/Risk ratio threshold
#hint i_eval_bars: The number of bars forward for which to run the RR analysis
#hint i_lookback: The nubmer of bars in retrospect for which to anchor the "risk" component of the trade (i.e. a value of 1 looks at only the present bar, a value of 2 looks at the present bar and 1 bar prior. This is due to the functionality of the "Highest" and "Lowest" functions which require an (n + 1) value in the length parameter to be equivalent to standard thinkscript indexing references like [1])
#hint i_exc_price_long: The price at which to anchor the "reward" component of the trade. Intended selections are: (HIGH v. CLOSE) or (LOW v. CLOSE). When HIGH/LOW is selected, the RR ratio is measured to the HIGH/LOW of the subsequent number of eval bars whereas if CLOSE/CLOSE is selected, the RR ratio is measured to the closes of the subsequent number of eval bars.
#INPUTS
input i_print_labels = YES;
input i_print_bubbles = YES;
input i_rr = 3.0;
input i_eval_bars = 3;
input i_lookback = 10;
input i_exc_price_long = high;
input i_exc_price_short = low;
#VARIABLES & LOGIC
def v_long = if !HasContractChangeEvent()[-i_eval_bars] and close > Lowest(low, i_lookback) and (Highest(i_exc_price_long[-i_eval_bars], i_eval_bars) - close) >= i_rr*(close - Lowest(low, i_lookback)) and Lowest(low[-i_eval_bars], i_eval_bars) > Lowest(low, i_lookback) then 1 else 0;
def v_short = if !HasContractChangeEvent()[-i_eval_bars] and close < Highest(high, i_lookback) and (close - Lowest(i_exc_price_short[-i_eval_bars], i_eval_bars)) >= i_rr*(Highest(high, i_lookback) - close) and Highest(high[-i_eval_bars], i_eval_bars) < Highest(high, i_lookback) then 1 else 0;
def v_long_count = TotalSum(v_long);
def v_short_count = TotalSum(v_short);
def v_long_rr = (Highest(i_exc_price_long[-i_eval_bars], i_eval_bars) - close)/(close - Lowest(low, i_lookback));
def v_short_rr = (close - Lowest(i_exc_price_short[-i_eval_bars], i_eval_bars))/(Highest(high, i_lookback) - close);
def v_long_type_cont = TotalSum(v_long[i_eval_bars] and close[i_eval_bars] > open[i_eval_bars])/v_long_count[i_eval_bars];
def v_long_type_fade = TotalSum(v_long[i_eval_bars] and close[i_eval_bars] < open[i_eval_bars])/v_long_count[i_eval_bars];
def v_short_type_cont = TotalSum(v_short[i_eval_bars] and close[i_eval_bars] < open[i_eval_bars])/v_short_count[i_eval_bars];
def v_short_type_fade = TotalSum(v_short[i_eval_bars] and close[i_eval_bars] > open[i_eval_bars])/v_short_count[i_eval_bars];
#PLOTS
plot p_long_rr = if v_long then v_long_rr else 0;
plot p_short_rr = if v_short then v_short_rr else 0;
#PLOT STYLES & SETTINGS
p_long_rr.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
p_long_rr.SetDefaultColor(Color.MAGENTA);
p_short_rr.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
p_short_rr.SetDefaultColor(Color.CYAN);
#LABELS
AddLabel(i_print_labels, "ACTIONABLE BARS: " + AsPercent((v_long_count[i_eval_bars] + v_short_count[i_eval_bars]) / BarNumber()), Color.WHITE);
AddLabel(i_print_labels, "LONG: " + v_long_count[i_eval_bars] + " (c/f: " + AsPercent(v_long_type_cont) + " / " + AsPercent(v_long_type_fade) + ") | SHORT: " + v_short_count[i_eval_bars] + " (c/f: " + AsPercent(v_short_type_cont) + " / " + AsPercent(v_short_type_fade) + ")", Color.WHITE);
AddLabel(i_print_labels, "AGG LONG RR: " + Round(TotalSum(if v_long[i_eval_bars] then v_long_rr[i_eval_bars] else 0) / v_long_count[i_eval_bars], 2) + " | AGG SHORT RR: " + Round(TotalSum(if v_short[i_eval_bars] then v_short_rr[i_eval_bars] else 0) / v_short_count[i_eval_bars], 2) , Color.WHITE);
#BUBBLES
DefineGlobalColor("long_cont", CreateColor(0, 255, 0)); #GREEN
DefineGlobalColor("long_fade", CreateColor(144, 238, 114)); #LIGHT GREEN
DefineGlobalColor("short_cont", CreateColor(255, 0, 0)); #RED
DefineGlobalColor("short_fade", CreateColor(255, 175, 175)); #PINK
AddChartBubble(i_print_bubbles and v_long, low, Round(v_long_rr, 1), if close > open then GlobalColor("long_cont") else if close < open then GlobalColor("long_fade") else Color.BLACK, no);
AddChartBubble(i_print_bubbles and v_short, high, Round(v_short_rr, 1), if close < open then GlobalColor("short_cont") else if close > open then GlobalColor("short_fade") else Color.WHITE, yes);
#DEBUG
It identifies bars with a X:1 trading opportunity either fading or continuing the existing price action. Stats labels also included. See hints for a thorough overview.
A scanner version might provide additional utility. I'm jammed for time at present, and it might be a while before I can get to it, so posting it here for anyone to play with or modify if so inclined.
Have fun.
Code:
#fl_rr_mapSTUDY.ts
#
#Fil Lorinc
#Creation date: 8/27/2015
#Edit Log (Date/Editor):
#
#
#
#hint: Identifies bars with a X:1 trading opportunity either fading or continuing the existing price action
#hint i_print_labels: Toggles chart labels
#hint i_print_bubbles: Toggles chart bubbles (display the RR above/below entry bar)
#hint i_rr: The Reward/Risk ratio threshold
#hint i_eval_bars: The number of bars forward for which to run the RR analysis
#hint i_lookback: The nubmer of bars in retrospect for which to anchor the "risk" component of the trade (i.e. a value of 1 looks at only the present bar, a value of 2 looks at the present bar and 1 bar prior. This is due to the functionality of the "Highest" and "Lowest" functions which require an (n + 1) value in the length parameter to be equivalent to standard thinkscript indexing references like [1])
#hint i_exc_price_long: The price at which to anchor the "reward" component of the trade. Intended selections are: (HIGH v. CLOSE) or (LOW v. CLOSE). When HIGH/LOW is selected, the RR ratio is measured to the HIGH/LOW of the subsequent number of eval bars whereas if CLOSE/CLOSE is selected, the RR ratio is measured to the closes of the subsequent number of eval bars.
#INPUTS
input i_print_labels = YES;
input i_print_bubbles = YES;
input i_rr = 3.0;
input i_eval_bars = 3;
input i_lookback = 10;
input i_exc_price_long = high;
input i_exc_price_short = low;
#VARIABLES & LOGIC
def v_long = if !HasContractChangeEvent()[-i_eval_bars] and close > Lowest(low, i_lookback) and (Highest(i_exc_price_long[-i_eval_bars], i_eval_bars) - close) >= i_rr*(close - Lowest(low, i_lookback)) and Lowest(low[-i_eval_bars], i_eval_bars) > Lowest(low, i_lookback) then 1 else 0;
def v_short = if !HasContractChangeEvent()[-i_eval_bars] and close < Highest(high, i_lookback) and (close - Lowest(i_exc_price_short[-i_eval_bars], i_eval_bars)) >= i_rr*(Highest(high, i_lookback) - close) and Highest(high[-i_eval_bars], i_eval_bars) < Highest(high, i_lookback) then 1 else 0;
def v_long_count = TotalSum(v_long);
def v_short_count = TotalSum(v_short);
def v_long_rr = (Highest(i_exc_price_long[-i_eval_bars], i_eval_bars) - close)/(close - Lowest(low, i_lookback));
def v_short_rr = (close - Lowest(i_exc_price_short[-i_eval_bars], i_eval_bars))/(Highest(high, i_lookback) - close);
def v_long_type_cont = TotalSum(v_long[i_eval_bars] and close[i_eval_bars] > open[i_eval_bars])/v_long_count[i_eval_bars];
def v_long_type_fade = TotalSum(v_long[i_eval_bars] and close[i_eval_bars] < open[i_eval_bars])/v_long_count[i_eval_bars];
def v_short_type_cont = TotalSum(v_short[i_eval_bars] and close[i_eval_bars] < open[i_eval_bars])/v_short_count[i_eval_bars];
def v_short_type_fade = TotalSum(v_short[i_eval_bars] and close[i_eval_bars] > open[i_eval_bars])/v_short_count[i_eval_bars];
#PLOTS
plot p_long_rr = if v_long then v_long_rr else 0;
plot p_short_rr = if v_short then v_short_rr else 0;
#PLOT STYLES & SETTINGS
p_long_rr.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
p_long_rr.SetDefaultColor(Color.MAGENTA);
p_short_rr.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
p_short_rr.SetDefaultColor(Color.CYAN);
#LABELS
AddLabel(i_print_labels, "ACTIONABLE BARS: " + AsPercent((v_long_count[i_eval_bars] + v_short_count[i_eval_bars]) / BarNumber()), Color.WHITE);
AddLabel(i_print_labels, "LONG: " + v_long_count[i_eval_bars] + " (c/f: " + AsPercent(v_long_type_cont) + " / " + AsPercent(v_long_type_fade) + ") | SHORT: " + v_short_count[i_eval_bars] + " (c/f: " + AsPercent(v_short_type_cont) + " / " + AsPercent(v_short_type_fade) + ")", Color.WHITE);
AddLabel(i_print_labels, "AGG LONG RR: " + Round(TotalSum(if v_long[i_eval_bars] then v_long_rr[i_eval_bars] else 0) / v_long_count[i_eval_bars], 2) + " | AGG SHORT RR: " + Round(TotalSum(if v_short[i_eval_bars] then v_short_rr[i_eval_bars] else 0) / v_short_count[i_eval_bars], 2) , Color.WHITE);
#BUBBLES
DefineGlobalColor("long_cont", CreateColor(0, 255, 0)); #GREEN
DefineGlobalColor("long_fade", CreateColor(144, 238, 114)); #LIGHT GREEN
DefineGlobalColor("short_cont", CreateColor(255, 0, 0)); #RED
DefineGlobalColor("short_fade", CreateColor(255, 175, 175)); #PINK
AddChartBubble(i_print_bubbles and v_long, low, Round(v_long_rr, 1), if close > open then GlobalColor("long_cont") else if close < open then GlobalColor("long_fade") else Color.BLACK, no);
AddChartBubble(i_print_bubbles and v_short, high, Round(v_short_rr, 1), if close < open then GlobalColor("short_cont") else if close > open then GlobalColor("short_fade") else Color.WHITE, yes);
#DEBUG