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
April 01, 2016 01:14PM
I've got another one for you tanman. I was reading about the "E" trade from posts way back and I'm trying to create a watch list column like the one they showed. Problem is, when I put the code in for one column, I cant change the time-frames but on one column. So if 1 column is a 5 min, they all have to be a five min. I like to have the same code for several time-frames. Can you help with this?Thanks again for your help. Here's the column watch-list code:

input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};

def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
MA3 = ExpAverage(close, long_average);
}


plot Eup = if MA1 > MA2 && MA2 > MA3 then 1 else
0;
def Edn = if MA1 < MA2 && MA2 < MA3 then 1 else
0;


EUp.AssignvalueColor(IF Eup THEN COLOR.LIGHT_green
else if Edn then color.PINK ELSE Color.gray);

AssignbackgroundColor(IF Eup THEN
COLOR.LIGHT_green else if Edn then color.PINK ELSE
Color.gray);
Re: Fun with ThinkScript
April 01, 2016 04:53PM
thank you very much !

I am loving what I am seeing so far. I will take a closer look this weekend and report back. Is it possible to turn this into a scan? I tried calling it from a scan but it returned zero results. I selected one of the 4 divergences types in the scan conditions.


thanks.
Re: Fun with ThinkScript
April 01, 2016 10:27PM
Tanman, I like the Macd Divergence study you posted. I have always been intrigued by divergence and have several studies. I modified your code with the following lengths: 16,97,2 and like the results. I am however having problems scanning for the condition, do you have some scan code to help recognize the divergence when it occurs? Also I have not been able to get your alert to work, have you tested the alerts?

appreciate your work and let me know if your interested in some more divergence studies
Re: Fun with ThinkScript
April 02, 2016 03:50PM
Rob Miller,

You are welcome. I have not tried to write any watchlist scripts before, and I don't know if that can be done for watchlist columns. Maybe Robert can help you with this if/when he comes back.



Edited 1 time(s). Last edit at 04/02/2016 04:25PM by tanman.
Re: Fun with ThinkScript
April 02, 2016 04:24PM
fvaldez and jakesdad,

You are welcome. This has been very useful to me as well, and I thank you fvaldez for bringing Elder's rules to my attention. Thank you jakesdad for offering me other divergence scripts and I will let you know when I need them. Previously, I have used momentum divergence based on modified AwesomeOscillator lower study with settings of 7/14/exponential which also works very well. Recently, I have invented a new volume based lower study to be used for divergence in /ES and SPY which has shown amazing performance. I am still testing it in real time so it might need to be fine tuned. I am also working on a script based on it to paint divergence arrows on upper chart, and coding that upper study has been extremely challenging.

I will have to check the alerts for the MACD divergence script in real time during trading hours. I think playing around with the [1] in the alert line and changing it to [2] or removing it might work.

As far as scans are concerned, the script that I posted has a "plot" for Diff at the beginning which needs to be changed to "def", so there is only one plot line in the scan script. Additionally, you might have to add [1] or [2] or [3] etc. to the divergence signal variable. My scan worked when I added [3]. For example, following is the scan for bearish divergence and you can modify script in similar way for scanning other divergences.

I changed the default number of bars to determine swing high/low to 4 because it gives better results in my experience. You can change it to whatever you like. I also added input for filter number to eliminate tiny divergences. You can set it to 0 if you want to see every divergence, even if it is microscopic, or increase it if you want to see only strong divergences. In my experience 0.005 gives good results.


input bar = 4;
input filter = 0.005;

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

def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;

def SwingHigh = Diff > 0 and Diff >= highest(Diff[1], bar) and Diff >= highest(Diff[-bar], bar);
def SHprice = if SwingHigh then Diff else SHprice[1];
def SHBar = if SwingHigh then BarNumber() else SHBar[1];
def CrossBarL = if Diff crosses below 0 then BarNumber() else CrossBarL[1];

def SwingLow = Diff < 0 and Diff <= lowest(Diff[1], bar) and Diff <= lowest(Diff[-bar], bar);
def SLprice = if SwingLow then Diff else SLprice[1];
def SLBar = if SwingLow then BarNumber() else SLBar[1];
def CrossBarH = if Diff crosses above 0 then BarNumber() else CrossBarH[1];

