NexusFi: Find Your Edge


Home Menu

 





Horizontal line with conditions.


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,473 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread

Horizontal line with conditions.

  #1 (permalink)
TRSQ
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);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
Bigger Wins or Fewer Losses?
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #2 (permalink)
 JayC 
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);

Reply With Quote
Thanked by:
  #3 (permalink)
TRSQ
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!

Reply With Quote
  #4 (permalink)
 JayC 
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);

Reply With Quote
Thanked by:
  #5 (permalink)
TRSQ
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.

Reply With Quote




Last Updated on April 11, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts