Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Fun with ThinkScript
September 17, 2017 10:27AM
Hi,

I recently got in to trading and using ToS. I am new to Thinkscript. Great many scripts from Robert and others in this thread. Good opportunity to learn. Thanks for sharing them here.

Have a question. I am trying to write script to read volume and compare against average volume across a specified period. I know how to read that. How can I read the color (red or green) of the bar?

Thanks in advance for your help.

Thanks,
Pravin
Re: Fun with ThinkScript
September 23, 2017 01:15PM
Hello! These are questions from a total newbie!

1. Does the code below automatically start at the beginning of the day, or does it consider the 389 bars from yesterday when calculating the first minute ratio?

def GreenCandle = Close>Close[1];
def RedCandle = Close<Close[1];
def UpVolume = if GreenCandle then Volume else 0;
def GreenVolume = SUM(UpVolume, 390);
def DownVolume = if RedCandle then Volume else 0;
def RedVolume = SUM(DownVolume, 390);

Plot ratio = GreenVolume[0]/RedVolume[0]-1;

2. If it doesn't start automatically at the beginning of the day, how would I go about adjusting it to start at 930AM?

Would greatly appreciate the experts' help with these questions!

Thank you v much!
Re: Fun with ThinkScript
September 23, 2017 09:49PM
OK! Per my earlier post, I have determined that I am definitely referencing yesterday's bars! So, Question #1 has been answered (by myself).

As for question #2, it is a burning question that will make my life a whole lot easier if a kind person could please let me know? Here is a simpler code that I wish to calculate using only today's bars:

plot Data = volume[1]/average(volume,390)-1;

In other words, I am trying to see what % higher or lower is the last minute's volume than the average minute volume for that particular day....

Would greatly appreciate any help,
Re: Fun with ThinkScript
September 24, 2017 08:28AM
Hello again, I came up with a rather blunt solution, but now I am getting the following error:

"com.devexperts.tos.thinkscript.runtime.TooComplexException: The complexity of the expression suggests it may not be reliable with real-time data.”

Here is my inelegant code below. Would greatly appreciate any advice on how to make this a lot simpler!

def value = if(secondstilltime(0932)<=60,if(secondstilltime(0932)>0,volume/average(volume,2)-1,0),0);
def value2 = if(secondstilltime(0933)<=60,if(secondstilltime(0933)>0,volume/average(volume,3)-1,0),0);
def value3 = if(secondstilltime(0934)<=60,if(secondstilltime(0934)>0,volume/average(volume,4)-1,0),0);
[etc]

plot dot=value+value2+value3+...+value389;
Re: Fun with ThinkScript
September 24, 2017 09:17AM
Hey, must have been the almond chocolates, I finally got a boost of brain cells, I think!

def relevantcandle = barnumber()>=1;
def relevantvolume = if relevantcandle then volume else 0;
def sumvolume = sum(relevantvolume,390);
plot dot = volume/(sumvolume/barnumber())-1;

Seemed to work.... let's see.... If yes, then I just need to apply this somehow to the red candle green candle formula...

Will keep you posted!
Re: Fun with ThinkScript
September 24, 2017 10:02AM
Ah well, think it may just be this:

def GreenCandle = Close>Close[1] and barnumber()>=1;
def RedCandle = Close<Close[1] and barnumber()>=1;
def UpVolume = if GreenCandle then Volume else 0;
def GreenVolume = SUM(UpVolume, 390);
def DownVolume = if RedCandle then Volume else 0;
def RedVolume = SUM(DownVolume, 390);

Plot ratio = GreenVolume[0]/RedVolume[0]-1;

Enough already, time to wake up over pints on Sukhumvit 33/1.....

This is Mick signing off from Bangers! โชคดีและหาเงิน! Lots of it
Re: Fun with ThinkScript
September 24, 2017 08:57PM
Hi. This is an awesome indicator combining many of the indicators I already use; thanks for sharing it! I wonder if it is possible to change the length for the squeeze from the preset of 20? I would like to alter it to 14.
Re: Fun with ThinkScript
September 26, 2017 06:53AM
I am a thinkscript newbie. want to find total number of earnings on the chart. Below is my code, no error message, but label is not showing on the chart.