def SHSP = if SwingHigh then high else SHSP[1];
def SLSP = if SwingLow then low else SLSP[1];

def BearDiv = Diff > 0 and CrossBarL[1] > SHBar[1] and Diff < SHprice[1] and high > SHSP[1] and SHprice[1] - Diff > filter;
def BullDiv = Diff < 0 and CrossBarH[1] > SLBar[1] and Diff > SLprice[1] and low < SLSP[1] and Diff - SLprice[1] > filter;
def HiddenBearDiv = Diff > 0 and Diff > SHprice[1] and high < SHSP[1] and Diff - SHprice[1] > filter;
def HiddenBullDiv = Diff < 0 and Diff < SLprice[1] and low > SLSP[1] and SLprice[1] - Diff > filter;

plot BearD = BearDiv[3];
Re: Fun with ThinkScript
April 02, 2016 06:29PM
Tanman, they at Thinkorswim told me to add a timeframe to each code. Is that something you know how to do? I know how to get into the code and change the timeframes myself, but as far as adding it initially is way beyond me. If you think you could take a shot at it I would really appreciate it. Thanks again for all your help.
Re: Fun with ThinkScript
April 02, 2016 09:18PM
Rob Miller,

Wherever "close" occurs in your code, change it to:

close(period = "5 min" ) for 5 minute time frame
close(period = "1 hour" ) for 1 hour time frame
close(period = "day" ) for daily time frame
close(period = "week" ) for weekly time frame
close(period = "month" ) for monthly time frame

You will have to write separate code and create separate watchlist for each time frame.



Edited 1 time(s). Last edit at 04/02/2016 09:18PM by tanman.
Re: Fun with ThinkScript
April 02, 2016 11:30PM
Tanman, Really some great work on that bear scan, can you create the bull scan ? It returns results on a 2 min chart but won't know for sure how well it scans realtime until market opens

I really like your study . I also input bar=4 and I like the results once again with lengths of 16,97,2. I also show your more standard lengths of 12,26,9

and it fits well with another MACD divergence study I posted below


It seems on back test then when they both fire to the bear side the pull back his highly probable but just like your original study I haven't been able to scan for the bear divergence or "divsignal" on this study, maybe you can break it apart like you did with your study and write a bear scan as well.
here's the MACD divergence study:


declare lower;

input fastEMA = 12;
input slowEMA = 26;
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
Re: Fun with ThinkScript
April 03, 2016 08:45AM
Jakesdad,

Thanks for your MACD divergence study! The difference is it gives the squeeze signal similar to TTM_Squeeze, because it is not a good idea to trade a divergence when the squeeze has fired. Reversion to mean strategies like MACD histogram divergence have a higher failure rate when there is a momentum breakout. Additionally it doesn't follow Alexander Elder's rule of zero line cross between the two divergent histogram peaks for actual divergence to be present. That is why it gives a few more signals and false positives are slightly more. His book is called "Two Roads Diverged, Trading Divergences". He says if zero line cross is not present between the divergent histogram peaks then divergence is merely a slowing down of momentum and not a true reversion to mean divergence. That is why fvaldez requested a divergence study taking into account Elder's rule, and coding for zero line cross between divergent histogram peaks was very tricky.


For bull divergence scan, replace last line with:

plot BullD = BullDiv[3];

You can also try [1] or [2] instead of [3].


For hidden bear divergence scan, replace last line with:

plot HiddenBearD = HiddenBearDiv[3];


For hidden bull divergence, replace last line with:

plot HiddenBullD = HiddenBullDiv[3];
Re: Fun with ThinkScript
April 03, 2016 11:51AM
thanks for the scan code Tanman, it works nice, did you look at the lengths I mentioned above? Also can you direct me to the rules on your high low divergence study? thanks
Re: Fun with ThinkScript
April 03, 2016 02:12PM
This should be simple enough but I can't figure out for the life of me how to plot only the last two signals of a simple swing peak like this

def Peak = high > Highest(high[1], 20) and high > Highest(high[-20], 20);


plot ArrowDOWN = Peak;
plot Signal = Peak;

I setup a counter and a label to get some feedback and I'm getting n/a as the output of the counter

def counter = if ArrowDOWN then counter[1] + 1 else counter[1];
addlabel(yes, "counter" + counter);

It does plot consecutively from the start to the end of the chart, but I'd like to just get the last two Peaks so as to get some visual aid as far as a possible trend line developing.

I'm also using EnableAproximation() to connect the peaks

plot Upperline = if ArrowDOWN then high else Double.NaN;
Upperline.EnableApproximation();


Any help would be much appreciated. Many thanks in advance!



Edited 1 time(s). Last edit at 04/03/2016 09:48PM by FluffyClouds.
Re: Fun with ThinkScript
April 03, 2016 08:59PM
Also! for some reason when extending the line it will only plot up to [x] bars previous to the current bar, so if the Peak def ( above ) is looking up 10 bars back, the extension will plot as expected but will always leave a space of 10 bars from where it plots to the current bar...

Just modifying a script I found here to show only the most recent two points and add alerts when the price breaches the extension

def Peak = high > Highest(high[1], 20) and high > Highest(high[-20], 20);


plot ArrowDOWN = Peak;
ArrowDOWN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDOWN.SetDefaultColor(Color.WHITE);
ArrowDOWN.SetLineWeight(1);


plot Upperline = if ArrowDOWN then high else Double.NaN;
Upperline.EnableApproximation();
Upperline.SetDefaultColor(Color.RED);
Upperline.SetLineWeight(1);


def UpperRun = if Peak then 1 else UpperRun[1] + 1;
def decline = if Peak then high - GetValue(high, UpperRun[1]) else Double.NaN;
def Upperslope = decline / UpperRun[1];


def UpperslopeX = if Peak then Upperslope else UpperslopeX[1];
def UpperlineX = if Peak then high else UpperlineX[1] + UpperslopeX;
plot UpperLineExtension = UpperlineX;
UpperLineExtension.SetDefaultColor(Color.WHITE);
UpperLineExtension.SetPaintingStrategy(PaintingStrategy.DASHES);


You can see what I mean on the attached picture...



Obviously alerts won't work unless the extensions plot all the way up to the current bar smiling smiley


Again Many thanks in advance!



Edited 3 time(s). Last edit at 04/03/2016 09:46PM by FluffyClouds.
Re: Fun with ThinkScript
April 04, 2016 07:25AM
Tanman. No where in the code does it say close , any other suggestions? Code is below, not sure where to enter . Thanks

"Wherever "close" occurs in your code, change it to:

close(period = "5 min" ) for 5 minute time frame
close(period = "1 hour" ) for 1 hour time frame
close(period = "day" ) for daily time frame
close(period = "week" ) for weekly time frame
close(period = "month" ) for monthly time frame "

###############################################################

input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};

def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
MA3 = ExpAverage(close, long_average);
}


plot Eup = if MA1 > MA2 && MA2 > MA3 then 1 else
0;
def Edn = if MA1 < MA2 && MA2 < MA3 then 1 else
0;


EUp.AssignvalueColor(IF Eup THEN COLOR.LIGHT_green
else if Edn then color.PINK ELSE Color.gray);

AssignbackgroundColor(IF Eup THEN
COLOR.LIGHT_green else if Edn then color.PINK ELSE
Color.gray);
Re: Fun with ThinkScript
April 04, 2016 12:38PM
I am looking for a scan that I can do before the market opens where the mark is is above the high or low of yesterdays range. Can that be done?
Re: Fun with ThinkScript
April 04, 2016 01:16PM
It would be really helpful if I could get an alert when the target and stop bubble appears. Is that possible?


Brakeout
Re: Fun with ThinkScript
April 04, 2016 05:41PM
Hi all! I've worked out extending the line to infinity using !isnan...

I would like to only plot the last two peaks of the following:

plot ArrowDOWN = Peak;
ArrowDOWN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDOWN.SetDefaultColor(Color.WHITE);
ArrowDOWN.SetLineWeight(1);


plot Upperline = if ArrowDOWN then high else Double.NaN;
Upperline.EnableApproximation();
Upperline.SetDefaultColor(Color.RED);
Upperline.SetLineWeight(1);

I know I have to Double.Nan everything before the last two peaks but can't figure out how....

Your help is greatly appreciated.



