declare lower; input length = 14; input over_sold = -45; input over_bought = 45; def price = close + low + high; def linDev = LinDev(price, length); plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015; plot OverBought = over_bought; plot ZeroLine = 0; plot OverSold = over_sold; CCI.SetDefaultColor(GetColor(9)); OverBought.SetDefaultColor(GetColor(5)); ZeroLine.SetDefaultColor(GetColor(5)); OverSold.SetDefaultColor(GetColor(5)); def cross_over_up = CCI[1] < 0 and CCI > 0; def cross_over_down = CCI[1] > 0 and CCI < 0; # tests # tests bars 1-10 Is current CCI greater then i+1 (previous) CCI rec CCI_last1_is_less = CCI[1] < CCI[0]; rec CCI_last2_is_less = CCI_last1_is_less is true and CCI[2] < CCI[0] ; rec CCI_last3_is_less = CCI_last2_is_less is true and CCI[3] < CCI[0]; rec CCI_last4_is_less = CCI_last3_is_less is true and CCI[4] < CCI[0]; rec CCI_last5_is_less = CCI_last4_is_less is true and CCI[5] < CCI[0]; rec CCI_last6_is_less = CCI_last5_is_less is true and CCI[6] < CCI[0]; rec CCI_last7_is_less = CCI_last6_is_less is true and CCI[7] < CCI[0]; rec CCI_last8_is_less = CCI_last7_is_less is true and CCI[8] < CCI[0]; rec CCI_last9_is_less = CCI_last8_is_less is true and CCI[9] < CCI[0]; rec CCI_last10_is_less = CCI_last9_is_less is true and CCI[10] < CCI[0]; # nomenclature pos= upper = positive CCI # is crossover last bar false, CCI positive, and last bar less then current (i+1) def test_1_bar_pos = cross_over_up is false and CCI > 0 and CCI_last1_is_less; def test_2_bar_pos = cross_over_up is false and CCI > 0 and CCI_last2_is_less; def test_3_bar_pos = cross_over_up is false and CCI > 0 and CCI_last3_is_less; def test_4_bar_pos = cross_over_up is false and CCI > 0 and CCI_last4_is_less; def test_5_bar_pos = cross_over_up is false and CCI > 0 and CCI_last5_is_less; def test_6_bar_pos = cross_over_up is false and CCI > 0 and CCI_last6_is_less; def test_7_bar_pos = cross_over_up is false and CCI > 0 and CCI_last7_is_less; def test_8_bar_pos = cross_over_up is false and CCI > 0 and CCI_last8_is_less; def test_9_bar_pos = cross_over_up is false and CCI > 0 and CCI_last9_is_less; def test_10_bar_pos = cross_over_up is false and CCI > 0 and CCI_last10_is_less; # tests bars 1-10 Is current CCI less then i+1 (previous) CCI rec CCI_last1_is_greater = CCI[1] > CCI[0]; rec CCI_last2_is_greater = CCI_last1_is_greater is true and CCI[2] > CCI[0] ; rec CCI_last3_is_greater = CCI_last2_is_greater is true and CCI[3] > CCI[0]; rec CCI_last4_is_greater = CCI_last3_is_greater is true and CCI[4] > CCI[0]; rec CCI_last5_is_greater = CCI_last4_is_greater is true and CCI[5] > CCI[0]; rec CCI_last6_is_greater = CCI_last5_is_greater is true and CCI[6] > CCI[0]; rec CCI_last7_is_greater = CCI_last6_is_greater is true and CCI[7] > CCI[0]; rec CCI_last8_is_greater = CCI_last7_is_greater is true and CCI[8] > CCI[0]; rec CCI_last9_is_greater = CCI_last8_is_greater is true and CCI[9] > CCI[0]; rec CCI_last10_is_greater = CCI_last9_is_greater is true and CCI[10] > CCI[0]; # are previous i+n CCI bars higher than current def test_11_bar_pos = test_2_bar_pos is false and test_3_bar_pos is false and test_4_bar_pos is false and test_5_bar_pos is false and test_6_bar_pos is false and test_7_bar_pos is false and test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_22_bar_pos = test_3_bar_pos is false and test_4_bar_pos is false and test_5_bar_pos is false and test_6_bar_pos is false and test_7_bar_pos is false and test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_33_bar_pos = test_4_bar_pos is false and test_5_bar_pos is false and test_6_bar_pos is false and test_7_bar_pos is false and test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_44_bar_pos = test_5_bar_pos is false and test_6_bar_pos is false and test_7_bar_pos is false and test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_55_bar_pos = test_6_bar_pos is false and test_7_bar_pos is false and test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_66_bar_pos = test_7_bar_pos is false and test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_77_bar_pos = test_8_bar_pos is false and test_9_bar_pos is false and test_10_bar_pos is false; def test_88_bar_pos = test_9_bar_pos is false and test_10_bar_pos is false; def test_99_bar_pos = test_10_bar_pos is false; # nomenclature neg = negative CCI # is crossover last bar false, CCI negative, and last bar greater then current (i+1) def test_1_bar_neg = cross_over_down is false and CCI < 0 and CCI_last1_is_greater; def test_2_bar_neg = cross_over_down is false and CCI < 0 and CCI_last2_is_greater; def test_3_bar_neg = cross_over_down is false and CCI < 0 and CCI_last3_is_greater; def test_4_bar_neg = cross_over_down is false and CCI < 0 and CCI_last4_is_greater; def test_5_bar_neg = cross_over_down is false and CCI < 0 and CCI_last5_is_greater; def test_6_bar_neg = cross_over_down is false and CCI < 0 and CCI_last6_is_greater; def test_7_bar_neg = cross_over_down is false and CCI < 0 and CCI_last7_is_greater; def test_8_bar_neg = cross_over_down is false and CCI < 0 and CCI_last8_is_greater; def test_9_bar_neg = cross_over_down is false and CCI < 0 and CCI_last9_is_greater; def test_10_bar_neg = cross_over_down is false and CCI < 0 and CCI_last10_is_greater; # are previous i+n CCI bars lower than current def test_11_bar_neg = test_2_bar_neg is false and test_3_bar_neg is false and test_4_bar_neg is false and test_5_bar_neg is false and test_6_bar_neg is false and test_7_bar_neg is false and test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_22_bar_neg = test_3_bar_neg is false and test_4_bar_neg is false and test_5_bar_neg is false and test_6_bar_neg is false and test_7_bar_neg is false and test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_33_bar_neg = test_4_bar_neg is false and test_5_bar_neg is false and test_6_bar_neg is false and test_7_bar_neg is false and test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_44_bar_neg = test_5_bar_neg is false and test_6_bar_neg is false and test_7_bar_neg is false and test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_55_bar_neg = test_6_bar_neg is false and test_7_bar_neg is false and test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_66_bar_neg = test_7_bar_neg is false and test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_77_bar_neg = test_8_bar_neg is false and test_9_bar_neg is false and test_10_bar_neg is false; def test_88_bar_neg = test_9_bar_neg is false and test_10_bar_neg is false; def test_99_bar_neg = test_10_bar_neg is false; #Run tests counter_upper = pos CCI counter #if CCI positive and last CCI greater then increment counter_upper else #if last bar counter is not zero and is not a positive crossover, CCI positive, and last bar less then current (i+1) then upper counter_upper is replaced with previous counter_upper else # if previous upper_counter zero then set upper_couter to zerobase uppper counter_upper rec counter_upper = if cross_over_up then 0 else if cross_over_up is false and CCI_last1_is_greater and CCI > 0 then counter_upper[1] + 1 else if test_1_bar_pos and test_11_bar_pos and counter_upper[1] <> 0 then counter_upper[1] else if test_1_bar_pos and counter_upper[1] == 0 then 0 else if test_2_bar_pos and test_22_bar_pos and counter_upper[1] <> 0 then counter_upper[2] else if test_2_bar_pos and counter_upper[2] == 0 then 0 else if test_3_bar_pos and test_33_bar_pos and counter_upper[1] <> 0 then counter_upper[3] else if test_3_bar_pos and counter_upper[3] == 0 then 0 else if test_4_bar_pos and test_44_bar_pos and counter_upper[1] <> 0 then counter_upper[4] else if test_4_bar_pos and counter_upper[4] == 0 then 0 else if test_5_bar_pos and test_55_bar_pos and counter_upper[1] <> 0 then counter_upper[5] else if test_5_bar_pos and counter_upper[5] == 0 then 0 else if test_6_bar_pos and test_66_bar_pos and counter_upper[1] <> 0 then counter_upper[6] else if test_6_bar_pos and counter_upper[6] == 0 then 0 else if test_7_bar_pos and test_77_bar_pos and counter_upper[1] <> 0 then counter_upper[7] else if test_7_bar_pos and counter_upper[7] == 0 then 0 else if test_8_bar_pos and test_88_bar_pos and counter_upper[1] <> 0 then counter_upper[8] else if test_8_bar_pos and counter_upper[8] == 0 then 0 else if test_9_bar_pos and test_99_bar_pos and counter_upper[1] <> 0 then counter_upper[9] else if test_9_bar_pos and counter_upper[9] == 0 then 0 else if test_10_bar_pos and counter_upper[1] <> 0 then counter_upper[10] else if test_10_bar_pos and counter_upper[10] == 0 then 0 else 0; AddVerticalLine(CCI > 0 and counter_upper<>0, concat(" ",concat(counter_upper,"")), Color.BLUE); #Run tests counter_lower = neg CCI counter #if CCI negative and last CCI less then increment counter_lower else #if last bar counter is not zero and is not a negative crossover, CCI negative, and last bar less then current (i+1) then lower counter_lower is replaced with previous counter_lower else # if previous counter_lower zero then set counter_lower to zero base counter_lower rec counter_lower = if cross_over_down then 0 else if cross_over_down is false and CCI_last1_is_less and CCI < 0 then counter_lower[1] + 1 else if test_1_bar_neg and test_11_bar_neg and counter_lower[1] <> 0 then counter_lower[1] else if test_1_bar_neg and counter_lower[1] == 0 then 0 else if test_2_bar_neg and test_22_bar_neg and counter_lower[1] <> 0 then counter_lower[2] else if test_2_bar_neg and counter_lower[2] == 0 then 0 else if test_3_bar_neg and test_33_bar_neg and counter_lower[1] <> 0 then counter_lower[3] else if test_3_bar_neg and counter_lower[3] == 0 then 0 else if test_4_bar_neg and test_44_bar_neg and counter_lower[1] <> 0 then counter_lower[4] else if test_4_bar_neg and counter_lower[4] == 0 then 0 else if test_5_bar_neg and test_55_bar_neg and counter_lower[1] <> 0 then counter_lower[5] else if test_5_bar_neg and counter_lower[5] == 0 then 0 else if test_6_bar_neg and test_66_bar_neg and counter_lower[1] <> 0 then counter_lower[6] else if test_6_bar_neg and counter_lower[6] == 0 then 0 else if test_7_bar_neg and test_77_bar_neg and counter_lower[1] <> 0 then counter_lower[7] else if test_7_bar_neg and counter_lower[7] == 0 then 0 else if test_8_bar_neg and test_88_bar_neg and counter_lower[1] <> 0 then counter_lower[8] else if test_8_bar_neg and counter_lower[8] == 0 then 0 else if test_9_bar_neg and test_99_bar_neg and counter_lower[1] <> 0 then counter_lower[9] else if test_9_bar_neg and counter_lower[9] == 0 then 0 else if test_10_bar_neg and counter_lower[1] <> 0 then counter_lower[10] else if test_10_bar_neg and counter_lower[10] == 0 then 0 else 0; AddVerticalLine(CCI < 0 and counter_lower <>0, Concat(counter_lower, ""), Color.red);