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
December 12, 2016 11:07AM
devildriver6

Thanks Loads...
Re: Fun with ThinkScript
December 12, 2016 12:44PM
Ralph53 Wrote:
-------------------------------------------------------
> It's 1 Minute devildriver6. What I'm trying to do
> is calculate the distance in cents from any point
> on a chart. Not just from crossover points. This
> will be a very useful script to have if it can be
> done because it will tell the size of any up
> thrust from anywhere in its cycle.

Okay, let me see if I understand correctly.
I'm sure "open <= close" isn't the actual condition you're looking for, as that'd be fairly hectic on a one minute chart.
So, I'm going to do this in generalized terms,rather than specifics.

If you want to save a value upon a condition being confirmed, you can use a recursive.

So, using your open <= close, it'd be like this.....

rec ConditionValue = if open <= close, then close else ConditionValue[1];

def ValuePlot = ConditionValue; ## either a def to store the value, or a plot to see the value

## Now for the value travelled, we'll subtract the ValuePlot from the current value
def Diff = close - ValuePlot;

addlabel(yes, Diff); #To see this value

##Other def's could be made based on predetermined variances.

def OverSold = Diff <= -10;
def OverBought = Diff >= 10;

So on and so forth.

Is this basically your intention?

As I said before, without knowing the specifics of what you're trying to do, this is all subjective.
Re: Fun with ThinkScript
December 12, 2016 01:01PM
Thanks for your time devildriver6. Sorry about my confusion about how Conditions work.This may make more sense;


def Condition1 = Close <= Open;
def Condition2 = Close < Open;

Plot X = if Condition1 then [ the distance in cents between the close of Condition1 continuing until Condition2 is reached ]


What I'm trying to do is have the script keep counting the distance from the point of Condition1 (through several green candles) until the start of Condition2. Then stop until the next 'ConditionConfirmed' point is reached where the cycle starts all over again.

Is this doable? Thanks, JM.




Edited 1 time(s). Last edit at 12/12/2016 04:15PM by Ralph53.
Re: Fun with ThinkScript
December 13, 2016 12:08PM
Is there anyway, where a script can look back at previous days action, but on a five minute time frame?

For example, "if yesterday's close (430PM) was higher than yesterday's 5 minute opening range (930-935AM), then 1 else 0".

Any insight would be greatly appreciated.
Re: Fun with ThinkScript
December 13, 2016 09:00PM
Robert - not sure if you're around, or know, but I'm working on something and need to get two things....
Or anyone else....

First, I need a way to call last years H. Obviously there's no aggregation for YEAR, which is dumb, but I need it.

Also, I need to call yesterday's RTH H.

Any help would be appreciated!
Re: Fun with ThinkScript
December 13, 2016 09:08PM
Ralph53 Wrote:
-------------------------------------------------------
> Thanks for your time devildriver6. Sorry about my
> confusion about how Conditions work.This may make
> more sense;
>
>
> def Condition1 = Close <= Open;
> def Condition2 = Close < Open;
>
> Plot X = if Condition1 then [ the distance in
> cents between the close of Condition1 continuing
> until Condition2 is reached ]
>
>
> What I'm trying to do is have the script keep
> counting the distance from the point of Condition1
> (through several green candles) until the start of
> Condition2. Then stop until the next
> 'ConditionConfirmed' point is reached where the
> cycle starts all over again.
>
> Is this doable? Thanks, JM.

Yeah, I'm not sure... Sorry man.
Maybe someone else can be more helpful.
How to find stocks which I have fallen a certain %?
December 13, 2016 11:44PM
So I want to know how to find stocks which have dropped 15% or higher from n bars, I figured out how to calculate that from a fixed no. of bars ago but I want the scanner to show all stocks 15% or more down from whenever last it happened. Is that possible?
Re: Fun with ThinkScript
December 14, 2016 12:42AM
Thanks for your help.
Re: Fun with ThinkScript
December 17, 2016 08:38AM
Quote
devildriver6
Robert - not sure if you're around, or know, but I'm working on something and need to get two things....
Or anyone else....

First, I need a way to call last years H. Obviously there's no aggregation for YEAR, which is dumb, but I need it.

Also, I need to call yesterday's RTH H.

Any help would be appreciated!

Note: this will ONLY work on a DAILY chart set to two years or longer because the intra-day charts do not extend far enough back to perform the necessary calculations.

# +--------------------------------------------------+
# |          Example: Find Last Year's High          |
# |                   Robert Payne                   |
# |               rrpayne.blogspot.com               |
# +--------------------------------------------------+
def lastYear = GetYear() == GetLastYear() - 1 ;
def dailyHigh = if lastYear then high else Double.NaN;
def lastYearHigh = HighestAll(dailyHigh);

AddLabel(yes, lastYearHigh, Color.YELLOW);

