"ShowOnlyToday" Function

Gvaro

New member
Hi! I need to add a "showonlytoday" function to this study below, because I would like to see previous days signals. Can someone help me add the code? Thanks.
https://usethinkscript.com/threads/moxie-indicator-for-thinkorswim.369/page-11#post-57574
Code:
#Robert Payne   06/17/2014
#Public Domain


#This script will calculate and plot the stop loss and first profit target when the stock breaks out above the previous day's high or opening range high (whichever is higher) or vice versa to the low-side. This may be used with a 2 min chart as he described in his original post for a more aggressive entry point, or, as he recommended to me, on a 5 min chart for a more conservative entry point.

#---------------------------------------------------------------------------------------------

script OpenRange {
    input ORtime = 5;

    def FirstBar = GetDay() != GetDay()[1];
    def RangeTime = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime;
    def Rhigh = if FirstBar then high else if RangeTime and high > Rhigh[1] then high else Rhigh[1];
    def Rlow = if FirstBar then low else if RangeTime and low < Rlow[1] then low else Rlow[1];

    plot h = if RangeTime then Double.NaN else Rhigh;
    plot l = if RangeTime then Double.NaN else Rlow;
}

def first30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) >= 0;
def today = GetLastDay() == GetDay();
def ATR = Average(TrueRange(high,  close,  low),  10);

plot yHigh = if !today then Double.NaN else high(period = "day" )[1];
yHigh.SetDefaultColor(Color.CYAN);
plot yLow = if !today then Double.NaN else low(period = "day" )[1];
yLow.SetDefaultColor(Color.PINK);

plot h5 = if !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).h;
h5.SetDefaultColor(Color.YELLOW);
plot l5 = if !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).l;
l5.SetDefaultColor(Color.YELLOW);
plot h30 = if !today then Double.NaN else OpenRange(30).h;
h30.SetDefaultColor(Color.YELLOW);
plot l30 = if !today then Double.NaN else OpenRange(30).l;
l30.SetDefaultColor(Color.YELLOW);

def lowConf = if first30 then Min(yLow, l5) - ATR else Min(yLow, l30) - ATR;
def highConf = if first30 then Max(yHigh, h5) + ATR else Max(yHigh, h30) + ATR;

plot lc1 = if first30 then lowConf else Double.NaN;
lc1.SetDefaultColor(Color.ORANGE);
plot lc2 = if !first30 then lowConf else Double.NaN;
lc2.SetDefaultColor(Color.ORANGE);
plot hc1 = if first30 then highConf else Double.NaN;
hc1.SetDefaultColor(Color.ORANGE);
plot hc2 = if !first30 then highConf else Double.NaN;
hc2.SetDefaultColor(Color.ORANGE);

def decisionL = if close > lowConf then Double.NaN else if close crosses below lowConf then low else decisionL[1];
def decisionH = if close < highConf then Double.NaN else if close crosses above highConf then high else decisionH[1];

plot dL = if !today then Double.NaN else decisionL;
dL.SetDefaultColor(Color.WHITE);
plot dH = if !today then Double.NaN else decisionH;
dH.SetDefaultColor(Color.WHITE);

def TL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(TL[1]) then TL[1] else if close crosses below dL then dL - 2 * ATR else Double.NaN, Double.NaN);
def SL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(SL[1]) then SL[1] else if close crosses below dL then dL + 2 * ATR else Double.NaN, Double.NaN);

plot Target1Low = if !today then Double.NaN else TL;
Target1Low.SetDefaultColor(Color.GREEN);
Target1Low.SetStyle(Curve.SHORT_DASH);
plot Stop1Low = if !today then Double.NaN else SL;
Stop1Low.SetDefaultColor(Color.RED);
Stop1Low.SetLineWeight(2);

AddChartBubble(IsNaN(TL[1]) and !IsNaN(TL), TL, "Target 1\n" + Round(TL, 2), Color.GREEN, no);
AddChartBubble(IsNaN(SL[1]) and !IsNaN(SL), SL, "Stop\n" + Round(SL, 2), Color.RED);

def TH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(TH[1]) then TH[1] else if close crosses above dH then dH + 2 * ATR else Double.NaN, Double.NaN);
def SH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(SH[1]) then SH[1] else if close crosses above dH then dH - 2 * ATR else Double.NaN, Double.NaN);

plot Target1High = if !today then Double.NaN else TH;
Target1High.SetDefaultColor(Color.GREEN);
Target1High.SetStyle(Curve.SHORT_DASH);
plot Stop1High = if !today then Double.NaN else SH;
Stop1High.SetDefaultColor(Color.RED);
Stop1High.SetLineWeight(2);

AddChartBubble(IsNaN(TH[1]) and !IsNaN(TH), TH, "Target 1\n" + Round(TH, 2), Color.GREEN);
AddChartBubble(IsNaN(SH[1]) and !IsNaN(SH), SH, "Stop\n" + Round(SH, 2), Color.RED, no);


def alertup = close[1] crosses above hc1 or close[1] crosses above hc2;
def alertdn = close[1] crosses below lc1 or close[1] crosses below lc2;
alert(alertup, getsymbol() + " UP", alert.bar, sound.bell);
[QUOTE]
alert(alertdn, getsymbol() + " DOWN", alert.bar, sound.bell);
[/QUOTE]
 
Last edited by a moderator:
Thanks for your help! I tried that formula before but it keeps showing the current day only.

The following script has an input showtodayonly. The image shows it set to NO and displays all the data for all of the days on the chart. Set the input showtodayonly will show just the current day's data.

Capture.jpg
Ruby:
#Robert Payne   06/17/2014
#Public Domain


