Horizontal line with conditions. - futures io
futures io



Horizontal line with conditions.


Discussion in ThinkOrSwim

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Horizontal line with conditions.

(login for full post details)
  #1 (permalink)
TRSQ
Montpellier
 
 
Posts: 5 since Apr 2021
Thanks: 3 given, 0 received

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

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(385 thanks from 40 posts)
looks_twoSalao's Journalby Salao
(85 thanks from 14 posts)
looks_3Learning to Profit - A journey in algorithms and optionsby Syntax
(59 thanks from 18 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(51 thanks from 23 posts)
looks_5Maybe a little bit different journalby Malykubo
(37 thanks from 23 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
The Crude Dude Oil Trading System
100 thanks
futures io site changelog and issues/problem reporting
33 thanks
Seasonal Trades
26 thanks
Help improve the FIO community
26 thanks
Spoo-nalysis ES e-mini futures S&P 500
22 thanks
 
(login for full post details)
  #2 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
 
Posts: 50 since Mar 2019
Thanks: 5 given, 37 received

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
The following user says Thank You to JayC for this post:
 
(login for full post details)
  #3 (permalink)
TRSQ
Montpellier
 
 
Posts: 5 since Apr 2021
Thanks: 3 given, 0 received


Thank you!! you also added the label that shows percentage gap in the day!!! that's awesome!

Reply With Quote
 
(login for full post details)
  #4 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
 
Posts: 50 since Mar 2019
Thanks: 5 given, 37 received

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
The following user says Thank You to JayC for this post:
 
(login for full post details)
  #5 (permalink)
TRSQ
Montpellier
 
 
Posts: 5 since Apr 2021
Thanks: 3 given, 0 received

Wow nice seems really a good tool! yeah im really interested in gaps and volume.

Reply With Quote


futures io Trading Community Platforms and Indicators ThinkOrSwim > Horizontal line with conditions.


Last Updated on April 11, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1,800 in prizes!

April

An Introduction to CME Group Micro Bitcoin Futures w/David Lerman

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts