Programmatic Support and Resistance for Thinkorswim

HighBredCloud

Well-known member
VIP
@HighBredCloud We both on the same boat. I have no idea, all of the sudden @netarchitech just disappear. Regardless, I hope him well.
Well IF anyone that knows him or has contact with him post an update in regards to his sudden disappearance. I know many people on here know each other outside of this forum...Its not like he was a fly by new member here for the indicators...At least @tomsk posted why he would be MIA this year...I think it would be a good idea to at least let the community know why you're not going to be around...Ben do you have members e-mails that can be used for checking up on them? Especially in the Covid-19 months who knows what can happen...
 
A little modification to this indicator. Creates a zone appearance instead of a thin line.

xVgjXpA.png


Code:
#Programmatic_SupportResistance_WickZoneMod
declare upper;

input LookbackPeriod = 5;
input HideCurrentTF = no;
input HideTimeFrame2 = no;
input HideTimeFrame3 = no;
input TimeFrame2 = {default "15 MIN", "1 MIN", "2 MIN", "3 MIN", "4 MIN", "5 MIN", "10 MIN", "20 MIN", "30 MIN", "1 HOUR", "2 HOURS", "4 HOURS", DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPT EXP"};
input TimeFrame3 = {"30 MIN", "1 MIN", "2 MIN", "3 MIN", "4 MIN", "5 MIN", "10 MIN", "15 MIN", "20 MIN",default "1 HOUR", "2 HOURS", "4 HOURS", DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPT EXP"};
input HideSwings = no;
input SwingsLagBar = 1;

#--------------------------------------------------------------
def _highInPeriod1 = Highest(high, LookbackPeriod);
def _lowInPeriod1 = Lowest(low, LookbackPeriod);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod];
def _markedLow1 = low == marketLow1;

rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then low else _lastMarkedLow1[1], low);
rec _lastMarkedLow11 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow11[1] else if _markedLow1 then Min(open, close) else _lastMarkedLow11[1], low);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod];
def _markedHigh1 = high == marketHigh1;

rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then high else _lastMarkedHigh1[1], high);
rec _lastMarkedHigh11 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh11[1] else if _markedHigh1 then Max(open, close) else _lastMarkedHigh11[1], high);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Resistance11 = _lastMarkedHigh11;
plot Support1 = _lastMarkedLow1;
plot Support11 = _lastMarkedLow11;
#--------------------------------------------------------------
Resistance11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance11.SetDefaultColor(Color.MAGENTA);
Resistance11.SetHiding(HideCurrentTF);
Resistance1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance1.SetDefaultColor(Color.MAGENTA);
Resistance1.SetHiding(HideCurrentTF);
AddCloud(Resistance1, Resistance11, Color.MAGENTA, Color.MAGENTA);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support1.SetDefaultColor(Color.YELLOW);
Support1.SetHiding(HideCurrentTF);
Support11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support11.SetDefaultColor(Color.YELLOW);
Support11.SetHiding(HideCurrentTF);
AddCloud(Support1, Support11, Color.YELLOW, Color.YELLOW);

#--------------------------------------------------------------
def LowSwingForw = Lowest(low, SwingsLagBar)[-SwingsLagBar];
def LowSwingBack = Lowest(low, LookbackPeriod)[1];
def SwingLow = if low < LowSwingForw and low <= LowSwingBack then 1 else 0;
plot LowSwing = if SwingLow then low else Double.NaN;
LowSwing.Hide();
#--------------------------------------------------------------
def HighSwingForw = Highest(high, SwingsLagBar)[-SwingsLagBar];
def HighSwingBack = Highest(high, LookbackPeriod)[1];
def SwingHigh = if high > HighSwingForw and high >= HighSwingBack then 1 else 0;
plot HighSwing = if SwingHigh then high else Double.NaN;
HighSwing.Hide();
#--------------------------------------------------------------
HighSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
HighSwing.SetLineWeight(5);
HighSwing.SetDefaultColor(Color.MAGENTA);
HighSwing.SetHiding(HideSwings);
LowSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LowSwing.SetLineWeight(5);
LowSwing.SetDefaultColor(Color.YELLOW);
LowSwing.SetHiding(HideSwings);
#--------------------------------------------------------------
Alert(HighSwing, "SupRes : Swing High", Alert.BAR, Sound.Bell);
Alert(LowSwing, "SupRes : Swing Low", Alert.BAR, Sound.Bell);
#--------------------------------------------------------------
AddLabel(HighSwing, "SupRes : Swing High", Color.MAGENTA);
AddLabel(LowSwing, "SupRes : Swing Low", Color.YELLOW);
#--------------------------------------------------------------
def _highInPeriod2 = Highest(high(period = TimeFrame2), LookbackPeriod);
def _lowInPeriod2 = Lowest(low(period = TimeFrame2), LookbackPeriod);
#--------------------------------------------------------------
def marketLow2 = if _lowInPeriod2 < _lowInPeriod2[-LookbackPeriod] then _lowInPeriod2 else _lowInPeriod2[-LookbackPeriod];
def _markedLow2 = low(period = TimeFrame2) == marketLow2;

