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
October 25, 2016 06:39PM
THANKS!
Re: Fun with ThinkScript
October 25, 2016 08:29PM
Thanks man..
Re: Fun with ThinkScript
October 26, 2016 12:25AM
Thanks devildriver6! This looks like it will work. I will give this a try. Thank you!

devildriver6 Wrote:
-------------------------------------------------------
> Another way to do this is as follows:
>
> def price = close;
> def fastLength = 50;
> def slowLength = 144;
> def displace = 0;
> def averageType = AverageType.EXPONENTIAL;
>
> def fastAvg = MovingAverage(averageType,
> price[-displace], fastLength);
> def slowAvg = MovingAverage(averageType,
> price[-displace], slowLength);
>
> def hiLevel = if fastAvg >= slowAvg then
> Double.POSITIVE_INFINITY else
> Double.NEGATIVE_INFINITY;
> AddCloud(hiLevel, -hiLevel, Color.GREEN,
> Color.RED
Trying to Scan
October 28, 2016 03:22PM
Hi All,

Great group here lots of good information. I have been using a MACD Divergence script for a few weeks, I didnt write it. I would like to scan for Bull fast and slow, Bear fast and slow. When I use the normal methods of "true" and =0 don't work, I get the dreaded "complex" error, Can someone look to see if its possible to simplifier the code so the scan can be performed? thanks for any help






#-----------------------------------------------------------------------------



#Swing hilo
input sb = 2;
input sf = 2;
input spacer = 1;

def swinglow = if low < Lowest(low[1], sb) and low < Lowest(low[-sf], sf)
then 1
else 0;
def sl = if swinglow == 1
then low - TickSize() * spacer
else Double.NaN;
def swinghigh = if high > Highest(high[1], sb) and high > Highest(high[-sf], sf)
then 1
else 0;
def sh = if swinghigh == 1
then high + TickSize() * spacer
else Double.NaN;

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up"winking smiley else Diff.Color("Positive and Down"winking smiley else if Diff < Diff[1] then Diff.Color("Negative and Down"winking smiley else Diff.Color("Negative and Up"winking smiley);
ZeroLine.SetDefaultColor(GetColor(0));

plot x = if swinghigh == 1 then Diff else Double.NaN;
plot y = if swinglow == 1 then Diff else Double.NaN;
x.SetPaintingStrategy(PaintingStrategy.POINTS);
y.SetPaintingStrategy(PaintingStrategy.POINTS);

def oschigh = if swinghigh == 1
then Diff
else oschigh[1];
def fast = if swinghigh == 1
then high
else fast[1];
def oschighdiv = if (fast - fast[1] > 0 and
oschigh - oschigh[1] < 0) or
(fast - fast[1] < 0 and
oschigh - oschigh[1] > 0)
then 1
else 0;
input bubblehighlimit = 1;
def dataCount = CompoundValue(1, if (oschighdiv)
then dataCount[1] + 1
else dataCount[1], 0);
#AddChartBubble(HighestAll(dataCount) - dataCount <= bubblehighlimit - 1 and oschighdiv == 1,
# if fast - fast[1] > 0 then Diff + TickSize() * spacer else Diff - TickSize() * spacer,
# if fast - fast[1] > 0 then "MACD\nBear \n fast" else "MACD\nBull \n fast",
# if fast - fast[1] > 0 then Color.RED else Color.GREEN,
# if fast - fast[1] > 0 then yes else no);


def cond2 = if swinghigh == 1 and oschighdiv == 1
then BarNumber()
else cond2[1];
def cond1 = if BarNumber() < HighestAll(cond2) and swinghigh == 1 #and oschighdiv == 0
then BarNumber()
else cond1[1];
#plot line = if BarNumber() == HighestAll(cond1)
# then Diff
# else if BarNumber() == HighestAll(cond2)
# then Diff
# else Double.NaN;
#line.EnableApproximation();
#line.SetDefaultColor(Color.WHITE);
#line.SetLineWeight(2);



def slow = if swinglow == 1
then low
else slow[1];

def osclow = if swinglow == 1
then Diff
else osclow[1];
def osclowdiv = if (slow - slow[1] > 0 and
osclow - osclow[1] < 0) or
(slow - slow[1] < 0 and
osclow - osclow[1] > 0)
then 1
else 0;
input bubblelowlimit = 1;
def dataCount1 = CompoundValue(1, if (osclowdiv)
then dataCount1[1] + 1
else dataCount1[1], 0);
#AddChartBubble(HighestAll(dataCount1) - dataCount1 <= bubblelowlimit - 1 and osclowdiv == 1,
# if slow - slow[1] > 0 then Diff + TickSize() * spacer else Diff - TickSize() * spacer,
# if slow - slow[1] > 0 then "MACD\nBear \n slow" else #"MACD\nBull \n slow",
# if slow - slow[1] > 0 then Color.RED else Color.GREEN,
#if slow - slow[1] > 0 then yes else no);


def cond2a = if swinglow == 1 and osclowdiv == 1
then BarNumber()
else cond2a[1];
def cond1a = if BarNumber() < HighestAll(cond2a) and swinglow == 1 #and osclowdiv == 0
then BarNumber()
else cond1a[1];
#plot linea = if BarNumber() == HighestAll(cond1a)
# then Diff
# else if BarNumber() == HighestAll(cond2a)
# then Diff
# else Double.NaN;
#linea.EnableApproximation();
#linea.SetDefaultColor(Color.blue);
#linea.SetLineWeight(2);


#AG
# What's in the code is two addbubble statements. From those, we get the two signals "bull" and "bear" -- each from either fast or slow indicators
# verbatim (in other words, I don't assert they're right, just duplicates of whatever is already there in that signal)

def diverg_high = HighestAll(dataCount) - dataCount <= bubblehighlimit - 1 and oschighdiv == 1 ;
def diverg_low = HighestAll(dataCount1) - dataCount1 <= bubblelowlimit - 1 and osclowdiv == 1;


def bear_fast = fast - fast[1] > 0; # (sic)
def bull_fast = !(bear_fast);
def bear_slow = slow - slow[1] > 0;
def bull_slow = !(bear_slow);

# there's four possible decorations:
# 1. "bear fast"
# 2. "bull fast"
# 3. "bear slow"
# 4. "bull slow"

plot "bear (fast)" = if diverg_high && bear_fast then Diff + TickSize() * spacer else Double.NaN;
"bear (fast)".SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
"bear (fast)".SetDefaultColor(Color.ORANGE);
"bear (fast)".SetLineWeight(3);
plot "bull (fast)" = if diverg_high && bull_fast then Diff - TickSize() * spacer else Double.NaN;
"bull (fast)".SetPaintingStrategy(PaintingStrategy.ARROW_UP);
"bull (fast)".SetDefaultColor(Color.CYAN);
"bull (fast)".SetLineWeight(3);
plot "bear (slow)" = if diverg_low && bear_slow then Diff + TickSize() * spacer else Double.NaN;
"bear (slow)".SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
"bear (slow)".SetDefaultColor(Color.CYAN);
"bear (slow)".SetLineWeight(3);
plot "bull (slow)" = if diverg_low && bull_slow then Diff - TickSize() * spacer else Double.NaN;
"bull (slow)".SetPaintingStrategy(PaintingStrategy.ARROW_UP);
"bull (slow)".SetDefaultColor(Color.CYAN);
"bull (slow)".SetLineWeight(3);


def signal = { default "No Signal", "Bear Fast", "Bear Slow", "Bull Fast", "Bull Slow"};

if diverg_high
then {
if bear_fast
then {
signal = signal."Bear Fast";
} else {
signal = signal."Bull Fast";
}
} else {
if diverg_low
then {
if bear_slow
then {
signal = signal."Bear Slow";
} else {
signal = signal."Bull Slow";
}
} else {
signal = signal[1];
}
}
;


AddLabel(yes,
if signal == signal."Bear Fast" then "bear fast"
else if signal == signal."Bear Slow" then "bear slow"
else if signal == signal."Bull Fast" then "bull fast"
else if signal == signal."Bull Slow" then "bull slow"
else if signal == signal."No Signal" then "No Signal"
else "<error>",
if signal == signal."Bull Fast" or signal == signal."Bull Slow"
then Color.DARK_GREEN
else Color.DARK_RED
);
Re: Fun with ThinkScript
October 30, 2016 03:29AM
Hi Ralph53

Here's a spread label script that I use, Is this what you want?

input label = Yes;

def rBID = if !isNaN(close(priceType="BID" )) then close(priceType="BID" ) else rBID[1];

def rASK = if !isNaN(close(priceType="ASK" )) then close(priceType="ASK" ) else rASK[1];

def spread = rASK - rBID;

AddLabel(label, "BID " + rBID, if rBID > rBID[1] then Color.GREEN else if rBID < rBID[1] then Color.RED else Color.GRAY);
AddLabel(label, "ASK " + rASK, if rASK > rASK[1] then Color.GREEN else if rASK < rASK[1] then Color.RED else Color.GRAY);

addLabel(label, "SPREAD " + spread );
Re: Fun with ThinkScript
October 30, 2016 08:55AM
yes, but how can i incorporate teh flashing label with this


def flash = if close(priceType = "LAST"winking smiley == close(priceType = "BID"winking smiley
then 1
else if close(priceType = "LAST"winking smiley == close(priceType = "ASK"winking smiley
then -1
else 0;
addLabel(1, "test", if flash == 1 then color.green
else if flash == -1
then color.red

else color.white);
Re: Trying to Scan
October 30, 2016 10:32AM
Have u found this code works well as far giving good signals? How do you use this code to trade?
Scan Help
November 01, 2016 09:10PM
Hi Scripters,

I have a MACD Divergence study (didn't write it) that I like to use during trading hours but trying to scan for divsignal and divsignall show inconsistent results, can you look at the script and add the scan codes to the bottom?

declare lower;

input fastEMA = 24;
input slowEMA = 52;
input Smooth = 9;

def c = close;
def h = high;
def l = low;
def FSignal = (c * .15) + (.85 * ExpAverage(c, fastEMA)[1]);
def SSignal = (c * .075) + (.925 * ExpAverage(c, slowEMA)[1]);

plot MACD = FSignal - SSignal;
MACD.SetPaintingStrategy(PaintingStrategy.LINE);
MACD.SetLineWeight(2);
MACD.AssignValueColor(if MACD < 0 and
MACD < MACD[1]
then Color.RED
else if MACD < 0 and
MACD > MACD[1]
then Color.CYAN
else if MACD > 0 and
MACD > MACD[1]
then Color.GREEN
else Color.LIME);

plot MACDSL = ExpAverage(MACD, Smooth);
MACDSL.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
MACDSL.SetLineWeight(5);
MACDSL.AssignValueColor(if MACDSL < 0 and
MACDSL < MACDSL[1]
then Color.PLUM
else if MACDSL < 0 and
MACDSL > MACDSL[1]
then Color.GREEN
else if MACDSL > 0 and
MACDSL > MACDSL[1]
then Color.BLUE
else Color.LIGHT_RED);

rec MACDh = CompoundValue(1, if MACD < 0
then Double.NaN
else if MACD crosses above 0
then MACD
else if MACD > 0 and
MACD > MACDh[1]
then MACD
else MACDh[1], 0);

rec Valueh = CompoundValue(1, if MACD < 0
then Double.NaN
else if MACD crosses above 0
then h
else if MACD > 0 and
h > Valueh[1]
then h
else Valueh[1], 0);

plot divSignal = if MACD > 0 and
h > Valueh[1] and
MACD < MACDh[1]
then 0
else Double.NaN;
divSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
divSignal.SetLineWeight(4);
divSignal.SetDefaultColor(Color.RED);

rec MACDl = CompoundValue(1, if MACD > 0
then Double.NaN
else if MACD crosses below 0
then MACD
else if MACD < 0 and
MACD < MACDl[1]
then MACD
else MACDl[1], 0);

rec Valuel = CompoundValue(1, if MACD > 0
then Double.NaN
else if MACD crosses below 0
then l
else if MACD < 0 and
l < Valuel[1]
then l
else Valuel[1], 0);

plot divSignall = if MACD < 0 and
l < Valuel[1] and
MACD > MACDl[1]
then 0
else Double.NaN;
divSignall.SetPaintingStrategy(PaintingStrategy.POINTS);
divSignall.SetLineWeight(4);
divSignall.SetDefaultColor(Color.GREEN);

def SMA = Average(c, 20);
def SD = StDev(c, 20);
def ATR = Average(TrueRange(h, c, l), 20);
def UpperBB = SMA + (SD * 2);
def UpperKC = SMA + (ATR * 1.5);
plot SQ = if UpperBB - UpperKC < 0
then 0
else Double.NaN;
SQ.SetPaintingStrategy(PaintingStrategy.Points);
SQ.SetLineWeight(2);
SQ.SetDefaultColor(Color.Yellow);

plot zeroLine = if IsNaN(divSignal) and
IsNaN(divSignall) and
IsNaN(SQ) and
!IsNaN(c)
then 0
else Double.NaN;
zeroLine.SetPaintingStrategy(PaintingStrategy.POINTS);
zeroLine.SetLineWeight(2);
zeroLine.SetDefaultColor(Color.BLUE);

#AddCloud(MACD, MACDSL, Color.LIGHT_GRAY, Color.YELLOW);

plot ArrowUP = if isNaN(SQ) and
SQ[1] == 0 and
MACD >= 0 and
MACD > MACD[1]
then 0
else Double.NaN;
ArrowUP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
ArrowUP.SetLineWeight(3);
ArrowUP.SetDefaultColor(Color.Green);

def SQbar = CompoundValue(2, if !IsNaN(SQ)
then SQbar[1] + 1
else if UpperBB > UpperKC
then Double.NaN
else SQbar[1], 1);



def LowTrough = if MACDSL < 0 and
MACDSL[1] < MACDSL[2] and
MACDSL > MACDSL[1]
then MACDSL
else if MACDSL > 0
then Double.NaN
else Double.NaN;

plot LowPoint = LowTrough;
LowPoint.EnableApproximation();
LowPoint.SetPaintingStrategy(PaintingStrategy.Line);
LowPoint.SetLineWeight(1);
LowPoint.SetDefaultColor(Color.White);


# End Code



Edited 1 time(s). Last edit at 11/01/2016 09:11PM by fingerlake.
Condition true recognition help
November 13, 2016 08:14PM
I am trying to figure out if a certain condition is true within n number of bars

so right now it looks very long and inefficient wondering if there is a easier way to do this I think fold function might help but I am not very familiar with it and am not able to make it work, here is how it looks right now.

(condition[1] or condition[2] or condition[3] or condition[4] or condition[5] or condition[6]..... or condition[n]) is true



Edited 1 time(s). Last edit at 11/13/2016 08:14PM by strategynode.
Re: Condition true recognition help
November 14, 2016 02:49AM
-- deleted --



Edited 1 time(s). Last edit at 11/14/2016 03:48AM by mntman.
Re: Condition true recognition help
November 14, 2016 11:59AM
Quote
strategynode
I am trying to figure out if a certain condition is true within n number of bars

so right now it looks very long and inefficient wondering if there is a easier way to do this I think fold function might help but I am not very familiar with it and am not able to make it work, here is how it looks right now.

(condition[1] or condition[2] or condition[3] or condition[4] or condition[5] or condition[6]..... or condition[n]) is true

# +--------------------------------------------------+
# |      Example: Condition True Within N Bars       |
# |                   Robert Payne                   |
# |               rrpayne.blogspot.com               |
# +--------------------------------------------------+
plot MA10 = Average(close, 10);
plot MA20 = Average(close, 20);

# Define the "condition" as MA10 crossing below MA20
def condition = MA10 crosses below MA20;

# Determine if the "condition" has been TRUE within the last "N" bars
def N = 5;
def trueWithin = Sum(condition, N);

# change candle color to yellow as a visual cue for this example
AssignPriceColor(if trueWithin then Color.YELLOW else Color.CURRENT);



- robert


Professional ThinkorSwim indicators for the average Joe



Edited 1 time(s). Last edit at 11/14/2016 12:06PM by robert.
Re: Condition true recognition help
November 14, 2016 09:52PM
Perfect thank you so much! Robert. So I tried a different method somebody else suggested was to use the
"condition true with n bars"
which also did give me what I was looking for, any reason you may think the above mentioned solution may not work?

Also I have another followup question on this how do I record the value where that certain condition is true so for example say:
Condition is true at bar 5 I want to know the high & low value of that bar to move forward with my calculation.
Re: Fun with ThinkScript
November 15, 2016 05:31PM
I want to start by saying you guys do some awesome work and create awesome indicators. I trade mostly futures. I trying to find a way to filter out lots of a certain size to determine if 50 lot (50-99) traders and 100 lot (100-150) are buying or selling. Then plot it on a chart so I can determine if they are idle, buying or selling. I use both TOS and Ninjatrader 8. I know of services that provide it but they want 400 a month for a subscription. If anyone could point me in the right direction I would greatly appreciate it. Thanks again.

Futuresnoob.
Re: Fun with ThinkScript
November 16, 2016 07:51AM
now it is actually possible to see what is happening on a 5 minute globex candlestick chart .... . instead of just seeing mush



elovemer Wrote:
-------------------------------------------------------
> and how might indicators be placed on these new
> spaced bars ?
>
> after all, the purpose of having spaced bars is to
> be able to see price.
>
>
>



Edited 1 time(s). Last edit at 11/16/2016 07:51AM by elovemer.
Breakout Scan Help
November 17, 2016 07:58AM
I think I'm looking for something simple, but can't figure it out. Can anyone tell me how to scan for stocks in TOS where the current price breaks either the previous candle (I use 60 minute candles) high or low? For good measure, ATR should also be greater than 50 cents. Thanks in advance!
Re: Fun with ThinkScript
November 17, 2016 12:36PM
Can someone please explain to me what the difference is between Close > Open and Close - Open? Do they mean the same thing.
Re: Fun with ThinkScript
November 17, 2016 01:18PM
Quote
Kamadi
Can someone please explain to me what the difference is between Close > Open and Close - Open? Do they mean the same thing.

"Close > Open" is a comparison. Is the closing price greater than the opening price? This will evaluate to either True or False

"Close - Open" is a math equation. What is the difference between the closing price and the opening price? This will evaluate to a number like 1.79.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
November 17, 2016 06:01PM
Thank you so much Robert for the explanation. Maybe you can help me with this script. Is there a way to write a script for multiple time frame MacDs that line up in sync. As a color dot indicator for the bottom of the chart. Example would be when the 12-26-9 macd value is above zero and value is above Avg all on the H1 , H4 , Daily , and weekly then I get a green dot and when it's below zero for all timeframes it's a red dot.
Re: Fun with ThinkScript
November 18, 2016 12:07AM
Kamadi Wrote:
-------------------------------------------------------
> Thank you so much Robert for the explanation.
> Maybe you can help me with this script. Is there a
> way to write a script for multiple time frame
> MacDs that line up in sync. As a color dot
> indicator for the bottom of the chart. Example
> would be when the 12-26-9 macd value is above zero
> and value is above Avg all on the H1 , H4 , Daily
> , and weekly then I get a green dot and when it's
> below zero for all timeframes it's a red dot.

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
def H1 = AggregationPeriod.HOUR ;
def H4 = AggregationPeriod.FOUR_HOURS ;
def D = AggregationPeriod.DAY ;
def W = AggregationPeriod.WEEK ;

DefineGlobalColor("UpTrend", Color.DARK_GREEN);
DefineGlobalColor("DownTrend", Color.RED);
DefineGlobalColor("NoTrend", Color.LIGHT_GRAY);

def TF = GetAggregationPeriod();
def TFCHECK = if TF < H1 then yes else no ;

#H1
def FastAvgH1 = ExpAverage(close(period = H1) ,FastLength);
def SlowAvgH1 = ExpAverage(close(period = H1) , SlowLength);
def ValueH1 = FastAvgH1 - SlowAvgH1;
def AvgH1 = ExpAverage(ValueH1, MACDLength);
def DiffH1 = (ValueH1 - AvgH1);

#H4
def FastAvgH4 = ExpAverage(close(period = H4) ,FastLength);
def SlowAvgH4 = ExpAverage(close(period = H4) , SlowLength);
def ValueH4 = FastAvgH4 - SlowAvgH4;
def AvgH4 = ExpAverage(ValueH4, MACDLength);
def DiffH4 = (ValueH4 - AvgH4);

#D
def FastAvgD = ExpAverage(close(period = D) ,FastLength);
def SlowAvgD = ExpAverage(close(period = D) , SlowLength);
def ValueD = FastAvgD - SlowAvgD;
def AvgD = ExpAverage(ValueD, MACDLength);
def DiffD = (ValueD - AvgD);

#W
def FastAvgW = ExpAverage(close(period = W) ,FastLength);
def SlowAvgW = ExpAverage(close(period = W) , SlowLength);
def ValueW = FastAvgW - SlowAvgW;
def AvgW = ExpAverage(ValueW, MACDLength);
def DiffW = (ValueW - AvgW);

plot DOT = if TFCHECK THEN low - 0.1 else Double.NaN ;
DOT.AssignValueColor(if (DiffH1 >0 AND DiffH4 > 0 AND DiffD > 0 AND DiffW > 0) then GlobalColor("UpTrend" ) else if (DiffH1 < 0 AND DiffH4 < 0 AND DiffD < 0 AND DiffW < 0) then GlobalColor("DownTrend" ) else GlobalColor("NoTrend" ));
DOT.SetPaintingStrategy(PaintingStrategy.POINTS);
DOT.SetLineWeight(3);



Edited 3 time(s). Last edit at 11/29/2016 04:26AM by victoradhitya.
Re: Fun with ThinkScript
November 18, 2016 08:20AM
Can this script be reposted without the smiley faces? Whenever I try to replace them I always get an error message. Thanks!
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
def H1 = AggregationPeriod.HOUR ;
def H4 = AggregationPeriod.FOUR_HOURS ;
def D = AggregationPeriod.DAY ;
def W = AggregationPeriod.WEEK ;

DefineGlobalColor("UpTrend", Color.DARK_GREEN);
DefineGlobalColor("DownTrend", Color.RED);
DefineGlobalColor("NoTrend", Color.LIGHT_GRAY);

def TF = GetAggregationPeriod();
def TFCHECK = if TF < H1 then yes else no ;

#H1
def FastAvgH1 = ExpAverage(close(period = H1) ,FastLength);
def SlowAvgH1 = ExpAverage(close(period = H1) , SlowLength);
def ValueH1 = FastAvgH1 - SlowAvgH1;
def AvgH1 = ExpAverage(ValueH1, MACDLength);
def DiffH1 = (ValueH1 - AvgH1);

#H4
def FastAvgH4 = ExpAverage(close(period = H4) ,FastLength);
def SlowAvgH4 = ExpAverage(close(period = H4) , SlowLength);
def ValueH4 = FastAvgH4 - SlowAvgH4;
def AvgH4 = ExpAverage(ValueH4, MACDLength);
def DiffH4 = (ValueH4 - AvgH4);

#D
def FastAvgD = ExpAverage(close(period = D) ,FastLength);
def SlowAvgD = ExpAverage(close(period = D) , SlowLength);
def ValueD = FastAvgD - SlowAvgD;
def AvgD = ExpAverage(ValueD, MACDLength);
def DiffD = (ValueD - AvgD);

#W
def FastAvgW = ExpAverage(close(period = W) ,FastLength);
def SlowAvgW = ExpAverage(close(period = W) , SlowLength);
def ValueW = FastAvgW - SlowAvgW;
def AvgW = ExpAverage(ValueW, MACDLength);
def DiffW = (ValueW - AvgW);

plot DOT = if TFCHECK THEN low - 0.1 else Double.NaN ;
DOT.AssignValueColor(if (DiffH1 >0 AND DiffH4 > 0 AND DiffD > 0 AND DiffW > 0) then GlobalColor("UpTrend"winking smiley else if (DiffH1 < 0 AND DiffH4 < 0 AND DiffD < 0 AND DiffW < 0) then GlobalColor("DownTrend"winking smiley else GlobalColor("NoTrend"winking smiley);
DOT.SetPaintingStrategy(PaintingStrategy.POINTS);
DOT.SetLineWeight(3);



Edited 2 time(s). Last edit at 11/18/2016 08:24AM by rcmcfe.
Re: Fun with ThinkScript
November 18, 2016 08:42AM
This forum has "automatic smiley" enabled. So anytime the message board encounters a quotation mark followed immediately by a close parenthesis it automatically converts that to a winking smiley. Like so...

") automatically becomes "winking smiley

To get around this when I post scripts, I will first open my script in a text editor then do a search and replace as follows:

search for: ")
replace with: " ) (that's [quotation mark][space][close parenthesis] )

After doing that I then paste my script on here.

Before:

def dailyHigh = high(period = "day"winking smiley;

After:

def dailyHigh = high(period = "day" );

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
November 18, 2016 09:11AM
Unfortunately, my text editor (mac) doesn't have a search function.
Re: Fun with ThinkScript
November 18, 2016 09:27AM
Quote
rcmcfe
Unfortunately, my text editor (mac) doesn't have a search function.

Sure it does. Just press [CMD]+[F]. Although, I much prefer the free TextWrangler editor from BareBones software.

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
November 23, 2016 05:57PM
Is it possible to scan for stocks that have low float on thinkorswim
Some assistance please smiling bouncing smiley
November 24, 2016 11:01PM
Firstly Thank you for this great resource !! I've learnt heats but struggling to figure out how to perform the following scenario:

Because of my timezone I start my trading day at 12:00 EST. I'm looking for a way to run a scan that with be "true" if the "high" > "open" any time between 9:30 EST and 12:00 EST and then if the 50MA > 200MA at the time I actually execute the scan, so from 12 noon onwards. So essentially look back to the morning hours and set some kind of flag to true ....

Hope that makes sense ?


Thanks Andrew
Re: Fun with ThinkScript
November 30, 2016 12:11AM
Hey guys,

EDIT: Nevermind, I was able to work through the issues I was having, and had some help from some of the guys in the thinkorswim Think Script chat room.

Best regards,
Derek



Edited 1 time(s). Last edit at 11/30/2016 06:45PM by DROCK.
Intraday EMAs
November 30, 2016 05:32PM
Hello, I would like to add a chart study where, on a 1 min chart, 9 period EMAs of 15 min and 60 min aggregation are shown. Would that be easy to script?
Thanks in advance

Stefano
Re: Intraday EMAs
December 01, 2016 07:51PM
stefcrive Wrote:
-------------------------------------------------------
> Hello, I would like to add a chart study where, on
> a 1 min chart, 9 period EMAs of 15 min and 60 min
> aggregation are shown. Would that be easy to
> script?
> Thanks in advance
>
> Stefano


Sefano - you just need to add different aggregations, but this only goes one way (time frames LARGER than chart level).

Like this...


input length = 9;
input displace = 0;
input Period_1 = aggregationPeriod.FIFTEEN_MIN;
input Period_2 = aggregationPeriod.HOUR;

## Chart Level EMA
plot ChartAvg = ExpAverage(close[-displace], length);

## 15 Minute EMA
plot "15EMA" = ExpAverage(close(period = Period_1)[-displace], length);

## Hourly EMA
plot "60EMA" = ExpAverage(close(period = Period_2)[-displace], length);


Erase what you don't need. smiling smiley
Re: Fun with ThinkScript
December 01, 2016 09:51PM
Now I have a question I can't quite figure out.

I'm trying to get the average of the volume bars, but I ONLY want the after hours bars to be calculated in the After Hours volume average, and ONLY the RTH bars to be calculated within the RTH volume average, both within the same indicator.

This way, it takes the averages of both sections and isn't too high in AHs and too low in RTHs.

Maybe Robert can help here.
Re: Fun with ThinkScript
December 02, 2016 07:18AM
Quote
devildriver6
Now I have a question I can't quite figure out.

I'm trying to get the average of the volume bars, but I ONLY want the after hours bars to be calculated in the After Hours volume average, and ONLY the RTH bars to be calculated within the RTH volume average, both within the same indicator.

This way, it takes the averages of both sections and isn't too high in AHs and too low in RTHs.

Maybe Robert can help here.

This will get you started.


# determine when the market is open
def mktIsOpen = SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) > 0;

# calculate volume when the market is open
plot volRTH = if mktIsOpen then volume else Double.NaN;

# calculate volume when the market is closed
plot volAH = if !mktIsOpen then volume else Double.NaN;

- robert


Professional ThinkorSwim indicators for the average Joe
Sorry, only registered users may post in this forum.

Click here to login