#This script will calculate and plot the stop loss and first profit target when the stock breaks out above the previous day's high or opening range high (whichever is higher) or vice versa to the low-side. This may be used with a 2 min chart as he described in his original post for a more aggressive entry point, or, as he recommended to me, on a 5 min chart for a more conservative entry point.

#---------------------------------------------------------------------------------------------

script OpenRange {
    input ORtime = 5;

    def FirstBar = GetDay() != GetDay()[1];
    def RangeTime = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime;
    def Rhigh = if FirstBar then high else if RangeTime and high > Rhigh[1] then high else Rhigh[1];
    def Rlow = if FirstBar then low else if RangeTime and low < Rlow[1] then low else Rlow[1];

    plot h = if RangeTime then Double.NaN else Rhigh;
    plot l = if RangeTime then Double.NaN else Rlow;
}

input showtodayonly = no;
def first30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) >= 0;
def today = GetLastDay() == GetDay();
def ATR = Average(TrueRange(high,  close,  low),  10);

plot yHigh = if showtodayonly and !today then Double.NaN else high(period = "day" )[1];
yHigh.SetDefaultColor(Color.CYAN);
plot yLow = if showtodayonly and  !today then Double.NaN else low(period = "day" )[1];
yLow.SetDefaultColor(Color.PINK);

plot h5 = if showtodayonly and  !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).h;
h5.SetDefaultColor(Color.YELLOW);
plot l5 = if showtodayonly and  !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).l;
l5.SetDefaultColor(Color.YELLOW);
plot h30 = if showtodayonly and  !today then Double.NaN else OpenRange(30).h;
h30.SetDefaultColor(Color.YELLOW);
plot l30 = if showtodayonly and  !today then Double.NaN else OpenRange(30).l;
l30.SetDefaultColor(Color.YELLOW);

def lowConf = if first30 then Min(yLow, l5) - ATR else Min(yLow, l30) - ATR;
def highConf = if first30 then Max(yHigh, h5) + ATR else Max(yHigh, h30) + ATR;

plot lc1 = if first30 then lowConf else Double.NaN;
lc1.SetDefaultColor(Color.ORANGE);
plot lc2 = if !first30 then lowConf else Double.NaN;
lc2.SetDefaultColor(Color.ORANGE);
plot hc1 = if first30 then highConf else Double.NaN;
hc1.SetDefaultColor(Color.ORANGE);
plot hc2 = if !first30 then highConf else Double.NaN;
hc2.SetDefaultColor(Color.ORANGE);

def decisionL = if close > lowConf then Double.NaN else if close crosses below lowConf then low else decisionL[1];
def decisionH = if close < highConf then Double.NaN else if close crosses above highConf then high else decisionH[1];

plot dL = if showtodayonly and  !today then Double.NaN else decisionL;
dL.SetDefaultColor(Color.WHITE);
plot dH = if showtodayonly and  !today then Double.NaN else decisionH;
dH.SetDefaultColor(Color.WHITE);

def TL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(TL[1]) then TL[1] else if close crosses below dL then dL - 2 * ATR else Double.NaN, Double.NaN);
def SL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(SL[1]) then SL[1] else if close crosses below dL then dL + 2 * ATR else Double.NaN, Double.NaN);

plot Target1Low = if showtodayonly and  !today then Double.NaN else TL;
Target1Low.SetDefaultColor(Color.GREEN);
Target1Low.SetStyle(Curve.SHORT_DASH);
plot Stop1Low = if showtodayonly and  !today then Double.NaN else SL;
Stop1Low.SetDefaultColor(Color.RED);
Stop1Low.SetLineWeight(2);

AddChartBubble(IsNaN(TL[1]) and !IsNaN(TL), TL, "Target 1\n" + Round(TL, 2), Color.GREEN, no);
AddChartBubble(IsNaN(SL[1]) and !IsNaN(SL), SL, "Stop\n" + Round(SL, 2), Color.RED);

def TH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(TH[1]) then TH[1] else if close crosses above dH then dH + 2 * ATR else Double.NaN, Double.NaN);
def SH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(SH[1]) then SH[1] else if close crosses above dH then dH - 2 * ATR else Double.NaN, Double.NaN);

plot Target1High = if showtodayonly and  !today then Double.NaN else TH;
Target1High.SetDefaultColor(Color.GREEN);
Target1High.SetStyle(Curve.SHORT_DASH);
plot Stop1High = if showtodayonly and  !today then Double.NaN else SH;
Stop1High.SetDefaultColor(Color.RED);
Stop1High.SetLineWeight(2);

AddChartBubble(IsNaN(TH[1]) and !IsNaN(TH), TH, "Target 1\n" + Round(TH, 2), Color.GREEN);
AddChartBubble(IsNaN(SH[1]) and !IsNaN(SH), SH, "Stop\n" + Round(SH, 2), Color.RED, no);


def alertup = close[1] crosses above hc1 or close[1] crosses above hc2;
def alertdn = close[1] crosses below lc1 or close[1] crosses below lc2;
Alert(alertup, GetSymbol() + " UP", Alert.BAR, Sound.Bell);
Alert(alertdn, GetSymbol() + " DOWN", Alert.BAR, Sound.Bell);
 
Thanks for your help! I tried that formula before but it keeps showing the current day only.
that's just part of the answer.
to display shapes on a chart,
1. you need to define the bars,
2. and define the data.

with that formula in post #2, you will be able to do step 1, define the bars , on just the current day, like you wanted.

next you need to define the data. you want previous days signals. so some kind of offset will need to be used, on some variables, in order to read historic data. but , i don't know what data you want to see on todays bars. 'previous days signals ' is too vague. there are 16 plots, bubbles, and alerts in that study.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
500 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top