rec _lastMarkedLow2 = CompoundValue(1, if IsNaN(_markedLow2) then _lastMarkedLow2[1] else if _markedLow2 then low(period = TimeFrame2) else _lastMarkedLow2[1], low(period = TimeFrame2));
rec _lastMarkedLow22 = CompoundValue(1, if IsNaN(_markedLow2) then _lastMarkedLow22[1] else if _markedLow2 then Min(open, close(period = TimeFrame2)) else _lastMarkedLow22[1], low(period = TimeFrame2));
#--------------------------------------------------------------
def marketHigh2 = if _highInPeriod2 > _highInPeriod2[-LookbackPeriod] then _highInPeriod2 else _highInPeriod2[-LookbackPeriod];
def _markedHigh2 = high(period = TimeFrame2) == marketHigh2;

rec _lastMarkedHigh2 = CompoundValue(1, if IsNaN(_markedHigh2) then _lastMarkedHigh2[1] else if _markedHigh2 then high(period = TimeFrame2) else _lastMarkedHigh2[1], high(period = TimeFrame2));
rec _lastMarkedHigh22 = CompoundValue(1, if IsNaN(_markedHigh2) then _lastMarkedHigh22[1] else if _markedHigh2 then Max(open, close(period = TimeFrame2)) else _lastMarkedHigh22[1], high(period = TimeFrame2));
#--------------------------------------------------------------
plot Resistance2 = _lastMarkedHigh2;
plot Resistance22 = _lastMarkedHigh22;
plot Support2 = _lastMarkedLow2;
plot Support22 = _lastMarkedLow22;
#--------------------------------------------------------------
Resistance2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance2.SetDefaultColor(Color.PINK);
Resistance2.SetHiding(HideTimeFrame2);
Resistance22.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance22.SetDefaultColor(Color.PINK);
Resistance22.SetHiding(HideTimeFrame2);
AddCloud(Resistance2, Resistance22, Color.PINK, Color.PINK);
#--------------------------------------------------------------
Support2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support2.SetDefaultColor(Color.ORANGE);
Support2.SetHiding(HideTimeFrame2);
Support22.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support22.SetDefaultColor(Color.ORANGE);
Support22.SetHiding(HideTimeFrame2);
AddCloud(Support2, Support22, Color.ORANGE, Color.ORANGE);
#--------------------------------------------------------------
def _highInPeriod3 = Highest(high(period = TimeFrame3), LookbackPeriod);
def _lowInPeriod3 = Lowest(low(period = TimeFrame3), LookbackPeriod);
#--------------------------------------------------------------
def marketLow3 = if _lowInPeriod3 < _lowInPeriod3[-LookbackPeriod] then _lowInPeriod3 else _lowInPeriod3[-LookbackPeriod];
def _markedLow3 = low(period = TimeFrame3) == marketLow3;

rec _lastMarkedLow3 = CompoundValue(1, if IsNaN(_markedLow3) then _lastMarkedLow3[1] else if _markedLow3 then low(period = TimeFrame3) else _lastMarkedLow3[1], low(period = TimeFrame3));
rec _lastMarkedLow33 = CompoundValue(1, if IsNaN(_markedLow3) then _lastMarkedLow33[1] else if _markedLow3 then Min(open, close(period = TimeFrame3)) else _lastMarkedLow33[1], low(period = TimeFrame3));
#--------------------------------------------------------------
def marketHigh3 = if _highInPeriod3 > _highInPeriod3[-LookbackPeriod] then _highInPeriod3 else _highInPeriod3[-LookbackPeriod];
def _markedHigh3 = high(period = TimeFrame3) == marketHigh3;

