Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Horizontal line with conditions.
Updated April 11, 2021
trending_up
2,473 views
thumb_up
2 thanks given
group
2 followers
forum
4 posts
attach_file
1 attachments
Horizontal line with conditions.
April 8th, 2021, 09:24 AM
Montpellier
Posts: 6 since Apr 2021
Thanks Given: 3
Thanks Received: 0
Hello,
I'm really new to build a script for thinkorswim .
Recently i've made this script but i'd like to put some condition on it.
1: i want it to show horzontal line only if the gap criteria. ( is above 10% or 30% for example).
def a = Open(period = AggregationPeriod.DAY);
def b = 1.2;
def c = 1.3;
plot push1 = a * b;
plot push2 = a * c;
push1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
push2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
April 8th, 2021, 01:47 PM
San Diego, CA
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43
The main idea is to add conditions to the plot lines and return Double.NaN when you don't want lines. Here's an example with your gap requirements.
Hope this helps,
Jay
Code
input minGap = 10;
def a = Open(period = AggregationPeriod.DAY);
def b = 1.2;
def c = 1.3;
def prevClose = close(period = AggregationPeriod.DAY)[1];
def gapPct = Round((a / prevClose - 1) * 100, numberOfDigits = 2);
def day = getDay();
def lastDay = getLastDay();
def isToday = if(day == lastDay, 1, 0);
plot push1 = if isToday and gapPct >= minGap then a * b else Double.NaN;
plot push2 = if isToday and gapPct >= minGap then a * c else Double.NaN;
push1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
push2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
AddLabel(yes, "GapPct: " + gapPct, Color.CYAN);
April 8th, 2021, 05:26 PM
Montpellier
Posts: 6 since Apr 2021
Thanks Given: 3
Thanks Received: 0
Thank you!! you also added the label that shows percentage gap in the day!!! that's awesome!
April 9th, 2021, 01:59 PM
San Diego, CA
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43
If gaps interest you, try this on a daily chart. It marks every gap greater than a percentage, and determines if it closed the gap or went higher. For this study, I used the previous high to find the gaps rather than previous close. It also aggregates the results of the chart in the label. Not sure if there's any edge here, but may be useful if you are studying gaps.
Code
input gap = 5.0;
input minVolume = 500000;
def todayHigh = high( period = AggregationPeriod.DAY);
def todayLow = low( period = AggregationPeriod.DAY);
def dailyOpen = open(period = AggregationPeriod.DAY);
def todayClose = close(period = AggregationPeriod.DAY);
def prevClose = close(period = AggregationPeriod.DAY)[1];
def newDay = GetYYYYMMDD() != GetYYYYMMDD()[1];
def dailyVol = volume(period = AggregationPeriod.DAY);
#gap calc
def gapPct = Round((dailyOpen - todayHigh[1]) / todayHigh[1] * 100, numberOfDigits = 0);
def minVolReached = dailyVol > minVolume;
def gapCondition = gapPct > gap and newDay and minVolReached;
def gapCount = if gapCondition then 1 + gapCount[1] else gapCount[1];
def totalGapVolume = if gapCondition then totalGapVolume[1] + dailyVol else totalGapVolume[1];
def avgGapVol = Round(totalGapVolume / gapCount, 0);
def closedHigher = if gapCondition and todayClose > dailyOpen then 1 else 0;
def closedGap = if gapCondition and todayLow <= todayHigh[1] then 1 else 0;
def openPeak = todayHigh - dailyOpen;
def closedGapTotal = if closedGap then 1 + closedGapTotal[1] else closedGapTotal[1];
def closedHigherTotal = if closedHigher then 1 + closedHigherTotal[1] else closedHigherTotal[1];
#display
AddLabel(visible = yes, text =
"Gap Ups > " + gap +
"%: " + gapCount +
", Closed Gap: " + closedGapTotal +
", Closed Higher: " + closedHigherTotal +
", AvgGapVol: " + avgGapVol
, Color.CYAN);
#produces a date label in MMDDYYYY format
def Year = (Round(GetYYYYMMDD() / 10000, 0));#This produces the year as1,210
def Month = GetMonth();
def Day = GetDayOfMonth(GetYYYYMMDD());
#mmm, bubbles
AddChartBubble(gapCondition, high,
"Date: " + Month + "/" + Day + "/" + AsPrice(Year) +
"\nGap: (" + gapPct + "%)" +
"\nVolume: " + dailyVol +
"\nOpen Peak: " + openPeak +
"\nClose: " + todayClose +
"\nPrevClose: " + prevClose +
"\nOpen: " + dailyOpen +
"\nClosed Higher: " + (if closedHigher then "Yes" else "No") +
"\nClosed Gap: " + (if closedGap then "Yes" else "No")
, Color.CYAN, yes);
April 11th, 2021, 08:15 AM
Montpellier
Posts: 6 since Apr 2021
Thanks Given: 3
Thanks Received: 0
Wow nice seems really a good tool! yeah im really interested in gaps and volume.
Last Updated on April 11, 2021