Quote
Ralph53
def Condition1 = Close <= Open;
def Condition2 = Close < Open;

Plot X = if Condition1 then [ the distance in cents between the close of Condition1 continuing until Condition2 is reached ]


What I'm trying to do is have the script keep counting the distance from the point of Condition1 (through several green candles) until the start of Condition2. Then stop until the next 'ConditionConfirmed' point is reached where the cycle starts all over again.

Is this doable? Thanks, JM.
# +--------------------------------------------------+
# |   Example: Plot the rise between Cond1 & Cond2   |
# |                   Robert Payne                   |
# |               rrpayne.blogspot.com               |
# +--------------------------------------------------+
declare lower;

def Cond1 = close >= open;
def Cond2 = close < open;

def Cond1Start = Cond1 and Cond2[1];
def StartValue = if Cond2 then Double.NaN else if Cond1Start then close else StartValue[1];

plot Continuation = close - StartValue;

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
December 20, 2016 01:29AM
hi, i will like to ask for a favor with a SCRIPT..

i will like to Add Label on the chart, saying when stocks or market is IN SQUEEZE and how many candles is in squeeze, Also when a stock is OUT OF SQUEEZE, and how many candles the stocks move when is out of squeeze, also on percent average how much the stocks move when is out of squeeze.
i hope someone can help.. thank you
Re: Fun with ThinkScript
December 20, 2016 01:34AM
hi, i will like to ask for a favor with a SCRIPT..

i will like to Add Label on the chart, saying when stocks or market is IN SQUEEZE and how many candles is in squeeze, Also when a stock is OUT OF SQUEEZE, and how many candles the stocks move when is out of squeeze, also on percent average how much the stocks move when is out of squeeze.
i hope someone can help.. thank you
Re: Fun with ThinkScript
December 20, 2016 03:04PM
Hi everyone. I have read this entire thread. Terrific stuff, and thanks to all.
I am not a programmer, and excuse me if I missed this subject in the thread.
I know you can set alerts when price hits it. example price alert at $20.00
My question, is it possible to have an alert go off when price hits a trendline that I have drawn?
Or when price gets within a certain percentage of the trendline?
I guess this would have to be built into a scan.
I have multiple charts that I have marked with trendlines, and price levels.
Thanks in advance for any help.
Re: Fun with ThinkScript
December 20, 2016 03:11PM
Robls Wrote:
-------------------------------------------------------
> Hi everyone. I have read this entire thread.
> Terrific stuff, and thanks to all.
> I am not a programmer, and excuse me if I missed
> this subject in the thread.
> I know you can set alerts when price hits it.
> example price alert at $20.00
> My question, is it possible to have an alert go
> off when price hits a trendline that I have
> drawn?
> Or when price gets within a certain percentage of
> the trendline?
> I guess this would have to be built into a scan.
> I have multiple charts that I have marked with
> trendlines, and price levels.
> Thanks in advance for any help.


If you draw a trend line on a chart, you can right click on said TL and create an alert based on it's position.
Same thing with price levels and fibs.
Re: Fun with ThinkScript
December 20, 2016 04:30PM
devildriver6 Wrote:
-------------------------------------------------------
> If you draw a trend line on a chart, you can right
> click on said TL and create an alert based on it's
> position.
> Same thing with price levels and fibs.
I know you can right-click on the TL and create an alert. Unfortunately, the alert is at the price you click at. I'm looking for something that would alert me when price touches the TL at any price along the TL, or within a certain percentage of touching the TL.
Re: Fun with ThinkScript
December 21, 2016 03:59PM
Hi this is my first time posting. The following code is for my watchlist and turns green / red when the EMAs are > or < each other and it works great. Now I'd like to incorporate the bid/ask into the code. Ideally it would turn green if EMAup and the ask is within .05 of SlowMA. Turns red if EMAdown and the bid is within .05 of the SlowMA else black. I just can't figure out how to the "within" part. I would appreciate any help and sorry if the code looks gross I'm still very new to this.


input price = close;
input fastLength = 3;
input slowLength = 9;
input averageType = AverageType.EXPONENTIAL;

def my60up = bid > close[1];
def my60down = bid < close[1];

def FastMA = MovingAverage(averageType, price, fastLength);
def SlowMA = MovingAverage(averageType, price, slowLength);

def EMAup = FastMA > SlowMA ;
def EMAdown = FastMA < SlowMA ;

plot PatternPlot =
my60up;

assignBackgroundColor(if EMAup then color.Green else if EMAdown then color.Red else color.Black) ;
Re: Fun with ThinkScript
December 21, 2016 04:31PM
Quote
mikew
I just can't figure out how to the "within" part. I would appreciate any help

