Shadow Trader Pivots

Chuck

Moderator
Staff member
5aJyx4S.png

Code:
# Shadow Trader Pivots
# Mobius
# V01.9.2011
#hintconfused smileyhadow Trader Pivots: Take all values from previous intraday market with close taken from the final close value. Settelment Value my differ slightly. POC with dashed line is the previous days point of control and the one Shadow Trader refers to. Volume profile is visible for the past 5 trading days. Pivots are plotted during Market Hours.

# PIVOT = (High + Close + Low)/3 (Values taken from intradays Market)
# R4 = High + 3 x (Pivot - Low)
# R3 = High + 2(Pivot – Low)
# R2 = Pivot + (R1 – S1)
# R1 = (2*Pivot) – Low
# S1 = (2*Pivot) – High
# S2 = Pivot – (R1 – S1)
# S3 = Low – 2(Hi – Pivot)
# S4 = Low - 3 x (High - Pivot)

declare hide_on_daily;

input MktOpen  = 0930; #hint MktOpen: Cash Marekt open EST.
input MktClose = 1600; #hint MktClose: Cash Market close EST.   

def h = high;
def l = low;
def c = close;
def Active = if SecondsFromTime(MktOpen) >= 0 and
                SecondsTillTime(MktClose) >= 0
             then 1
             else 0;
def Today = GetDay() == GetLastDay();
def Yesterday = GetDay() == GetLastDay()-1;
def ap = AggregationPeriod.Day;
def last = if Yesterday and !last[1]
           then close(period = ap)[1]
           else if Yesterday and
              SecondsTillTime(MktClose) == 0 and
              SecondsFromTime(MktClose) == 0
              then if c <> last[1]
                   then c
                   else last[1]
              else last[1];
def prevHigh = if Yesterday and !prevHigh[1]
               then high(period = ap)[1]
               else if Yesterday and Active and !Active[1]
               then h
               else if Yesterday and Active and h > prevHigh[1]
                    then h
               else prevHigh[1];
#addLabel(1, "prevHigh " + prevHigh);
def prevLow = if Yesterday and !prevLow[1]
              then low(period = ap)[1]
              else if Yesterday and Active and !Active[1]
               then l
               else if Yesterday and Active and l < prevLow[1]
                    then l
               else prevLow[1];
def BubbleLocation = if Today and Active and !Active[1]
                     then c
                     else double.nan;
plot LastClose = if Today and Active then last else Double.NaN;
LastClose.SetStyle(curve.short_dash);
LastClose.SetDefaultColor(Color.WHITE);
#AddLabel(1, "Yest Close " + LastClose);
AddChartBubble(BubbleLocation, LastClose, "C", Color.Dark_Gray, no);
plot pivot = Round(((LastClose + prevHigh + prevLow) / 3) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, (pivot), "Pivot", Color.Dark_Gray, yes);
plot R1 = Round(((2 * pivot) - prevLow) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(R1), "R1", Color.Dark_Gray, no);
plot S1 = Round(((2 * pivot) - prevHigh) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(S1), "S1", Color.Dark_Gray, yes);
plot R2 = Round((pivot + (R1 - S1)) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(R2), "R2", Color.Dark_Gray, no);
plot S2 = Round((pivot - (R1 - S1)) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(S2), "S2", Color.Dark_Gray, yes);
plot R3 = Round((prevHigh + (2 * (pivot - prevLow))) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(R3), "R3", Color.Dark_Gray, no);
plot S3 = Round((prevLow - (2 * (prevHigh - pivot))) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(S3), "S3", Color.Dark_Gray, yes);
plot R4 = Round((prevHigh + (3 * (pivot - prevLow))) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(R4), "R4", Color.Dark_Gray, no);
plot S4 = Round((prevLow - (3 * (prevHigh - pivot))) / TickSize(), 0) * TickSize();
AddChartBubble(BubbleLocation, HighestAll(S4), "S4", Color.Dark_Gray, yes);
pivot.SetPaintingStrategy(PaintingStrategy.DASHES);
pivot.SetDefaultColor(Color.Dark_Orange);
pivot.SetLineWeight(1);
R1.SetPaintingStrategy(PaintingStrategy.DASHES);
R1.SetDefaultColor(Color.GREEN);
R1.SetLineWeight(1);
R2.SetPaintingStrategy(PaintingStrategy.DASHES);
R2.SetDefaultColor(Color.GREEN);
R2.SetLineWeight(1);
R3.SetPaintingStrategy(PaintingStrategy.DASHES);
R3.SetDefaultColor(Color.GREEN);
R3.SetLineWeight(1);
R4.SetPaintingStrategy(PaintingStrategy.DASHES);
R4.SetDefaultColor(Color.GREEN);
R4.SetLineWeight(1);
S1.SetPaintingStrategy(PaintingStrategy.DASHES);
S1.SetDefaultColor(Color.RED);
S1.SetLineWeight(1);
S2.SetPaintingStrategy(PaintingStrategy.DASHES);
S2.SetDefaultColor(Color.RED);
S2.SetLineWeight(1);
S3.SetPaintingStrategy(PaintingStrategy.DASHES);
S3.SetDefaultColor(Color.RED);
S3.SetLineWeight(1);
S4.SetPaintingStrategy(PaintingStrategy.DASHES);
S4.SetDefaultColor(Color.RED);
S4.SetLineWeight(1);
def AvgVolume = Average(volume(period = AggregationPeriod.Day), 21);
addLabel(1, volume(period = AggregationPeriod.Day),
         if volume(period = AggregationPeriod.Day) > AvgVolume
         then color.green
         else color.white);
# End Code Shadow Trader Pivots
## VolumeProfile_RTH and Overnight
# Previous POC Extended to Current Day