rec _lastMarkedHigh3 = CompoundValue(1, if IsNaN(_markedHigh3) then _lastMarkedHigh3[1] else if _markedHigh3 then high(period = TimeFrame3) else _lastMarkedHigh3[1], high(period = TimeFrame3));
rec _lastMarkedHigh33 = CompoundValue(1, if IsNaN(_markedHigh3) then _lastMarkedHigh33[1] else if _markedHigh3 then  Max(open, close(period = TimeFrame3)) else _lastMarkedHigh33[1], high(period = TimeFrame3));
#--------------------------------------------------------------
plot Resistance3 = _lastMarkedHigh3;
plot Resistance33 = _lastMarkedHigh33;
plot Support3 = _lastMarkedLow3;
plot Support33 = _lastMarkedLow33;
#--------------------------------------------------------------
Resistance3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance3.SetDefaultColor(Color.PLUM);
Resistance3.SetHiding(HideTimeFrame3);
Resistance33.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance33.SetDefaultColor(Color.PLUM);
Resistance33.SetHiding(HideTimeFrame3);
AddCloud(Resistance3, Resistance33, Color.PLUM, Color.PLUM);
#--------------------------------------------------------------
Support3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support3.SetDefaultColor(Color.DARK_ORANGE);
Support3.SetHiding(HideTimeFrame3);
Support33.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support33.SetDefaultColor(Color.DARK_ORANGE);
Support33.SetHiding(HideTimeFrame3);
AddCloud(Support3, Support33, Color.DARK_ORANGE, Color.DARK_ORANGE);
 
Last edited by a moderator:

Trading51

Active member
2019 Donor
does anyone know if the horizontal lines at the pivot high and low get drawn after x amount of bars any logic that someone could share thanks.
 

lowtrade

Member
VIP
Hi, I did a search on the forum but I couldn't find it.

I'm looking for a scan where I would get the stocks that are trading very close the support level. Something similar to the below one.

SiX5Cic.jpg
 

Cwparker23

New member
Added two more lookbackperiods and a function to turn the cloud off for the 2nd and 3rd periods. I did this because I like to trade on the three-minute time frame. my first lookbackperiod is 5, which gives me fifteen minutes worth oh data. my second lookbackperiod is 4 on a fifteen-minute time frame which gives me an hour's worth of data. My third lookbackperiod is 4 on an hour's time frame, which gives me four hours worth of data.
Code:
#Programmatic_SupportResistance_WickZoneMod
# CWPARKER remastered
declare upper;
input TimeFrame1 = AggregationPeriod.THREE_MIN;
input TimeFrame2 = AggregationPeriod.FIFTEEN_MIN;
input TimeFrame3 = AggregationPeriod.HOUR;
input LookbackPeriod1 = 5;
input LookbackPeriod2 = 5;
input LookbackPeriod3 = 5;
input HideTimeFrame2 = no;
input HideTimeFrame2_cloud = no;
input HideTimeFrame3 = no;
input HideTimeFrame3_cloud = no;
input HideCurrentTF = no;
input HideSwings = no;
input SwingsLagBar = 1;
def C = close (period =  TimeFrame1);
def O = open (period =  TimeFrame1);
def H = HIGH(period =  TimeFrame1);
DEF L = LOW(period =  TimeFrame1);
##############################################
def H2 = HIGH(period =  TimeFrame2);
DEF L2 = LOW(period =  TimeFrame2);
def C2 = close (period =  TimeFrame2);
def O2 = open (period =  TimeFrame2);
#############################################
def H3 = HIGH(period =  TimeFrame3);
DEF L3 = LOW(period =  TimeFrame3);
def C3 = close (period =  TimeFrame3);
def O3 = open (period =  TimeFrame3);
#########################################

#--------------------------------------------------------------
def _highInPeriod1 = Highest(h, LookbackPeriod1);
def _lowInPeriod1 = Lowest(l, LookbackPeriod1);
#--------------------------------------------------------------
def marketLow1 = if _lowInPeriod1 < _lowInPeriod1[-LookbackPeriod1] then _lowInPeriod1 else _lowInPeriod1[-LookbackPeriod1];
def _markedLow1 = l == marketLow1;

rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow1[1] else if _markedLow1 then l else _lastMarkedLow1[1], l);
rec _lastMarkedLow11 = CompoundValue(1, if IsNaN(_markedLow1) then _lastMarkedLow11[1] else if _markedLow1 then Min(o, c) else _lastMarkedLow11[1], l);
#--------------------------------------------------------------
def marketHigh1 = if _highInPeriod1 > _highInPeriod1[-LookbackPeriod1] then _highInPeriod1 else _highInPeriod1[-LookbackPeriod1];
def _markedHigh1 = h == marketHigh1;

rec _lastMarkedHigh1 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh1[1] else if _markedHigh1 then H else _lastMarkedHigh1[1], h);
rec _lastMarkedHigh11 = CompoundValue(1, if IsNaN(_markedHigh1) then _lastMarkedHigh11[1] else if _markedHigh1 then Max(o, c) else _lastMarkedHigh11[1], h);
#--------------------------------------------------------------
plot Resistance1 = _lastMarkedHigh1;
plot Resistance11 = _lastMarkedHigh11;
plot Support1 = _lastMarkedLow1;
plot Support11 = _lastMarkedLow11;
#--------------------------------------------------------------
Resistance11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance11.SetDefaultColor(Color.pink);
Resistance11.SetHiding(HideCurrentTF);
Resistance1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance1.SetDefaultColor(Color.pink);
Resistance1.SetHiding(HideCurrentTF);
AddCloud(Resistance1, Resistance11, Color.pink, Color.pink);
#--------------------------------------------------------------
Support1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support1.SetDefaultColor(Color.white);
Support1.SetHiding(HideCurrentTF);
Support11.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support11.SetDefaultColor(Color.white);
Support11.SetHiding(HideCurrentTF);
AddCloud(Support1, Support11, Color.white, Color.white);

#--------------------------------------------------------------
def LowSwingForw = Lowest(l, SwingsLagBar)[-SwingsLagBar];
def LowSwingBack = Lowest(l, LookbackPeriod1)[1];
def SwingLow = if l < LowSwingForw and l <= LowSwingBack then 1 else 0;
plot LowSwing = if SwingLow then l else Double.NaN;
LowSwing.Hide();
#--------------------------------------------------------------
def HighSwingForw = Highest(h, SwingsLagBar)[-SwingsLagBar];
def HighSwingBack = Highest(h, LookbackPeriod1)[1];
def SwingHigh = if h > HighSwingForw and h >= HighSwingBack then 1 else 0;
plot HighSwing = if SwingHigh then h else Double.NaN;
HighSwing.Hide();
#--------------------------------------------------------------
HighSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
HighSwing.SetLineWeight(5);
HighSwing.SetDefaultColor(Color.MAGENTA);
HighSwing.SetHiding(HideSwings);
LowSwing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
LowSwing.SetLineWeight(5);
LowSwing.SetDefaultColor(Color.YELLOW);
LowSwing.SetHiding(HideSwings);
#--------------------------------------------------------------
Alert(HighSwing, "SupRes : Swing High", Alert.BAR, Sound.Bell);
Alert(LowSwing, "SupRes : Swing Low", Alert.BAR, Sound.Bell);
#--------------------------------------------------------------
AddLabel(HighSwing, "SupRes : Swing High", Color.MAGENTA);
AddLabel(LowSwing, "SupRes : Swing Low", Color.YELLOW);
#--------------------------------------------------------------
def _highInPeriod2 = Highest(h2, LookbackPeriod2);
def _lowInPeriod2 = Lowest(l2, LookbackPeriod2);
#--------------------------------------------------------------
def marketLow2 = if _lowInPeriod2 < _lowInPeriod2[-LookbackPeriod2] then _lowInPeriod2 else _lowInPeriod2[-LookbackPeriod2];
def _markedLow2 = l2 == marketLow2;

rec _lastMarkedLow2 = CompoundValue(1, if IsNaN(_markedLow2) then _lastMarkedLow2[1] else if _markedLow2 then l2 else _lastMarkedLow2[1], l2);
rec _lastMarkedLow22 = CompoundValue(1, if IsNaN(_markedLow2) then _lastMarkedLow22[1] else if _markedLow2 then Min(o2, c2) else _lastMarkedLow22[1], l2);
#--------------------------------------------------------------
def marketHigh2 = if _highInPeriod2 > _highInPeriod2[-LookbackPeriod2] then _highInPeriod2 else _highInPeriod2[-LookbackPeriod2];
def _markedHigh2 = h2 == marketHigh2;