def SlowMA = MovingAverage(averageType, price, slowLength); 
def withinRange = ask >= SlowMA - 0.05 AND ask <= SlowMA + 0.05;

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
December 21, 2016 04:38PM
Thanks!!!
Color Coding Candle Based upon Moving Averages
December 27, 2016 01:12PM
I am trying to color my candle based upon the close of three different moving averges similar to the E method, so the the example the 5, 10 and 25 simple moving averages. Cannot get the think script code right.

SMA1 = 5 SMA
SMA2 = 10 SMA
SMA3 = 25 SMA

The Candle is colored green when the SMA1 > SMA2 & SMA1 > SMA3
The Candle is colored Yellow when the SMA1 < SMA 2 and SMA1 > SMA3 OR SMA1 > SMA2 AND SMA1<SMA3
The Candle is colored Red when SMA1 < SMA2 and SMA1 < SMA 3


Thank you for all of your help!
Re: Color Coding Candle Based upon Moving Averages
December 27, 2016 03:46PM
Quote
bubba
I am trying to color my candle based upon the close of three different moving averges similar to the E method, so the the example the 5, 10 and 25 simple moving averages. Cannot get the think script code right.

SMA1 = 5 SMA
SMA2 = 10 SMA
SMA3 = 25 SMA

The Candle is colored green when the SMA1 > SMA2 & SMA1 > SMA3
The Candle is colored Yellow when the SMA1 < SMA 2 and SMA1 > SMA3 OR SMA1 > SMA2 AND SMA1<SMA3
The Candle is colored Red when SMA1 < SMA2 and SMA1 < SMA 3


Thank you for all of your help!



# +------------------------------------------------------------+
# |    Example: Color-Code Candles Based on Moving Averages    |
# |                        Robert Payne                        |
# |                    rrpayne.blogspot.com                    |
# +------------------------------------------------------------+
plot sma5 = Average(close, 5);
plot sma10 = Average(close, 10);
plot sma20 = Average(close, 20);

AssignPriceColor(if sma5 > sma10 and sma10 > sma20 then Color.GREEN else if sma5 < sma10 and sma10 < sma20 then Color.RED else Color.YELLOW);

- robert


Professional ThinkorSwim indicators for the average Joe
Snake Force Indicator
December 28, 2016 06:21AM
Hi guys,

I was searching then I found this indicator ( Snake Force ) , but I couldn't find it as thinkorswim code. Is it available on Thinkorswim ?

I found a link for this indicator on MT4
[www.greattradingsystems.com]



Edited 3 time(s). Last edit at 12/29/2016 04:24AM by SARA.
Re: Snake Force Indicator
December 28, 2016 06:29AM
_____



Edited 1 time(s). Last edit at 12/29/2016 04:24AM by SARA.
Re: Fun with ThinkScript
December 29, 2016 12:21PM
This scan has been useful Robert. I am trying to find scan logic that looks for Kangaroo tails as described by Alex Elder. This looks for long tail down at trend bottoms and up from uptrends. Long wicks being the important candle. I found the logic from a metastock scan, but am unable to recreate in TOS. I was wondering if this would be hard?

{ User inputs }
wickLim:=Input("Minimum candlewick % size of H-L range",0,100,25);
multi:=Input("H-L range Minimum: range Avg x",
0,100,2);
pds:=Input("H-L range Average lookback periods",
1,2520,21);

{ Minimum average H-L range }
range:=Max(H-L,.00001);
rangeOk:=(H-L)>Mov(range,pds,S)*multi;

{ Wicks }
upHi:=Max(O,C);
dwLo:=Min(O,C);
wickUp:=(1-(upHi-L)/range)*100;
wickDw:=(dwLo-L)/range*100;

{ Signals }
buy:=rangeOk
AND wickDw>wickLim
AND dwLo<=Ref(L,-1);
sell:=rangeOk
AND wickUp>wickLim
AND upHi>=Ref(H,-1);
signals:=buy-sell;

{ Plot in own window }
signals

---8<------------------------------

Any help would be greatly appreciated!

P.S. This was in response to a short scan you created earlier

# Calculate the length of the candle's wicks
def UpperWick = high - Max(open, close);
def LowerWick = Min(open, close) - low;

# Calculate the length of the candle's body
def CandleBody = AbsValue(open - close);

# Compare the wicks to the body to ensure that one wick is 3x longer than the body
# also compare the other wick to ensure that it is a "small" wick
def Hammer = (UpperWick / CandleBody >= 3) and (LowerWick / CandleBody <= 0.5);
def Star = (LowerWick / CandleBody >= 3) and (UpperWick / CandleBody <= 0.5);

# A scan should define one (and only one) plot for output. This plot will signal on
# either a hammer or a star;
plot data = Hammer or Star;