def bar = BarNumber();
def RTHBar1 = if SecondsFromTime(MktOpen) == 0 and
                 SecondsTillTime(MktOpen) == 0
              then bar
              else RTHBar1[1];
def RTHBarEnd = if SecondsFromTime(MktClose) == 0 and
                   SecondsTillTime(MktClose) == 0
                then 1
                else Double.NaN;
def cond = bar == RTHBar1; #Active != Active[1];
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = 10, "pricePerRow" = PricePerRow.TICKSIZE, "value area percent" = 68.4);
def pc = if IsNaN(vol.GetPointOfControl())
         then pc[1]
         else vol.GetPointOfControl();
def hVA = if IsNaN(vol.GetHighestValueArea())
          then hVA[1]
          else vol.GetHighestValueArea();
def lVA = if IsNaN(vol.GetLowestValueArea())
          then lVA[1]
          else vol.GetLowestValueArea();
def hProfile = if IsNaN(vol.GetHighest())# and con
               then hProfile[1]
               else vol.GetHighest();
def lProfile = if IsNaN(vol.GetLowest())# and con
               then lProfile[1]
               else vol.GetLowest();
def POC = if Active then pc else Double.NaN;
def VAHigh = if Active then hVA else Double.NaN;
def VALow = if Active then lVA else Double.NaN;
def PrevPC = if !IsNaN(RTHBarEnd)
            then POC[1]
            else PrevPC[1];
def PrevPCBar = if !IsNaN(RTHBarEnd)
               then bar
               else PrevPCBar[1];
def PrevPC_Limit = if bar == PrevPCBar
                  then Double.NaN
                  else if bar > PrevPCBar
                       then bar - PrevPCBar
                       else PrevPC_Limit[1];
def PrevVAH = if !IsNaN(RTHBarEnd)
            then VAHigh[1]
            else PrevVAH[1];
def PrevVAHBar = if !IsNaN(RTHBarEnd)
               then bar
               else PrevVAHBar[1];
def PrevVAH_Limit = if bar == PrevVAHBar
                  then Double.NaN
                  else if bar > PrevVAHBar
                       then bar - PrevVAHBar
                       else PrevVAH_Limit[1];
def PrevVAL = if !IsNaN(RTHBarEnd)
            then VALow[1]
            else PrevVAL[1];
def PrevVALBar = if !IsNaN(RTHBarEnd)
               then bar
               else PrevVALBar[1];
def PrevVAL_Limit = if bar == PrevVALBar
                  then Double.NaN
                  else if bar > PrevVALBar
                       then bar - PrevVALBar
                       else PrevVAL_Limit[1];
script LinePlot {
    input LineLimit = 0;
    input OnExpansion = yes;
    input data = close;
    input bar = 0;
    def ThisBar = HighestAll(bar);
    def cLine = if bar == ThisBar
                then data
                else Double.NaN;
    def cond1 = CompoundValue(1, if IsNaN(data)
                                 then cond1[1]
                                 else data, data);
    plot P = if ThisBar - LineLimit <= bar
             then HighestAll(cLine)
             else Double.NaN;
    plot ExpLine = if OnExpansion and
                     IsNaN(data[-1])
                   then cond1
                   else Double.NaN;
}
plot PrevPOC = LinePlot(data = PrevPC, LineLimit = PrevPC_Limit, OnExpansion = no, bar = PrevPCBar).P;
PrevPOC.SetDefaultColor(Color.RED);
PrevPOC.SetDefaultColor(Color.RED);
plot PrevVAHline = LinePlot(data = PrevVAH, LineLimit = PrevVAH_Limit, OnExpansion = no, bar = PrevVAHBar).P;
PrevVAHline.SetDefaultColor(Color.RED);
PrevVAHline.SetDefaultColor(Color.RED);
plot PrevVALline = LinePlot(data = PrevVAL, LineLimit = PrevVAL_Limit, OnExpansion = no, bar = PrevVALBar).P;
PrevVALline.SetDefaultColor(Color.RED);
PrevVALline.SetDefaultColor(Color.RED);
addCloud(PrevVALline, PrevVAHline, color.dark_Gray, Color.dark_Gray);
input bubbles = yes;
def n = 2;
def n1 = n + 1;
AddChartBubble(bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), PrevVAH[n1], "VAH", color = Color.YELLOW, yes);
AddChartBubble(bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), PrevVAL[n1], "VAL", Color.YELLOW, no);
AddChartBubble(bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), PrevPOC[n1], "POC", Color.RED, no);
# End POC and Value Area
 
Last edited:

MikeK

New member
Hey @Chuck I get this when I try to load it.
Identifier Already Used: Can not add input: MktOpen at 206:7
Identifier Already Used: MktOpen at 206:7
Identifier Already Used: Can not add input: MktClose at 207:7
Identifier Already Used: MktClose at 207:7
Identifier Already Used: h at 209:5
Identifier Already Used: l at 210:5
Identifier Already Used: c at 211:5
Identifier Already Used: Active at 212:5
Identifier Already Used: Today at 216:5
Identifier Already Used: Yesterday at 217:5
Identifier Already Used: ap at 218:5
Identifier Already Used: last at 219:5
Identifier Already Used: prevHigh at 228:5
Identifier Already Used: prevLow at 235:5
Identifier Already Used: BubbleLocation at 242:5
Identifier Already Used: LastClose at 245:6
Identifier Already Used: pivot at 249:6
Identifier Already Used: R1 at 251:6
Identifier Already Used: S1 at 253:6
Identifier Already Used: R2 at 255:6
 
Last edited by a moderator:

Chuck

Moderator
Staff member
I’m not a psychiatrist, but that is a different version of the same basic study.
 
Top