Day of Week Gap Analytics is generally understudied,
This Gap Analytics study complement's @mashume's work by tracking the cumulative ticks gained/lost on gap bars segmented by DAY OF WEEK.
https://usethinkscript.com/threads/...forms-well-on-a-particular-day-of-year.16929/
3 types of analysis can be run: Close-Close, Close-Open, Open-Close. Clarifying equity expansion/contraction by DAY OF WEEK is it's primary value - perhaps use it to complement your other trading tools. Example use: $AMD Daily, 1 Year chart - Close-Close analysis. Significant equity expansion is from Wednesday to Monday. > *Buy near Wednesday's Close - *Sell the following Monday before the Close IF consistent with your primary indicators. Hope the community finds some value in the study.
This Gap Analytics study complement's @mashume's work by tracking the cumulative ticks gained/lost on gap bars segmented by DAY OF WEEK.
https://usethinkscript.com/threads/...forms-well-on-a-particular-day-of-year.16929/
3 types of analysis can be run: Close-Close, Close-Open, Open-Close. Clarifying equity expansion/contraction by DAY OF WEEK is it's primary value - perhaps use it to complement your other trading tools. Example use: $AMD Daily, 1 Year chart - Close-Close analysis. Significant equity expansion is from Wednesday to Monday. > *Buy near Wednesday's Close - *Sell the following Monday before the Close IF consistent with your primary indicators. Hope the community finds some value in the study.
Ruby:
#Gap Analytics Study
#Ommni007, 11/3/23 Free to share within UseThinkscript Community
#Change log: 11/3/23 Trimmed to basic version
#hint: Tracks the cumulative ticks gained/lost on gap bars segmented by DAY OF WEEK.
#hint i_type: The type of analysis to run. Options are: <b>CloseOpen</b> (current open minus previous close), <b>OpenClose</b> (current close versus current open), and <b>CloseClose</b> (current close versus previous close)
declare lower;
#INPUTS
input i_print_day_labels = YES;
input i_type = {default CloseOpen, OpenClose, CloseClose};
input timeFrame = {default DAY, WEEK, MONTH};
#LOGIC
def v_tick_size = TickSize();
def v_contract_roll = HasContractChangeEvent();
def v_weekday = GetDayOfWeek(GetYYYYMMDD());
def v_gap_up;
def v_gap_down;
switch (i_type)
{
case CloseOpen:
if open(period = timeFrame) > close(period = timeFrame)[1] and !v_contract_roll
then {
v_gap_up = 1;
}
else {
v_gap_up = 0;
}
if open(period = timeFrame) < close(period = timeFrame)[1] and !v_contract_roll
then {
v_gap_down = 1;
}
else {
v_gap_down = 0;
}
case OpenClose:
if close(period = timeFrame) > open(period = timeFrame)
then {
v_gap_up = 1;
}
else {
v_gap_up = 0;
}
if close(period = timeFrame) < open(period = timeFrame)
then {
v_gap_down = 1;
}
else {
v_gap_down = 0;
}
case CloseClose:
if close(period = timeFrame) > close(period = timeFrame)[1] and !v_contract_roll
then {
v_gap_up = 1;
}
else {
v_gap_up = 0;
}
if close(period = timeFrame) < close(period = timeFrame)[1] and !v_contract_roll
then {
v_gap_down = 1;
}
else {
v_gap_down = 0;
}
}
def v_gap_size;
switch (i_type)
{
case CloseOpen:
if (v_gap_up or v_gap_down)
then {
v_gap_size = (open(period = timeFrame) - close(period = timeFrame)[1]) / v_tick_size;
}
else {
v_gap_size = 0;
}
case OpenClose:
if (v_gap_up or v_gap_down)
then {
v_gap_size = (close(period = timeFrame) - open(period = timeFrame)) / v_tick_size;
}
else {
v_gap_size = 0;
}
case CloseClose:
if (v_gap_up or v_gap_down)
then {
v_gap_size = (close(period = timeFrame) - close(period = timeFrame)[1]) / v_tick_size;
}
else {
v_gap_size = 0;
}
}
#ACCUMULATE THE GAPS THEMSELVES (IN TICKS). GAPS UP ARE ADDITIVE, GAPS DOWN ARE SUBTRACTIVE.
def v_mon_gap;
def v_tue_gap;
def v_wed_gap;
def v_thu_gap;
def v_fri_gap;
if v_weekday == 1 and (v_gap_up or v_gap_down)
then {v_mon_gap = v_mon_gap[1] + v_gap_size;}
else {v_mon_gap = v_mon_gap[1];}
if v_weekday == 2 and (v_gap_up or v_gap_down)
then {v_tue_gap = v_tue_gap[1] + v_gap_size;}
else {v_tue_gap = v_tue_gap[1];}
if v_weekday == 3 and (v_gap_up or v_gap_down)
then {v_wed_gap = v_wed_gap[1] + v_gap_size;}
else {v_wed_gap = v_wed_gap[1];}
if v_weekday == 4 and (v_gap_up or v_gap_down)
then {v_thu_gap = v_thu_gap[1] + v_gap_size;}
else {v_thu_gap = v_thu_gap[1];}
if v_weekday == 5 and (v_gap_up or v_gap_down)
then {v_fri_gap = v_fri_gap[1] + v_gap_size;}
else {v_fri_gap = v_fri_gap[1];}
def v_avg_gap_mon = TotalSum(AbsValue(v_mon_gap-v_mon_gap[1]))/TotalSum(v_mon_gap <> v_mon_gap[1]);
def v_avg_gap_tue = TotalSum(AbsValue(v_tue_gap-v_tue_gap[1]))/TotalSum(v_tue_gap <> v_tue_gap[1]);
def v_avg_gap_wed = TotalSum(AbsValue(v_wed_gap-v_wed_gap[1]))/TotalSum(v_wed_gap <> v_wed_gap[1]);
def v_avg_gap_thu = TotalSum(AbsValue(v_thu_gap-v_thu_gap[1]))/TotalSum(v_thu_gap <> v_thu_gap[1]);
def v_avg_gap_fri = TotalSum(AbsValue(v_fri_gap-v_fri_gap[1]))/TotalSum(v_fri_gap <> v_fri_gap[1]);
#PLOTS
plot p_mon_gap = Round(v_mon_gap * v_tick_size,2);
plot p_tue_gap = Round(v_tue_gap * v_tick_size,2);
plot p_wed_gap = Round(v_wed_gap * v_tick_size,2);
plot p_thu_gap = Round(v_thu_gap * v_tick_size,2);
plot p_fri_gap = Round(v_fri_gap * v_tick_size,2);
plot p_zero = 0;
#PLOT STYLES & SETTINGS
p_mon_gap.SetDefaultColor(Color.MAGENTA);
p_tue_gap.SetDefaultColor(Color.CYAN);
p_wed_gap.SetDefaultColor(Color.LIGHT_GRAY);
p_thu_gap.SetDefaultColor(Color.GREEN);
p_fri_gap.SetDefaultColor(Color.YELLOW);
p_zero.SetStyle(Curve.SHORT_DASH);
p_zero.SetDefaultColor(Color.WHITE);
p_zero.SetLineWeight(3);
AddLabel(i_print_day_labels, "MON", Color.MAGENTA);
AddLabel(i_print_day_labels, "TUE", Color.CYAN);
AddLabel(i_print_day_labels, "WED", Color.LIGHT_GRAY);
AddLabel(i_print_day_labels, "THU", Color.GREEN);
AddLabel(i_print_day_labels, "FRI", Color.YELLOW);
Last edited by a moderator: