# Floor Traders pivots (can be used in scanner)
# Mobius
# V01.06.2011
def Today = GetDay() == GetLastDay();
def Yesterday = GetDay() == GetLastDay() - 1;
def last = if Today and !Today[1]
then close[1]
else last[1];
def prevHigh = if YesterDay and !YesterDay[1]
then high
else if Yesterday and
high > prevHigh[1]
then high
else prevHigh[1];
def prevLow = if Yesterday and !Yesterday[1]
then low
else if Yesterday and
low < prevLow[1]
then low
else prevLow[1];
def BubbleLocation = !yesterday and yesterday[1];
plot pHigh = prevHigh;
pHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pHigh.SetDefaultColor(color.dark_green);
AddChartBubble(BubbleLocation, prevHigh, "Prev High", Color.DARK_GRAY, no);
plot pLow = prevLow;
pLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pLow.SetDefaultColor(color.dark_red);
AddChartBubble(BubbleLocation, prevLow, "Prev low", Color.DARK_GRAY, no);
plot pivot = (prevHigh + prevLow + last) / 3;
pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
pivot.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, pivot, "Pivot", Color.DARK_GRAY, no);
plot R1 = Round(((2 * pivot) - prevLow) / TickSize(), 0) * TickSize();
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, R1, "R1", Color.DARK_GRAY, no);
plot S1 = Round(((2 * pivot) - prevHigh) / TickSize(), 0) * TickSize();
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, S1, "S1", Color.DARK_GRAY, yes);
plot R2 = Round((pivot + (R1 - S1)) / TickSize(), 0) * TickSize();
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, R2, "R2", Color.DARK_GRAY, no);
plot S2 = Round((pivot - (R1 - S1)) / TickSize(), 0) * TickSize();
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, S2, "S2", Color.DARK_GRAY, yes);
plot R3 = Round((prevHigh + (2 * (pivot - prevLow))) / TickSize(), 0) * TickSize();
R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, R3, "R3", Color.DARK_GRAY, no);
plot S3 = Round((prevLow - (2 * (prevHigh - pivot))) / TickSize(), 0) * TickSize();
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, S3, "S3", Color.DARK_GRAY, yes);
plot R4 = Round((prevHigh + (3 * (pivot - prevLow))) / TickSize(), 0) * TickSize();
R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R4.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, R4, "R4", Color.DARK_GRAY, no);
plot S4 = Round((prevLow - (3 * (prevHigh - pivot))) / TickSize(), 0) * TickSize();
S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S4.SetDefaultColor(color.dark_gray);
AddChartBubble(BubbleLocation, S4, "S4", Color.DARK_GRAY, yes);
AddLabel(1, "Yesterdays Close = " + last,
if close > last then color.green
else if close == last then color.cyan
else color.red);
# Scan examples
# If you name this study "Floor_Trader_Pivots_Scan" you can reference the study in the scanner and scan for equities crossing above or below any of the plots using the format below.
# close crosses above Floor_Trader_Pivots_Scan()."R1"
# End Code Floor Trader Pivots
Hi, thanks for the code can you share this study via TOS?@KCLLive Haven't looked at your script any, but Mobius of the TSL coded Floor Trader Pivots for ThinkorSwim a decade ago. I'm certainly not trying to dissuade you from continuing your script - I think it very commendable that you are actively trying vs wanting others to do the coding. This may make it easier.
Code:# Floor Traders pivots (can be used in scanner) # Mobius # V01.06.2011 def Today = GetDay() == GetLastDay(); def Yesterday = GetDay() == GetLastDay() - 1; def last = if Today and !Today[1] then close[1] else last[1]; def prevHigh = if YesterDay and !YesterDay[1] then high else if Yesterday and high > prevHigh[1] then high else prevHigh[1]; def prevLow = if Yesterday and !Yesterday[1] then low else if Yesterday and low < prevLow[1] then low else prevLow[1]; def BubbleLocation = !yesterday and yesterday[1]; plot pHigh = prevHigh; pHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pHigh.SetDefaultColor(color.dark_green); AddChartBubble(BubbleLocation, prevHigh, "Prev High", Color.DARK_GRAY, no); plot pLow = prevLow; pLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pLow.SetDefaultColor(color.dark_red); AddChartBubble(BubbleLocation, prevLow, "Prev low", Color.DARK_GRAY, no); plot pivot = (prevHigh + prevLow + last) / 3; pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pivot.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, pivot, "Pivot", Color.DARK_GRAY, no); plot R1 = Round(((2 * pivot) - prevLow) / TickSize(), 0) * TickSize(); R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R1.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R1, "R1", Color.DARK_GRAY, no); plot S1 = Round(((2 * pivot) - prevHigh) / TickSize(), 0) * TickSize(); S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S1.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S1, "S1", Color.DARK_GRAY, yes); plot R2 = Round((pivot + (R1 - S1)) / TickSize(), 0) * TickSize(); R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R2.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R2, "R2", Color.DARK_GRAY, no); plot S2 = Round((pivot - (R1 - S1)) / TickSize(), 0) * TickSize(); S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S2.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S2, "S2", Color.DARK_GRAY, yes); plot R3 = Round((prevHigh + (2 * (pivot - prevLow))) / TickSize(), 0) * TickSize(); R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R3.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R3, "R3", Color.DARK_GRAY, no); plot S3 = Round((prevLow - (2 * (prevHigh - pivot))) / TickSize(), 0) * TickSize(); S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S3.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S3, "S3", Color.DARK_GRAY, yes); plot R4 = Round((prevHigh + (3 * (pivot - prevLow))) / TickSize(), 0) * TickSize(); R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R4.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R4, "R4", Color.DARK_GRAY, no); plot S4 = Round((prevLow - (3 * (prevHigh - pivot))) / TickSize(), 0) * TickSize(); S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S4.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S4, "S4", Color.DARK_GRAY, yes); AddLabel(1, "Yesterdays Close = " + last, if close > last then color.green else if close == last then color.cyan else color.red); # Scan examples # If you name this study "Floor_Trader_Pivots_Scan" you can reference the study in the scanner and scan for equities crossing above or below any of the plots using the format below. # close crosses above Floor_Trader_Pivots_Scan()."R1" # End Code Floor Trader Pivots
If you ever need or want a script and can't find it here at UseThinkscript, try https://tinyurl.com/tsCommunity - its a OneNote kept up by Johnny Quotron of the TSL. There's far more codes there than anyone could ever use.
input Timeframe = AggregationPeriod.DAY;
input ShowOnlyToday = YES;
input PlotNextDay = YES;
input price = FundamentalType.CLOSE;
#declare hide_on_daily;
#Cloud Color
defineGlobalColor("Cloud", Color.VIOLET);
def high = high(period = Timeframe);
def low = low(period = Timeframe);
def close = close(period = Timeframe);
plot PP;
plot LOD;
plot HOD;
plot BC;
plot TC;
#RESITANCES / SUPPORTS
plot R1;
plot R2;
plot R3;
plot R4;
plot S1;
plot S2;
plot S3;
plot S4;
if ShowOnlyToday and !IsNaN(close(period = Timeframe)[-2])
then {
PP = Double.NaN;
LOD = Double.NaN;
HOD = Double.NaN;
BC = Double.NaN;
TC = Double.NaN;
# RESISTANCES / SUPPORTS
R1 = Double.NaN;
R2 = Double.NaN;
R3 = Double.NaN;
R4 = Double.NaN;
S1 = Double.NaN;
S2 = Double.NaN;
S3 = Double.NaN;
S4 = Double.NaN;
} else {
PP = (high[1] + low[1] + close[1]) / 3;
LOD = low[1];
HOD = high[1];
BC = (high[1] + low[1]) / 2;
TC = (PP - BC) + PP;
# RESISTANCES / SUPPORTS
R1 = 2 * PP - low[1];
R2 = PP + (high[1] - low[1]);
R3 = R1 + (high[1] - low[1]);
R4 = R3 + (R2 - R1);
S1 = 2 * PP - high[1];
S2 = PP - (high[1] - low[1]);
S3 = S1 - (high[1] - low [1]);
S4 = S3 - (S1 - S2);
}
#PLOT LINES
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LOD.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
HOD.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
BC.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
TC.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
#SUPPORTS / RESISTANCES
R1.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
R3.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
R4.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
S4.setPaintingStrategy(PaintingStrategy.HORIZONTAL);
#ADD COLOR
PP.SetDefaultColor(color = Color.VIOLET);
LOD.SetDefaultColor(color = Color.LIGHT_ORANGE);
HOD.SetDefaultColor(color = Color.LIGHT_ORANGE);
BC.SetDefaultColor(color = Color.VIOLET);
TC.SetDefaultColor(color = Color.VIOLET);
R1.SetDefaultColor(color = Color.GRAY);
R2.SetDefaultColor(color = Color.GRAY);
R3.SetDefaultColor(color = Color.GRAY);
R4.SetDefaultColor(color = Color.GRAY);
S1.SetDefaultColor(color = Color.GRAY);
S2.SetDefaultColor(color = Color.GRAY);
S3.SetDefaultColor(color = Color.GRAY);
S4.SetDefaultColor(color = Color.GRAY);
#CLOUDS
AddCloud(BC, TC, color1 = globalColor("Cloud"), color2 = globalColor("Cloud"));
@GRINKT change the first line of your IF statement to this:
Ruby:if (ShowOnlyToday and !IsNaN(close(period = Timeframe)[-2])) or (!PlotNextDay and IsNaN(close(period = Timeframe)))
Hi, I've enjoyed trying out your script and it works well. I have used and modified a few scripts from here, but I have fairly limited coding ability to be honest. I wonder if you know how to add a label above each pivot line that stays at the far right edge of the window, as shown in the picture I've attached - this is a Ninjatrader script.Appreciate that i was doing or statement inside first if so i couldnt get it to work...
If anyone wants this, here my version of floor pivots - http://tos.mx/HZG74pF
This code is pretty amazing and works great for renko charts as well. If there is a way to get this code to calculate for a set period of days, would be awesome.@KCLLive Haven't looked at your script any, but Mobius of the TSL coded Floor Trader Pivots for ThinkorSwim a decade ago. I'm certainly not trying to dissuade you from continuing your script - I think it very commendable that you are actively trying vs wanting others to do the coding. This may make it easier.
Code:# Floor Traders pivots (can be used in scanner) # Mobius # V01.06.2011 def Today = GetDay() == GetLastDay(); def Yesterday = GetDay() == GetLastDay() - 1; def last = if Today and !Today[1] then close[1] else last[1]; def prevHigh = if YesterDay and !YesterDay[1] then high else if Yesterday and high > prevHigh[1] then high else prevHigh[1]; def prevLow = if Yesterday and !Yesterday[1] then low else if Yesterday and low < prevLow[1] then low else prevLow[1]; def BubbleLocation = !yesterday and yesterday[1]; plot pHigh = prevHigh; pHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pHigh.SetDefaultColor(color.dark_green); AddChartBubble(BubbleLocation, prevHigh, "Prev High", Color.DARK_GRAY, no); plot pLow = prevLow; pLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pLow.SetDefaultColor(color.dark_red); AddChartBubble(BubbleLocation, prevLow, "Prev low", Color.DARK_GRAY, no); plot pivot = (prevHigh + prevLow + last) / 3; pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pivot.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, pivot, "Pivot", Color.DARK_GRAY, no); plot R1 = Round(((2 * pivot) - prevLow) / TickSize(), 0) * TickSize(); R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R1.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R1, "R1", Color.DARK_GRAY, no); plot S1 = Round(((2 * pivot) - prevHigh) / TickSize(), 0) * TickSize(); S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S1.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S1, "S1", Color.DARK_GRAY, yes); plot R2 = Round((pivot + (R1 - S1)) / TickSize(), 0) * TickSize(); R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R2.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R2, "R2", Color.DARK_GRAY, no); plot S2 = Round((pivot - (R1 - S1)) / TickSize(), 0) * TickSize(); S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S2.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S2, "S2", Color.DARK_GRAY, yes); plot R3 = Round((prevHigh + (2 * (pivot - prevLow))) / TickSize(), 0) * TickSize(); R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R3.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R3, "R3", Color.DARK_GRAY, no); plot S3 = Round((prevLow - (2 * (prevHigh - pivot))) / TickSize(), 0) * TickSize(); S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S3.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S3, "S3", Color.DARK_GRAY, yes); plot R4 = Round((prevHigh + (3 * (pivot - prevLow))) / TickSize(), 0) * TickSize(); R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R4.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, R4, "R4", Color.DARK_GRAY, no); plot S4 = Round((prevLow - (3 * (prevHigh - pivot))) / TickSize(), 0) * TickSize(); S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S4.SetDefaultColor(color.dark_gray); AddChartBubble(BubbleLocation, S4, "S4", Color.DARK_GRAY, yes); AddLabel(1, "Yesterdays Close = " + last, if close > last then color.green else if close == last then color.cyan else color.red); # Scan examples # If you name this study "Floor_Trader_Pivots_Scan" you can reference the study in the scanner and scan for equities crossing above or below any of the plots using the format below. # close crosses above Floor_Trader_Pivots_Scan()."R1" # End Code Floor Trader Pivots
This code is pretty amazing and works great for renko charts as well. If there is a way to get this code to calculate for a set period of days, would be awesome.
Can someone pls help me with this?
Code:# Floor Traders pivots (can be used in scanner) # Mobius # V01.06.2011 # modified to allow a number of days back from today to define high/low input back = 1;#hint back:must be >= 1 assert(back>=1, "back must be greater than or equal to 1"); def ymd = GetYYYYMMDD(); def ct = if !IsNaN(close) and ymd != ymd[1] then ct[1] + 1 else ct[1]; def na = Double.NaN; def cond = HighestAll(ct) - ct + 1; #cond.setpaintingStrategy(paintingStrategy.VALUES_BELOW); def last = if cond[1] == 2 and cond == 1 then close[1] else last[1]; def prevHigh = if cond[1] == back + 2 and cond == back + 1 then high else if cond != 1 and high > prevHigh[1] then high else prevHigh[1]; def prevLow = if cond[1] == back + 2 and cond == back + 1 then low else if cond != 1 and low < prevLow[1] then low else prevLow[1]; def BubbleLocation = cond[1] == 2 and cond == 1; plot pHigh = if cond > back + 1 then na else prevHigh; pHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pHigh.SetDefaultColor(Color.DARK_GREEN); AddChartBubble(BubbleLocation, prevHigh, "Prev High", Color.DARK_GRAY, no); plot pLow = if cond > back + 1 then na else prevLow; pLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pLow.SetDefaultColor(Color.DARK_RED); AddChartBubble(BubbleLocation, prevLow, "Prev low", Color.DARK_GRAY, no); plot pivot = (prevHigh + prevLow + last) / 3; pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); pivot.SetDefaultColor(Color.cyan); AddChartBubble(BubbleLocation, pivot, "Pivot", Color.DARK_GRAY, no); plot R1 = Round(((2 * pivot) - prevLow) / TickSize(), 0) * TickSize(); R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R1.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, R1, "R1", Color.DARK_GRAY, no); plot S1 = Round(((2 * pivot) - prevHigh) / TickSize(), 0) * TickSize(); S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S1.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, S1, "S1", Color.DARK_GRAY, yes); plot R2 = Round((pivot + (R1 - S1)) / TickSize(), 0) * TickSize(); R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R2.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, R2, "R2", Color.DARK_GRAY, no); plot S2 = Round((pivot - (R1 - S1)) / TickSize(), 0) * TickSize(); S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S2.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, S2, "S2", Color.DARK_GRAY, yes); plot R3 = Round((prevHigh + (2 * (pivot - prevLow))) / TickSize(), 0) * TickSize(); R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R3.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, R3, "R3", Color.DARK_GRAY, no); plot S3 = Round((prevLow - (2 * (prevHigh - pivot))) / TickSize(), 0) * TickSize(); S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S3.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, S3, "S3", Color.DARK_GRAY, yes); plot R4 = Round((prevHigh + (3 * (pivot - prevLow))) / TickSize(), 0) * TickSize(); R4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); R4.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, R4, "R4", Color.DARK_GRAY, no); plot S4 = Round((prevLow - (3 * (prevHigh - pivot))) / TickSize(), 0) * TickSize(); S4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); S4.SetDefaultColor(Color.DARK_GRAY); AddChartBubble(BubbleLocation, S4, "S4", Color.DARK_GRAY, yes); AddLabel(1, "Yesterdays Close = " + last, if close > last then Color.GREEN else if close == last then Color.CYAN else Color.RED); addlabel(1, "Days Back " + back, color.yellow); # Scan examples # If you name this study "Floor_Trader_Pivots_Scan" you can reference the study in the scanner and scan for equities crossing above or below any of the plots using the format below. #
Thanks a lot SleepyZ. Yoy're my savior. Sometimes its difficult as I am not able to work with thinkscript for its limitations or my ignorance. I've been struggling and working on the code for quite sometime. I was able to code and work for smaller tick renkos, but was causing a lot of issues on some charts. This works amazing on many timeframes. I'll look into this code as well and learn from this. Genius work perhaps !Modified to allow a number of days back from today to define high/low
Input back must be >= 1
Image is a renko 5d 100 ticks set to 2 days back
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.