Edited 1 time(s). Last edit at 04/04/2016 08:05PM by FluffyClouds.
Re: Fun with ThinkScript
April 05, 2016 06:32PM
Rob Miller,

6 lines in your code contain the variable "close".

For example:

MA1 = Average(close, short_average);

For 5 minute time frame, change it to:

MA1 = Average(close(period = "5 min" ), short_average);
Re: Fun with ThinkScript
April 05, 2016 06:37PM
FluffyClouds,

In TOS, click on Support/Chat in top right corner and then click on Chat Rooms and then thinkscriptLounge. Over there please ask Mobius to help you out with any advanced thinkscript problem. He is the best thinkscript code writer I have seen and should be able to help you out. If he cannot do something then no one can!
Re: Fun with ThinkScript
April 05, 2016 06:51PM
Texas John,

Try this for above yesterday high:

plot AboveY = close > high(period ="day" )[1];


For below yesterday low:

plot BelowY = close < low(period = "day" )[1];


For Target bubble alert try this:

alert(decisionL[1], getsymbol() + " Time to go short", alert.bar, sound.bell);
alert(decisionH[1], getsymbol() + " Time to go long", alert.bar, sound.bell);
Re: Fun with ThinkScript
April 05, 2016 09:01PM
Tanman, thanks.

Yes Mobius has help me a out a bit, just though I tried to figure it out on my own and also try other sources before I reach out to him again....

BUT! really? referencing a specific number of instances of a condition is advanced?? To tell you the truth almost anything is advanced for me as I've barely scratched the surface. The examples and tutorials on the learning center are fairly simple even for me, they need to update it with more examples, I figured I'm probably not the only one who's wanted to reference a specific number of past instances and that would be a good tutorial to have smiling smiley

Thanks Tanman.

Anyone else wants to chime in, if I wanted to reference the last two instances of simple sma crossover for example??

plot Data = close[1] < Average(close, 20)[1] and close > Average(close, 20);
Data.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_UP);
Re: Fun with ThinkScript
April 06, 2016 07:13AM
Tanman,

Thanks for the help.
Re: Fun with ThinkScript
April 07, 2016 09:27AM
thanks Tanman, duh. I wasnt paying attention.
Re: Fun with ThinkScript
April 07, 2016 03:09PM
Hey guys,

Long time admirer first time requestor here.

I've been working with an old Robert study from several years ago.

This is the study that plots the blue up and yellow down arrows based on several factors that are beyond my coding capabilities.

My question is: Is it possible to modify this script so that arrows show up when the green SMA line (ln1) crosses BELOW the blue SMA line line (ln 2) instead of where it currently plots the blue arrows?

The current blue line seems to be a bit lagged as it shows up a few bars after where I'm looking for it to show up.

I think this has something to do with the [1] vs [-1] code but I can't be sure.

I will post a screenshot of where I'd like the indicator to show up (purple arrow pointing down) on my next post.

Any help on this would be greatly appreciated.

This is truly an amazing thread.

Here is the code in question:

declare upper;
input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};
input showArrows = yes;

def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
MA3 = ExpAverage(close, long_average);
}

# define e-signal and crossover point
def Eup = MA1 > MA2 && MA2 > MA3;
def Edn = MA1 < MA2 && MA2 < MA3;

def CrossUp = close > MA1 && Eup && !Eup[1];
def CrossDn = close < MA1 && Edn && !Edn[1];

# Define up and down signals
def higherHigh = close > Highest(Max(open, close), 3)[1];
def lowerLow = close < Lowest(Min(open, close), 3)[1];
def SignalUp = if (CrossUp && higherHigh)
then 1
else if (CrossUp[1] && higherHigh && !higherHigh[1])
then 1
else if (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
then 1
else Double.NaN;
def SignalDn = if (CrossDn && lowerLow)
then 1
else if (CrossDn[1] && lowerLow && !lowerLow[1])
then 1
else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2])
then 1
else Double.NaN;

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(CreateColor(145, 210, 144));
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(CreateColor(111, 183, 214));
ln2.SetLineWeight(2);
plot ln3 = MA3;
ln3.SetDefaultColor(CreateColor(249, 140, 182));
ln3.SetLineWeight(2);

# Show an arrow
plot ArrowUp = if SignalUp and showArrows then low * 0.997 else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUp.SetLineWeight(4);
ArrowUp.SetDefaultColor(Color.YELLOW);
plot ArrowDn = if SignalDn and showArrows then high * 1.003 else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ArrowDn.SetLineWeight(4);
ArrowDn.SetDefaultColor(Color.CYAN);

# Add label for Eup or Edn
AddLabel(Eup, "E Up", CreateColor(134, 202, 93));
AddLabel(Edn, "E Dn", CreateColor(232, 148, 157));

# Calculate Meter Values
def sl1 = ma1 > ma1[1];
def sl2 = ma2 > ma2[1];
def sl3 = ma3 > ma3[1];
def p1 = close > ma1;
def p2 = close > ma2;
def p3 = close > ma3;
def u1 = 2 * (close > open);
def u2 = 2 * (close > high[1]);
def d1 = 2 * (close < open);
def d2 = 2 * (close < low[1]);

def UPstr = sl1 + sl2 + sl3 + p1 + p2 + p3 + u1 + u2;
def DNstr = !sl1 + !sl2 + !sl3 + !p1 +!p2 + !p3 + d1 + d2;

# Add Strength Meter
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 3 then CreateColor(128, 199, 94) else if Edn and DNstr >= 3 then CreateColor(232, 143, 153) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 6 then CreateColor(99, 197, 72) else if Edn and DNstr >= 6 then CreateColor(238, 123, 136) else CreateColor(177,177,166));
AddLabel(Eup or Edn, " ", if Eup and UPstr >= 8 then CreateColor(65, 195, 50) else if Edn and DNstr >= 8 then CreateColor(245, 101, 117) else CreateColor(177,177,166));
Re: Fun with ThinkScript
April 07, 2016 03:55PM
Does anyone know how to code a Put vs Call volume indicator. Basically showing the Put/ Call volume on any timeframe?



Edited 7 time(s). Last edit at 04/08/2016 03:13PM by Kamadi.
Re: Fun with ThinkScript
April 07, 2016 04:21PM
Sorry guys I was unable to paste the screenshot of where I'd like the arrows to go.

If anyone is able to assist it would be greatly appreciated.

Thanks!
Re: Fun with ThinkScript
April 07, 2016 06:28PM
Hello all great site
I want to create a simple code TOS for both a scan and upper chart signal to enter and exit trades.
A trader gave me this and i have seen this work on a live chart.
I have tried several times to write the code and cant get all three bars in the pattern
appreciate any help
Kevin

BR= 3 bar reversal. It’s a candlestick pattern. At a trading top, it will look like this:
Bar #1 is an up bar.
Bar #2 is a down bar, and the high of Bar #2 is higher than the close of Bar #1.
Bar #3 is a down bar, and the close of Bar #3 is lower than the open of Bar #1.
The inverse occurs at trading bottoms.
These can also occur in the middle of a trending move, after a countertrend wave is complete, and when that happens, it’s signaling the continuation of the current trend.
This pattern occurs on all time frames, but I have found that the hourly gives the best risk/reward setup. At a trading top, the trading strategy is to go short at the close of Bar #3, and place a stop one tick above the high of Bar #2.



Edited 1 time(s). Last edit at 04/07/2016 06:30PM by kevinmick.
JML
Re: Fun with ThinkScript
April 08, 2016 09:26AM
Tanman or anyone else...

Looking for a script that when in pit hours 9:30 to 4:15 EST, hourly candles would change one hour after pit open therefore 10:30 , 11:30 ect. instead of changing at the top of the hour like it does default. Can anyone help with this, thanks
Re: Fun with ThinkScript
April 08, 2016 03:09PM
########################################



Edited 1 time(s). Last edit at 04/08/2016 03:10PM by Kamadi.
Re: Fun with ThinkScript
April 08, 2016 03:11PM
Can anyone PLEASE help me with this. I use the double moving avg crossover to make trades. Ive managed to put both double moving avges together in one script but I can get it to show an arrow when the two points cross. I would like an Up/Down arrow when double moving avg 1 crosses the other. Here is the scripts. Not sure why the smiley faces shows up. But where you see them replace with a closed parenthesis