def earningCount = if IsNaN(earningCount) then 0 else if hasEarnings() then earningCount + 1 else earningCount;
    AddLabel(yes, "There are total " + earningCount  + " earnings"winking smiley;
Re: Fun with ThinkScript
September 28, 2017 03:00AM
How to put Daily Ichimoku levels on a 1-minute chart:

I use the 7-22-44 calculations.

input agg = AggregationPeriod.DAY;
input h = FundamentalType.HIGH;
input l = FundamentalType.LOW;
input tPeriod = 7;

def htenkan = highest(Fundamental(h, period = agg), tPeriod);
def ltenkan = lowest(Fundamental(l, period = agg), tPeriod);
plot tenkan = (htenkan+ltenkan)/2;

input kPeriod=22;
def hkijun = highest(Fundamental(h, period = agg), kPeriod);
def lkijun = lowest(Fundamental(l, period = agg), kPeriod);
plot kijun = (hkijun+lkijun)/2;

def Atenkan=(htenkan[22]+ltenkan[22])/2;
def Akijun=(hkijun[22]+lkijun[22])/2;
plot SpanA=(Atenkan+Akijun)/2;

input bPeriod=44;
def bhigh=highest(Fundamental(h,period=agg),bPeriod)[22];
def blow=lowest(Fundamental(l,period=agg),bPeriod)[22];
plot SpanB=(bhigh+blow)/2;

AddCloud(SpanA,SpanB,color.YELLOW,color.PINK);
Re: Fun with ThinkScript
September 29, 2017 11:56AM
There has to be an easier way to track entry price in TOS strategies, as well as FPL & trade statistics.
Does anyone have any insight to this?

I would love some help, if possible.
Re: Close of the highest volume bar
October 04, 2017 03:19AM
Hi Robert

Wonder if you or somebody can help me with this,in a 5 min chart, I need to get the closing price of the bar which has the highest volume in the interval 0930 to 11 am. Of course, it would happen that that close will change with time if a new highest volume bar appears...

Thanks
Rigel

------------------------------------------------------------------------------------------------------------------------------------------------



Any idea with this?

Thanks
rigel



Edited 1 time(s). Last edit at 10/04/2017 03:21AM by rigel.
Re: Close of the highest volume bar
October 09, 2017 01:02PM
rigel Wrote:
-------------------------------------------------------
> Hi Robert
>
> Wonder if you or somebody can help me with this,in
> a 5 min chart, I need to get the closing price of
> the bar which has the highest volume in the
> interval 0930 to 11 am. Of course, it would happen
> that that close will change with time if a new
> highest volume bar appears...
>
> Thanks
> Rigel
>
> --------------------------------------------------
> --------------------------------------------------
> --------------------------------------------
>
>
>
> Any idea with this?
>
> Thanks
> rigel


Rigel -

This will get you what you need, but the highest volume candle is always gonna be in the first 5-15 minutes of the session.
Also, not sure how long you wanna retain this information.... so, this gets it for 150 bars, so basically EOD.


input start = 0930;
input end = 1100;
input Length = 150;


def IsActive = if secondsfromTime(start) > 0 && secondstillTime(end) > 0 then 1 else 0;

def HighVol = if IsActive then highest(volume, Length) else HighVol[1];
addlabel(yes, HighVol);

def HighBar = if HighVol[1] < HighVol[2] && HighVol[-1] == HighVol then close[1] else HighBar[1];
addlabel(yes, HighBar);
TOS Scanner Bollinger Band
October 09, 2017 05:30PM
I am trying to build a TOS scanner that finds stocks that are currently in a BollingerBand squeeze for a period of time

I have the code below - but it only seems to find the beginning of a squeeze

----------------------------------------

BollingerBandwidth()."Bandwidth" is less than or equal to BollingerBandwidth()."Squeeze"

-----------------------------------------
Re: Fun with ThinkScript
October 14, 2017 08:12PM
Hi Erica,

While I am not positive about your coding issue, there is a simple way to create the alert that you are wanting, yet it would be sent as a text message or an email. This could be done in one of two ways. First, if you go to the MarketWatch tab, you can set an alert for an individual symbol. All you have to do is create a study alert for the regular MACD but with the parameters of the histogram. To create the alert, select Study alert on the right hand side of the screen. Select edit, study, type in MACD, then change the plot to Diff, then crosses above (or below for the bear cross). Then on the right of this dialogue box select MACD again and change the plot to the zeroline. The default is going to give you an alert in real-time, but if you would like to be notified on bar close just change the offset to 1 on both sides.

The second way to do this is to go to the Scan tab and basically follow the exact same steps as I listed. However, now you can change from receiving alerts to come an entire watchlist. I hope this helps.
Re: Fun with ThinkScript
October 16, 2017 04:58PM
Hey Robert (or anyone who can help)

I'm looking to scan for two conditions being met 1) an inside day (the previous day) 2) the present price being near the 200 sma (say within 1.01 above and .99 below) The idea being to look for a potential reversal due to the fact of the indecision (inside day the day before), and also the potential support/resistance of the 200 sma below/above. Ideally the scan would be flexible to adjust for daily weekly timframes etc.

I also like the inside day / linearregcurve(400) combo
Thanks,

Jay

[tos.mx]



Edited 2 time(s). Last edit at 10/16/2017 05:02PM by Jaldi.
Re: Fun with ThinkScript
October 19, 2017 06:57AM
Comparing volume from two time periods:

Looking to compare the volume on the current 1 minute bars with the total daily volume from 1 bar ago. This is what I have:

def daily = aggregationPeriod.DAY;
def min = aggregationperiod.MIN;

def vmin = volume(period = min);
def vday = volume(period = daily)[1];

def cond1 = vmin > vday;

plot result = cond1;

I'm getting the error of a secondary period not allowed. I want to scan the on current 1min charts but is there any way to get the value for the total volume for yesterday (regular trading session) and compare the current 1 min volume to that total volume from 1 day ago?

Thanks
Re: Close of the highest volume bar
October 25, 2017 02:11PM
Thank Devil

Your script is giving, as you say, the first bar but not necessarily always happens that, it could be the highest 5 min volumen is the third or any other bar in the interval mentioned.

R
Req- Ichimoku MTF Indicator For ToS
October 28, 2017 04:50AM
Hello members, I am new to this forum. But i have a great idea on ichimoku strategy. But if any coder helps me in making that simple indicator that reduces lot of work on seeing ichimoku charts on Multi time frames.

Main idea is whether the price is above or below the Ichimoku Cloud of various Timeframes. the Timeframes i need to be watched is M5, M15, M30, 1H. The indicator needs to be plot below the chart (not overlay) with like red dots for below cloud and green dots for above cloud for the above mentioned timeframes, if it is in the cloud just black color or no color. My trade idea is to take the trade when all of the timeframes shows either bullish(all green dots) for buy or bearish(all red dots) for sell.

So please help me. I will surely give some reward for this work after creating the indicator if any one can.

Thank you



Edited 1 time(s). Last edit at 10/28/2017 04:56AM by dave365.
Free Scripts
October 27, 2017 04:44PM
I was just curious if it was legal to tweak free scripts that have been posted and sell them online for a cheap price? There have been a few that have been posted over that last few months that I would like to add to my website? Is that okay as long as their free and no legal agreement document has been signed?
Re: Fun with ThinkScript
October 28, 2017 10:30PM
Hi guys. Does anyone know a way to reference the bar that matches my Lowest(low[1], 5) call in thinkscript?
Re: Fun with ThinkScript / counting winners
November 03, 2017 04:04PM
Hi, Guys,

I'm trying to count winning trades in a back-testing system.

I want it to show the winning count on-the-fly in chartbubbles.


def boughtprice = EntryPrice(); # tracks the entry price of the trade
def net = (close - boughtprice); # calculates the running net of a trade

def win = Exit_Condition and net > 0; # defines a winning trade

def wincount_1 = TotalSum(win); # try to simply sum the number of wins
def wincount_2 = if loss then losscount[1] + 1 else losscount[1]; # another try to count the wins

AddChartBubble(Exit_Condition, high, "closing trade"
+ "\nWin = " + win
+ "\nwincount_1 = " + wincount_1
+ "\nwincount_2 = " + wincount_2
, Color.CYAN, yes);

This just reports N/A on the count attempts.

This seems like something that should be a built-in function - or at least should be easy.

Anyone have an idea how to make it work?

Thanks for any help!
Re: TOS Scanner Bollinger Band
November 03, 2017 08:42PM
There are elegant ways to do this.
When I wanted this very thing, I didn't want to put in the work to do it elegantly.
So, I brute-forced it like this:

def condition = B_width < K_width AND
B_width[1] < K_width[1] AND
B_width[2] < K_width[2] AND
B_width[3] < K_width[3] AND
B_width[4] < K_width[4] AND
B_width[5] < K_width[5] AND
B_width[6] < K_width[6] AND
B_width[7] < K_width[7] AND
B_width[8] < K_width[8] AND
B_width[9] < K_width[9]
;

That'll get you ten bars worth.

I *know* this isn't elegant, but it will do the job.
Re: Fun with ThinkScript
November 06, 2017 04:58AM
Is there a way to put an arrow on a specific day of the week on a day chart? So for example on a daily chart of 3 months show all fridays?

Also how can create a rollover vertical line on a daily chart for the week, so just like the year end rollover line I would like a week end rollover line is this possible?



Edited 1 time(s). Last edit at 11/06/2017 05:04AM by strategynode.
Re: Fun with ThinkScript
November 12, 2017 09:04AM
hot smiley Holy Fricken Cow LoL Been looking for a few months for a Board where other people actually help with a problem instead of brushing you off or charging you for help every time you turn around. I'm new to Trading but got into Penny Stock in 2012 for about three months, Had a few plays that to me were pretty big a few cashes over 1K smileys with beer and then made a few stupid plays and lost most of what I won.... In those the prices move so fast on most of them you cant cash out by the time you bought in LoL I played Tagg first time in after watching for three weeks from .01c to average of .23c everyday(ppl getting in and out first 2hrs everyday Prob 20-30 times in that first two hrs. with big gains)it stated on stats over 90million trades everyday in 2hrs??? Never seen such a thing!!! ppl making money up the Wazoo every few pennies. Anyway I record everything I do and did and would review with Snagit. My problem was I started on Capital Investments and had to verify after entering the sell or buy in a window and by the time you confirmed buy or sell the price had moved 5-10cents every time angry smiley Missed a few big Trades(20k+) and got so mad After three months quit. But what I learned from that is how to use the programs that work the markets "Something Called Autosell eye popping smiley LoL but on something moving that fast autosell doesnt work too well!!! (Short story long Ha Ha) Got back in to it in Feb 2017(Prob no more Penny Stock for Me) for good... and Learning all I can...I get maybe 4hrs sleep a day now EveryDay. Signed up in Feb 2017 TD and started learning everything I can about different ways of trading, Everyone thats making bigger money talks about Futures, Emins, Binaries, Etc. Wouldn't know how to trade those very good but learning with Paper Money can't afford to lose 10-50K or more in a few days LoL. Heard theirs big money in those if you know what your doing so maybe someday but right now I'm Trading Options On My REAL MONEY Account and its kinda Scary I don't want to be "Exercised, or Assigned" Those are Scary Words!!! Cant afford Amazon at 1100+ A Share eye popping smiley So until I know more and how all of that works I only Buy Options...I don't sell Them(Where most of the money is made I'm told???)

Anyway Newbie Here and You all are right from what I read here ROBERT "Were you born with an (Einstein) Gene" LoL Besides 1 other guy I ever met on Coding I haven't seen Anyone that can figure stuff out as good as You!!!! Not to say some of the other people on here are not Good or Great because some of you follow right along with Robert and have some of the best ideas I've Ever read on Coding/Charting!!!! I have been "Using" Almost all of the Ideas/ code that you all have come up with and Love the Sharing and the Teaching with a lot of you sharing why and how the code works winking smiley I have payed quite a bit on sites for some good programs and have tipped a lot to others that have had good ideas and Great Code and everyone I buy or someone shares I learn more!!! Not great with Math that is what hinders me(Hated it in School, Algebra Geometry, Calculus.....No Way!!! Basic Math Whoo Hoo smiling bouncing smiley ) I'm paying for it now Ha Ha. Anyway I'm only on page 26 of Fun with ThinkScript and I hope that the ppl that have posted on here in those previous post are still around AWESOME STUFF YOU HAVE ALL SHARED!!! look forward to Sharing when I make some programs that are even close to what some of you have come up with...Thanks Again Newbie Scott D. smileys with beer
Re: Fun with ThinkScript
November 17, 2017 04:45AM
Hi All,

I am new to TOS and not too familiar with the scanning script

Can anyone please help to create/translate a script for Pocket Pivot:

The details are as below:
// Criteria to only scan leading stocks

[type = stock] and
[daily sma(40,daily volume) > 500000] and
[daily sma(40,daily close) > 10] and
[daily close > daily sma(200,daily close)] and

// Criteria to verify the day's volume should be larger than the highest down volume day over the prior 10 days
[daily volume > 1 days ago daily volume * 1 days ago ROC(1) /absval(1 days ago ROC(1))* -1] and
[daily volume > 2 days ago daily volume * 2 days ago ROC(1) /absval(2 days ago ROC(1))* -1] and
[daily volume > 3 days ago daily volume * 3 days ago ROC(1) /absval(3 days ago ROC(1))* -1] and
[daily volume > 4 days ago daily volume * 4 days ago ROC(1) /absval(4 days ago ROC(1))* -1] and
[daily volume > 5 days ago daily volume * 5 days ago ROC(1) /absval(5 days ago ROC(1))* -1] and
[daily volume > 6 days ago daily volume * 6 days ago ROC(1) /absval(6 days ago ROC(1))* -1] and
[daily volume > 7 days ago daily volume * 7 days ago ROC(1) /absval(7 days ago ROC(1))* -1] and
[daily volume > 8 days ago daily volume * 8 days ago ROC(1) /absval(8 days ago ROC(1))* -1] and
[daily volume > 9 days ago daily volume * 9 days ago ROC(1) /absval(9 days ago ROC(1))* -1] and
[daily volume > 10 days ago daily volume * 10 days ago ROC(1) /absval(10 days ago ROC(1))* -1] and

//Criteria to see jump through 10 or 50 d SMA
[[yesterday's daily close < yesterday's daily sma(10,daily close)] and [daily close > daily sma(10,daily close)]

or

[yesterday's daily close < yesterday's daily sma(50,daily close)] and [daily close > daily sma(50,daily close)]]


Greatly appreciate your help! smileys with beer
ThinkScript counting N days in X timeframe
November 20, 2017 01:28AM
Hello everyone,
long time lurker first post. I have a simple question that I cannot seem to answer and would appreciate any help.

I know how to script consecutive days closing lower such as --- def LC = sum(close<close[1], 3) ==3; --- but seem to be missing how to script 3 days closing lower "out of" 6 such as -- N out of X days.

Edit: ... victory! I figured it out smiling smiley



Edited 1 time(s). Last edit at 11/30/2017 01:54AM by Jdubpwr.
Re: Fun with ThinkScript / counting winners
November 20, 2017 03:39AM
Hello danceswithclouds,

It is my limited understanding that TOS has the strategy tracking hard coded preventing access to the data. Some features can be accessed but are limited in use, such as entryprice() and FPL() . entryprice() interaction generally only knows if a position is active so once the position is closed it resets, unlike FPL() which keeps a running log, though in P&L not trades. One side step is to track the number of occurrences between exit rule and FPL() but never had much luck. If back testing, it is easier to export the data out of the strategy manager into excel. However, I found something better and close to what you are looking for a couple years ago.

TrendXplorer adapted some work to produce a lower study that displays all the information you are looking for. It does not work off the strategy side of TOS so he linked the getsymbol and entry/exit logic to actively display rate of return, open profit, CAR, roundtrips, etc, and the winning/losing trades you are looking for. You will have to dig through the script and remove the stochastic study he used as an example then merely insert your entry/exit logic and the symbol you are trading at the top of the script "input longETF = "SPY" but leave everything else the same. very easy. I imagine you can then port the study to the upper chart panel to add the stats in the bubbles at each exit as you desire, use lower in combo with the regular strategy side of TOS on the upper candle area.

To view some images and copy the script visit - [indexswingtrader.blogspot.com] , scroll down to the comment section and look for the # StochasticCrossoverSystem_Equity_Stats script which is the specific study you want to edit. If the link does not display (this is my 2nd post) then google -- How To Time The Market? Stochastics Rulez! TrendXplorer -- and it will display in the first few results.

Take care.
HOD scanner
November 20, 2017 03:34AM
Hi folks,

does anybody have script for HOD (high of the day) scanner. I tried to use the one that TOS offers in their study filter but it does not work properly when applied to Watchlist.

Thanx
S.
MA & Stochastic Signals?
November 29, 2017 05:47AM
Hey there. Great forum and lots of nice threads.

I'm myself no coder so I'm not able to do anything with ThinkScript but I was wondering if somebody here could come up with a script for this:

- If Hull Moving Average is pointing down and red + Stochastic overbought with a cross-over of K/D lines = ARROW DOWN

- Vice versa if Hull Moving Average is pointing up and green + Stochastic oversold with a cross-over of K/D lines = ARROW UP

Ideally the study would have options to change MA length & settings as well as Stochastic options inputs as well as alerts with arrow signals.

Is this possible?

If in case somebody could create it and post the code here I'd be very grateful.
Re: MA & Stochastic Signals?
November 30, 2017 01:42AM
MXO1.
What HMA length, and stochastic settings are you using? For example, Hma = 20, and stoch settings are 5,3,3. I created the script for you but no signals plot on a daily chart unless you are using large setting numbers and I want to make sure it is what you asked for. Also, the HMA pointing up/green or down/red is formulated hma>hma[1] by default meaning the slope of moving average being greater or lesser than where it was one bar ago, instead of whether the current candle close is above or below the moving average. It basically creates a 2 candle delay in changing direction but avoids whipsaw a little better. This means the HMA can be green pointing up, but a candle close below. You are focused on the slope/color of the HMA, not if the candle is above/below, correct?
Sorry, only registered users may post in this forum.

Click here to login