NexusFi: Find Your Edge


Home Menu

 





ThinkScript Scans


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,803 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 14 posts
    2. attach_file 0 attachments




 
Search this Thread

ThinkScript Scans

  #11 (permalink)
RandomDude
Las Vegas, NV
 
Posts: 66 since Aug 2022
Thanks Given: 2
Thanks Received: 18

First, I am posting as study so you can figure out if it is giving you the open and close that you want. After you load the study, set the PercentageChange parameter to 100, so the Signal plot doesn't give a result. Otherwise your chart might be squished vertically, depending on the instrument.

Note that TOS indexes bars by their start time, not the close time. So the close of 930 bar on a 15 minute chart, will be at 945. As discussed, you will need to indicate the time frame in the scan settings.

Second, it looks like you are in a different time zone, so see line 3 in the code below. You want to edit the 0300 to shift to your time zone. I am PST, so if you are EST, for example, then it should be either 0000 or 0600. Not sure which way you need it to shift, so you will have to play with it.

If satisfactory, you can delete the last 3 lines of the code and put in scan and give it a good workout in OnDemand and/or simulation before going live.

If not what you want, please let me know, will try my best. ;-)

 
Code
input OpenTime = 0930;
input PercentChange = 20;

def OpenShifted = OpenTime + 0300;

#========================================================

rec FirstOpen;
if (FirstOpen[1] == 0) {FirstOpen = first(open());
} else {
if (SecondsTillTime(OpenShifted)) == 0 {
FirstOpen = open(); 
} else {
FirstOpen = FirstOpen[1];
}
}

#========================================================

rec FirstClose;
if (FirstClose[1] == 0) {FirstClose = first(close());
} else {
if (SecondsTillTime(OpenShifted)) == 0 {
FirstClose = close(); 
} else {
FirstClose = FirstClose[1];
}
}

#========================================================

def cond = if (FirstOpen - FirstClose) / FirstOpen > (PercentChange / 100) then 1 else 0;
plot signal= cond;

#========================================================

plot ScanOpen = FirstOpen;
plot ScanClose = FirstClose;

AddVerticalLine((SecondsTillTime(OpenShifted)) == 0 , 5, Color.DARK_GREEN, Curve.FIRM);

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didnt know anythin …
Psychology and Money Management
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
 
  #12 (permalink)
ddtav478
Biloxi Mississippi
 
Posts: 8 since Aug 2022
Thanks Given: 3
Thanks Received: 0


RandomDude View Post
First, I am posting as study so you can figure out if it is giving you the open and close that you want. After you load the study, set the PercentageChange parameter to 100, so the Signal plot doesn't give a result. Otherwise your chart might be squished vertically, depending on the instrument.

Note that TOS indexes bars by their start time, not the close time. So the close of 930 bar on a 15 minute chart, will be at 945. As discussed, you will need to indicate the time frame in the scan settings.

Second, it looks like you are in a different time zone, so see line 3 in the code below. You want to edit the 0300 to shift to your time zone. I am PST, so if you are EST, for example, then it should be either 0000 or 0600. Not sure which way you need it to shift, so you will have to play with it.

If satisfactory, you can delete the last 3 lines of the code and put in scan and give it a good workout in OnDemand and/or simulation before going live.

If not what you want, please let me know, will try my best. ;-)

 
Code
input OpenTime = 0930;
input PercentChange = 20;

def OpenShifted = OpenTime + 0300;

#========================================================

rec FirstOpen;
if (FirstOpen[1] == 0) {FirstOpen = first(open());
} else {
if (SecondsTillTime(OpenShifted)) == 0 {
FirstOpen = open(); 
} else {
FirstOpen = FirstOpen[1];
}
}

#========================================================

rec FirstClose;
if (FirstClose[1] == 0) {FirstClose = first(close());
} else {
if (SecondsTillTime(OpenShifted)) == 0 {
FirstClose = close(); 
} else {
FirstClose = FirstClose[1];
}
}

#========================================================

def cond = if (FirstOpen - FirstClose) / FirstOpen > (PercentChange / 100) then 1 else 0;
plot signal= cond;

#========================================================

plot ScanOpen = FirstOpen;
plot ScanClose = FirstClose;

AddVerticalLine((SecondsTillTime(OpenShifted)) == 0 , 5, Color.DARK_GREEN, Curve.FIRM);

You are awesome! Apologies for getting back to you so late. I'm gonna mess around with this and plug it into a scanner later tonight and tomorrow. I'm only 1hr behind, so no big deal.

Also, question? Does this code particularly scan for any stocks that had a 15min price drop within the last 30 days? Or does it scan for stocks on the day it was initiated?

Reply With Quote
  #13 (permalink)
RandomDude
Las Vegas, NV
 
Posts: 66 since Aug 2022
Thanks Given: 2
Thanks Received: 18


Strictly today. For 30 days, only way I can think would be to create separate formulas for each day and then reference those number of specific periods back within each formula, e.g. close[26], close[52], etc. Would have to think how to do that. Regardless, you will definitely have to do the legwork on that one as that would take some time and be pretty tedious.

That might be something you want to post on thinkscript forum, they may have much better solution than I do.

Reply With Quote
Thanked by:
  #14 (permalink)
ddtav478
Biloxi Mississippi
 
Posts: 8 since Aug 2022
Thanks Given: 3
Thanks Received: 0


RandomDude View Post
Strictly today. For 30 days, only way I can think would be to create separate formulas for each day and then reference those number of specific periods back within each formula, e.g. close[26], close[52], etc. Would have to think how to do that. Regardless, you will definitely have to do the legwork on that one as that would take some time and be pretty tedious.

That might be something you want to post on thinkscript forum, they may have much better solution than I do.

Absolutely! Just looking at it and I see the open and close and what you’re referencing. Again, thank you so much, this really helped me out a ton!

Reply With Quote
  #15 (permalink)
RandomDude
Las Vegas, NV
 
Posts: 66 since Aug 2022
Thanks Given: 2
Thanks Received: 18

In most languages I've learned how to use a "for" statement to this kind of thing, but not available in thinkscript. Maybe another way, but I don't know it.

There is BarNumber(), and believe can use that, but problem being if there are bars missing, this will give erroneous results, and you wouldn't know it unless you validated every scan result...every time. Can't see that being practical.
Not sure how often stocks have missing bars, but I know with futures and currencies it happens often enough. So I don't recommend this approach.

Last is using date and time members, https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Date---Time, and replicating the formula 30 times. But never really used these and so far all ideas have failed. Probably not difficult, but difficult for me.

At this point, I need help. If someone else can chime in or you can find another study that references prior days' intraday bars, then I can look at it.

Reply With Quote




Last Updated on August 29, 2022


© 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