input displace = 0;
input MA1_length = 1;
input MA2_length = 5;
input price = close;

DefineGlobalColor("RisingMA", color.blue);
DefineGlobalColor("FallingMA", color.red);

input movingAverageType1 = {default Hull, Simple, Exponential, Weighted, Variable};
input movingAverageType2 = {default Exponential, Variable, Simple, Weighted, Hull};

def data1;

switch (movingAverageType1) {
case Simple:
data1 = compoundValue(1, Average(price[-displace], MA1_length), price);
case Exponential:
data1 = compoundValue(1, ExpAverage(price[-displace], MA1_length), price);
case Weighted:
data1 = compoundValue(1, wma(price[-displace], MA1_length), price);
case Hull:
data1 = compoundValue(1, hullMovingAvg(price[-displace], MA1_length), price);
case Variable:
data1 = compoundValue(1, VariableMA(price = price, length = MA1_length), price);
}

plot DoubleMA;

switch (movingAverageType2) {
case Simple:
DoubleMA = compoundValue(1, Average(data1[-displace], MA2_length), data1);
case Exponential:
DoubleMA = compoundValue(1, ExpAverage(data1[-displace], MA2_length), data1);
case Weighted:
DoubleMA = compoundValue(1, wma(data1[-displace], MA2_length), data1);
case Hull:
DoubleMA = compoundValue(1, hullMovingAvg(data1[-displace], MA2_length), data1);
case Variable:
DoubleMA = compoundValue(1, VariableMA( data1, MA2_length), data1);
}

DoubleMA.SetLineWeight(4);
DoubleMA.AssignValueColor(if DoubleMA > DoubleMA[1] then globalColor("RisingMA"winking smiley else globalColor("FallingMA"winking smiley);
DoubleMA.HideBubble();
#########################################################################
# Second Moving Avg
input displace1 = 0;
input MA1_length1 = 3;
input MA2_length1 = 6;
input price1 = close;

DefineGlobalColor("RisingMA1", color.blue);
DefineGlobalColor("FallingMA1", color.red);

input movingAverageType3 = {default Hull, Simple, Exponential, Weighted, Variable};
input movingAverageType4 = {default Exponential, Variable, Simple, Weighted, Hull};

def data2;

switch (movingAverageType3) {
case Simple:
data2 = compoundValue(1, Average(price1[-displace1], MA1_length1), price1);
case Exponential:
data2 = compoundValue(1, ExpAverage(price1[-displace1], MA1_length1), price1);
case Weighted:
data2 = compoundValue(1, wma(price1[-displace1], MA1_length1), price1);
case Hull:
data2 = compoundValue(1, hullMovingAvg(price1[-displace1], MA1_length1), price1);
case Variable:
data2 = compoundValue(1, VariableMA(price = price1, length = MA1_length1), price1);
}

plot DoubleMA8;

switch (movingAverageType4) {
case Simple:
DoubleMA8 = compoundValue(1, Average(data2[-displace1], MA2_length1), data2);
case Exponential:
DoubleMA8 = compoundValue(1, ExpAverage(data2[-displace1], MA2_length1), data2);
case Weighted:
DoubleMA8 = compoundValue(1, wma(data2[-displace1], MA2_length1), data2);
case Hull:
DoubleMA8 = compoundValue(1, hullMovingAvg(data2[-displace1], MA2_length1), data2);
case Variable:
DoubleMA8 = compoundValue(1, VariableMA( data2, MA2_length1), data2);
}

DoubleMA8.SetLineWeight(2);
DoubleMA8.AssignValueColor(if DoubleMA8 > DoubleMA8[1] then globalColor("RisingMA"winking smiley else globalColor("FallingMA"winking smiley;
DoubleMA8.HideBubble();

########################################################################
JML
Re: Fun with ThinkScript
April 08, 2016 06:35PM
JML Wrote:
-------------------------------------------------------
> Tanman or anyone else...
>
> Looking for a script that when in pit hours 9:30
> to 4:15 EST, hourly candles would change one hour
> after pit open therefore 10:30 , 11:30 ect.
> instead of changing at the top of the hour like it
> does default. Can anyone help with this, thanks

Please forget this request, got it figured out thanks
JML
Sorry, only registered users may post in this forum.

Click here to login