rec _lastMarkedHigh2 = CompoundValue(1, if IsNaN(_markedHigh2) then _lastMarkedHigh2[1] else if _markedHigh2 then h2 else _lastMarkedHigh2[1], h2);
rec _lastMarkedHigh22 = CompoundValue(1, if IsNaN(_markedHigh2) then _lastMarkedHigh22[1] else if _markedHigh2 then Max(o2, c2) else _lastMarkedHigh22[1], h2);
#--------------------------------------------------------------
plot Resistance2 = _lastMarkedHigh2;
plot Resistance22 = _lastMarkedHigh22;
plot Support2 = _lastMarkedLow2;
plot Support22 = _lastMarkedLow22;
#--------------------------------------------------------------
Resistance2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance2.SetDefaultColor(Color.RED);
Resistance2.SetHiding(HideTimeFrame2);
Resistance22.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance22.SetDefaultColor(Color.RED);
Resistance22.SetHiding(HideTimeFrame2);
AddCloud(if !HideTimeFrame2_cloud  then RESistance2 else Double.NaN, RESistance22 , Color.RED, Color.RED);
#--------------------------------------------------------------
Support2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support2.SetDefaultColor(Color.LIGHT_GREEN);
Support2.SetHiding(HideTimeFrame2);
Support22.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support22.SetDefaultColor(Color.LIGHT_GREEN);
Support22.SetHiding(HideTimeFrame2);
AddCloud(if !HideTimeFrame2_cloud  then SUPPort2  else Double.NaN, SUPPort22  , Color.LIGHT_GREEN, Color.LIGHT_GREEN);
#--------------------------------------------------------------
def _highInPeriod3 = Highest(h3, LookbackPeriod3);
def _lowInPeriod3 = Lowest(l3, LookbackPeriod3);
#--------------------------------------------------------------
def marketLow3 = if _lowInPeriod3 < _lowInPeriod3[-LookbackPeriod3] then _lowInPeriod3 else _lowInPeriod3[-LookbackPeriod3];
def _markedLow3 = l3 == marketLow3;

rec _lastMarkedLow3 = CompoundValue(1, if IsNaN(_markedLow3) then _lastMarkedLow3[1] else if _markedLow3 then l3 else _lastMarkedLow3[1], l3);
rec _lastMarkedLow33 = CompoundValue(1, if IsNaN(_markedLow3) then _lastMarkedLow33[1] else if _markedLow3 then Min(o3, c3) else _lastMarkedLow33[1], l3);
#--------------------------------------------------------------
def marketHigh3 = if _highInPeriod3 > _highInPeriod3[-LookbackPeriod3] then _highInPeriod3 else _highInPeriod3[-LookbackPeriod3];
def _markedHigh3 = h3 == marketHigh3;

rec _lastMarkedHigh3 = CompoundValue(1, if IsNaN(_markedHigh3) then _lastMarkedHigh3[1] else if _markedHigh3 then h3 else _lastMarkedHigh3[1], h3);
rec _lastMarkedHigh33 = CompoundValue(1, if IsNaN(_markedHigh3) then _lastMarkedHigh33[1] else if _markedHigh3 then  Max(o3, c3) else _lastMarkedHigh33[1], h3);

#--------------------------------------------------------------
plot Resistance3 = _lastMarkedHigh3;
plot Resistance33 = _lastMarkedHigh33;
plot Support3 = _lastMarkedLow3;
plot Support33 = _lastMarkedLow33;
#--------------------------------------------------------------
Resistance3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance3.SetDefaultColor(Color.MAGENTA);
Resistance3.SetHiding(HideTimeFrame3);
Resistance33.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Resistance33.SetDefaultColor(Color.MAGENTA );
Resistance33.SetHiding(HideTimeFrame3);
AddCloud(if !HideTimeFrame3_Cloud  then RESistance3 else Double.NaN, RESistance33 , Color.MAGENTA, Color.MAGENTA);
#--------------------------------------------------------------
Support3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support3.SetDefaultColor(Color.DARK_GREEN);
Support3.SetHiding(HideTimeFrame3);
Support33.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Support33.SetDefaultColor(Color.DARK_GREEN);
Support33.SetHiding(HideTimeFrame3);
AddCloud(if !HideTimeFrame3_Cloud  then Support3  else Double.NaN, Support33 , Color.DARK_GREEN, Color.DARK_GREEN);
 