Edited 1 time(s). Last edit at 12/29/2016 12:27PM by Spivvy.
TTM WAVE B,C
December 31, 2016 09:58AM
hi everyone, i will like some help with the TTM WAVE B and C, i found some script online but is for different broker not Thinkorswim, here is the script for that broker, can somebody know how to create this script for TOS? i will like to have the TTM WAVE, B and C. thank you very much.. happy 2017

here is the script:


// Wave B
fastMA3 = usewb ? ema(close, 8) : na
slowMA3 = usewb ? ema(close, 89) : na
macd3 = usewb ? fastMA3 - slowMA3 : na
signal3 = usewb ? ema(macd3, 89) : na
hist3 = usewb ? macd3 - signal3 : na

fastMA4 = usewb ? ema(close, 8) : na
slowMA4 = usewb ? ema(close, 144) : na
macd4 = usewb ? fastMA4 - slowMA4 : na
signal4 = usewb ? ema(macd4, 144) : na
hist4 = usewb ? macd4 - signal4 : na

// Wave C
fastMA5 = usewc ? ema(close, 8) : na
slowMA5 = usewc ? ema(close, 233) : na
macd5 = usewc ? fastMA5 - slowMA5 : na
signal5 = usewc ? ema(macd5, 233) : na
hist5 = usewc ? macd5 - signal5 : na

fastMA6 = usewc ? ema(close, 8) : na
slowMA6 = usewc ? ema(close, 377) : na
macd6 = usewc ? fastMA6 - slowMA6 : na

// PLOTs
plot(macd6, color=#FF0000, style=histogram, title="Wave C1", linewidth=3)
plot(hist5, color=#FF8C00, style=histogram, title="Wave C2", linewidth=3)

plot(hist4, color=#FF00FF, style=histogram, title="Wave B1", linewidth=3)
plot(hist3, color=#0000FF, style=histogram, title="Wave B2", linewidth=3)

plot(hist2, color=#008000, style=histogram, title="Wave A1", linewidth=3)
plot(hist1, color=#DAA520, style=histogram, title="Wave A2", linewidth=3)

hline(0, color=black, title = "Zero Line", linewidth = 2, linestyle = solid)
Re: TTM WAVE B,C
January 04, 2017 08:28PM


Wolfe Wave for ThinkorSwim: what if you could predict the future?

This is a zero-lag indicator that relies on price-action alone. It automatically identifies and draws the Wolfe Wave pattern in real time.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: TTM WAVE B,C
January 04, 2017 09:57PM
I may be able to do this for you.
Re: TTM WAVE B,C
January 05, 2017 04:17AM
hey robert i read thru the article and free e-book you referenced on your website. very interesting strategy, I've never seen reversals traded in this fashion before based on price action alone. until now its always been with the aid of a divergence indicator, like the macd, which can be lagging.

question... unfortunately i trade daily candle charts and am unable to watch a particular security throughout the day for this price pattern to form. depending on how your script works, is it possible to create a scan that looks for the entry arrow (bullish or bearish) that recently formed that day after the close?

thanks,
mike



Edited 1 time(s). Last edit at 01/05/2017 04:18AM by mntman.
Re: TTM WAVE B,C
January 05, 2017 06:08AM
Mike,

This is the most complicated indicator I have yet programmed. I don't know, yet, if it can be turned into a scan or not. It may be too complex for the limited capabilities of the scan tool. Unfortunately, it will probably be another week or two before I have time available for any additional programming.

Due to my job, I am also limited to the daily chart. It doesn't take that long to flip through the watchlist looking for the arrows in the evening, though.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: TTM WAVE B,C
January 05, 2017 01:51PM
thanks robert and no prob i understand. i remember you explaining a little bit about the limitations of the scans one time before maybe with the market forecast divergences...

looking fwd to checking this one out and comparing with volume spikes, TICK, and maybe a couple other oscillators just out of curiosity.
Re: Fun with ThinkScript
January 06, 2017 12:38AM
I have a simple script for a stock's spread that TOS sent me a while back. It produces several white zero's when I use it in a watch list. Does anyone have a better spread script that works in a watch list column without the white zero's? Thanks, JM.


def Bid = if isnan(close(priceType = PriceType.BID)) then Bid[1] else close(priceType = PriceType.BID);
def Ask = if isnan(close(priceType = PriceType.ASK)) then Ask[1] else close(priceType = PriceType.ASK);
def Spread = Ask - Bid;

Plot Spd = Spread;
Re: Fun with ThinkScript
January 07, 2017 02:13AM
Hi Robert ,

Why we can't write a script on a Multi time frames that includes 10 min , 11 min, 12 min, 13 min, 14 min, and 15 min?

what I knew on all platforms is that 1 min , 2 min, 3 min, 4 min, and 5 min time frame is accepted but from 11 till 14 not accepted.
Sorry, only registered users may post in this forum.

Click here to login