Last edited:

QUIKTDR1

Member
VIP
Could we write a code for IF ((C1 +O+H+L+C*2) /6) >3ema and C> 8ema >13 ema >20ema and XAvgC3>Avg(XAvgC3,5) and XAvgC8 > XAvgc8.1 then BUY and if XAvgC3<Avg(XAvgC3,5) and ((C1 +O+H+L+C*2) /6) <3ema and C< 8ema <13 ema <20ema XAvgC8 < XAvgc8.1 then sell
 

theLEMband

New member
VIP
Added two more lookbackperiods and a function to turn the cloud off for the 2nd and 3rd periods. I did this because I like to trade on the three-minute time frame. my first lookbackperiod is 5, which gives me fifteen minutes worth oh data. my second lookbackperiod is 4 on a fifteen-minute time frame which gives me an hour's worth of data. My third lookbackperiod is 4 on an hour's time frame, which gives me four hours worth of data.
This is great, now one of my favorite tools!
 

joshua74133

Member
VIP
im wanting it to ding and change the background color when the price touches the topline. my brain is numb trying to figure it out

Code:
input magnitude = 2;
input showValues = yes;
def top = high >= Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude);
def topvalue = if BarNumber() < magnitude then Double.NaN else if top    then high else topvalue[1];
plot topline = topvalue;
def countp = if IsNaN(top) and !IsNaN(top[1]) then 1 else countp[1] + 1;
plot peaktop = if IsNaN(top) then GetValue(topline, countp) else Double.NaN;
def bottom = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude);
def bottomValue = if BarNumber() < magnitude then Double.NaN else if bottom then low else bottomValue[1];
plot bottomline = bottomValue;


topline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topline.SetDefaultColor(Color.RED);
peaktop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peaktop.SetDefaultColor(Color.RED);
bottomline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bottomline.SetDefaultColor(Color.GREEN);
 
Last edited by a moderator:

BenTen

Administrative
Staff
VIP
@joshua74133 Add the following to the bottom of your script:

Code:
def condition = close crosses above Topline;
AssignPriceColor(if condition then color.green else color.white);
Alert(condition, " ", Alert.Bar, Sound.Chimes);
 

joshua74133

Member
VIP
@BenTen i tried to add another condition but IF is in red.

Code:
def condition = if open is equal to topline and RSI > over_Bought then
AssignPriceColor(if condition then Color.GREEN else Color.CURRENT);
Alert(condition, " ", Alert.BAR, Sound.Chimes);

here is the whole script

Code:
declare lower;

input length = 7;
input over_Bought = 50;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

plot RSI = 50 * (ChgRatio + 1);
plot OverSold = over_Sold;
plot OverBought = over_Bought;
plot UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
plot DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

RSI.DefineColor("OverBought", GetColor(5));
RSI.DefineColor("Normal", GetColor(7));
RSI.DefineColor("OverSold", GetColor(1));
RSI.AssignValueColor(if RSI > over_Bought then RSI.Color("OverBought") else if RSI < over_Sold then RSI.Color("OverSold") else RSI.Color("Normal"));
OverSold.SetDefaultColor(GetColor(8));
OverBought.SetDefaultColor(GetColor(8));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);


input magnitude = 2;
input showValues = yes;
def top = high >= Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude);
def topvalue = if BarNumber() < magnitude then Double.NaN else if top    then high else topvalue[1];
plot topline = topvalue;
def countp = if IsNaN(top) and !IsNaN(top[1]) then 1 else countp[1] + 1;
plot peaktop = if IsNaN(top) then GetValue(topline, countp) else Double.NaN;
def bottom = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude);
def bottomValue = if BarNumber() < magnitude then Double.NaN else if bottom then low else bottomValue[1];
plot bottomline = bottomValue;


topline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
topline.SetDefaultColor(Color.RED);
peaktop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peaktop.SetDefaultColor(Color.RED);
bottomline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bottomline.SetDefaultColor(Color.GREEN);

def condition = if open is equal to topline and RSI > over_Bought then
AssignPriceColor(if condition then Color.GREEN else Color.CURRENT);
Alert(condition, " ", Alert.BAR, Sound.Chimes);
 

Similar threads

Top