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
January 06, 2016 10:09AM
no need to yell!
Re: Fun with ThinkScript
January 06, 2016 04:36PM
Can anyone please help me on my requested script
Re: Fun with ThinkScript
January 06, 2016 07:11PM
Quote
tanman
# long and short signal formula
def OBV = TotalSum(Sign(close - close[1]) *volume);
def OBVUP = OBV > OBV[1];
def OBVDN = OBV < OBV[1];

Tanman what's the reason you use TotalSum in this case? It looks like difference of OBV and OBV[1] would be the difference of current bar volume and the very first bar volume of the chart. It seems kind of irrelevant comparing these two volumes.
Re: Fun with ThinkScript
January 07, 2016 12:40PM
Kamadi,

You are welcome! Thanks for the kind words. Unfortunately I am still learning thinkscript and don't know how to convert it to a scan. But I think it can be done theoretically. I think it would be on the lines of def variable = if conditions are met (which I have already coded) ..... then 1 else 0; and then running the scan for all stocks in which variable = 1
Re: Fun with ThinkScript
January 07, 2016 12:47PM
howo3579,

That's how OBV is coded in TOS. Open studies and then click on "edit studies", then scroll down to OnBalanceVolume study, then left click on it and click "view" and you will get the original code for OBV already programmed in TOS. I merely copied that original code. Then I defined OBV increasing if OBV at current bar is greater than the previous bar (OBV[1] means the previous bar, not the first bar).



Edited 1 time(s). Last edit at 01/07/2016 12:48PM by tanman.
Re: Fun with ThinkScript
January 07, 2016 01:35PM
RobertC,

Yes you did it correctly (with 1000 shares).

It appears you placed stop loss of 0.15 on a 2 minute chart, which is almost equal to ATR. I usually use ATR x 1.5 on the 2 minute chart (because ATR x 1 is more likely to be hit), or just below last swing low, whichever is greater. ATR x 1.5 was 0.20 so the stop loss would have been 43.61 - 0.2 = 43.41. The last swing low was 43.39 and stop loss below it would have been 43.38 which is 0.23 below entry price. So in this case I would have preferred stop loss at 43.38 and target increments of 0.23 (same as stop loss). First profit target would have been 43.84 to close 1/2 position and second profit target 44.07 to close full position. With 1000 shares, this would have given a profit of $115 for 500 shares + $230 for remaining 500 shares = $345, while risking $230.

I do not risk more than 0.5% of my total account equity on a single day trade. Risking $230 in the above example would require an account of $46,000 for risk of 0.5%. For example, if account size is $30,000 then buy 650 shares in the above trade to risk 0.5%.

You can also use the resistance at day's high at that time of 44.04 as a second profit target which would make sense. Whenever I enter trades I also keep an eye on the closest resistance based on the current time frame price action or the closest daily time frame moving average (for example daily 8 EMA, 21 EMA, 55 EMA etc.) for a profit target point or exit point. I raise stop loss to entry price as soon as first profit target of ATR x 1.5 is hit to lock in a profit no matter what happens. If after the first profit target is hit, the second profit target of ATR x 3, or closest resistance is not hit and price begins to pullback, then I use 2 closes below 8 EMA or stop loss at entry price (whichever is closer) as final exit point.

You can also use the 2 closes below 8 EMA as the final exit point (to keep the remaining 1/2 position as a runner to capture maximum profit), instead of ATR x 3 as the second profit target, if there is a strong intraday trend.

You can also choose to skip the trade if a strong resistance (daily high, previous swing high, 30 minute open range high, previous day high, daily EMA etc.) is very close to the entry price, or enter only if that close resistance is broken (If resistance is less than ATR x 1.5 from entry price).



Edited 2 time(s). Last edit at 01/07/2016 04:57PM by tanman.
Re: Fun with ThinkScript
January 07, 2016 04:53PM
Can anyone help me put the following code into a scan for when the sell signal appears?


# Short_123_Reversal


# Inputs
input price = close;
input length = 9;
input length2 = 20;
input maType = {default Weighted, Exponential, Simple, Wilders, Hull};

# Input Moving Average types
def ma = ExpAverage(price, length);

def ma2 = ExpAverage(price, length2);


# Set crossthreshold according to aggregationPeriod
def thrUp =
if getAggregationPeriod() == AggregationPeriod.WEEK
then 0.005
else if getAggregationPeriod() == AggregationPeriod.DAY
then 0.0025
else if getAggregationPeriod() == AggregationPeriod.HOUR
then 0.0015
else 0.00125;

def thrDn =
if getAggregationPeriod() == AggregationPeriod.WEEK
then 0.005
else if getAggregationPeriod() == AggregationPeriod.DAY
then 0.0025
else if getAggregationPeriod() == AggregationPeriod.HOUR
then 0.0015
else 0.00125;

# Price CrossOver
def up = close > ((1 + thrUp) * ma) and close[1] <= ((1 + thrUp) * ma[1]);
rec barUp = if up then barNumber() else if isNaN(barUp[1]) then barNumber() else barUp[1];

# Price CrossUnder
def down = close < ((1 - thrDn) * ma2) and close[1] >= ((1 - thrDn) * ma2[1]);
rec barDown = if down then barNumber() else if isNaN(barDown[1]) then barNumber() else barDown[1];

#cross

def condition1 = open > ma;
def condition2 = close < ma2;
def condition3 = condition1 and condition2;

##### Plotting Peaks and Valleys
input magnitude = 3;


# define and plot the most recent peak
def peak = high >= Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude);
def peakvalue = if BarNumber() < magnitude then Double.NaN else if peak then high else peakvalue[1];
plot peakline = peakvalue;
peakline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peakline.SetDefaultColor(Color.GREEN);

# extend the current peak line to the right edge of the chart
def countp = if IsNaN(peak) and !IsNaN(peak[1]) then 1 else countp[1] + 1;
plot peakext = if IsNaN(peak) then GetValue(peakline, countp) else Double.NaN;
peakext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peakext.SetDefaultColor(Color.GREEN);

# continue the previous peak as a dashed line
def oldpeak = if BarNumber() < magnitude then Double.NaN else if peak then peakvalue[1] else oldpeak[1];
plot oldpeakline = oldpeak;
oldpeakline.SetPaintingStrategy(PaintingStrategy.DASHES);
oldpeakline.SetDefaultColor(Color.GREEN);

def condition4 = (peak < peak[1]) and (condition3 is true);





# Sell Signal
plot sell = if condition4 and (if isNaN(barDown[1]) then 1 else if barDown[1] <= barUp then 1 else 0) then 1 else 0;
sell.setDefaultColor(color.BLUE);
sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#Trigger alerts

alert(sell, "Price CrossUnder", Alert.Bar, Sound.Ring);


Re: Fun with ThinkScript
January 07, 2016 05:44PM
Tanman,

On the ATR are you using a standard 14 length and Wilder Average? LVS worked great today, but I was using a 3 length on ATR. What other stocks work well with this code. I can't seem to find others that work like LVS.

Great work
Re: Fun with ThinkScript
January 07, 2016 05:48PM
brazilianpillar , if you're asking how to use the scanner I can help. Otherwise not. For using the scanner I notice if I scan for ALL STOCKS the scanner chokes on a TIMEOUT error. I figure that's because of the complexity of your code, size of selected market (I first chose ALL STOCKS), bar range for signal occurence (I first chose 1 bar), and price range. I finally got some results (65) with these settings:
NASDAQ, abt $2 - $33, Sell Plot IS TRUE, Signal Within 4 bars.
Bottom line, I think changing parameters will give you better results. Hope this helps. Bom dia!
=================================
brazilianpillar Wrote:
-------------------------------------------------------
> Can anyone help me put the following code into a
> scan for when the sell signal appears?
>
>
> # Sell Signal
> plot sell = if condition4 and (if
> isNaN(barDown[1]) then 1 else if barDown[1] <=
> barUp then 1 else 0) then 1 else 0;
> sell.setDefaultColor(color.BLUE);
> sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_
> ARROW_DOWN);
>
> #Trigger alerts
>
> alert(sell, "Price CrossUnder", Alert.Bar,
> Sound.Ring);
>
>
>
Re: Fun with ThinkScript
January 08, 2016 02:22PM
RobertC,

I use Wilders Average and 6 length on ATR for lower time frame charts (5 minutes and lower), and Wilders Average and 14 length on ATR for daily time frame charts.

I have a watch list of stocks for intraday breakout trading which has been giving good results with the long tailed candle breakout strategy also, especially on 2 minute charts. Following is my watch list:

AAL, LVS, STX, YHOO, BBY, ANF, MOS, GPS, JBLU, MGM, TWTR, FEYE, GPRO, VIPS, MU, HTZ, P, BBRY, SUNE

These stocks satisfy the following parameters which makes them low priced for smaller accounts, very liquid and excellent intraday movers with minimal slippage on entry and exit. I keep updating my stock watch list depending on these parameters.

Price < $50
Daily average volume > 3,000,000
Daily ATR% > 3%
Bid-Ask spread = 1-2 cents

Almost all these stocks had winning long tailed candle breakout signals today. If you study all the signals in these stocks you will find high percentage of winners. I avoid signals which are against direction of SPY, or occur after extended moves, or close to resistance for long entry or support for short entry, or in the dreaded lunch hour. I watch for the following resistance/support areas, which my code automatically draws for me:

1. Previous day high, low, and pivot point
2. 30 minute opening range high and low
3. Intraday high and low
4. Daily ATR high and low price levels
5. Daily 8, 21, 55, 200 EMA price levels
6. 10 and 30 day high and low

If you go through all the signals triggered today in these stocks on my watch list, you will notice that if you had avoided signals against direction of SPY, or occurring after extended moves, or close to any of the above support/resistance areas, or the dreaded lunch hour, you would have eliminated almost all losing or marginal signals (which were a low percentage to start with).

Following code will give you all the above mentioned support and resistance levels (colors look best on white background and you can change colors in the code for black background):



# Plot opening range high/low and add cloud
script OpenRange {
input ORtime = 5;

def FirstBar = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60;
def RangeTime = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime;
def Rhigh = if FirstBar then high else if RangeTime and high > Rhigh[1] then high else Rhigh[1];
def Rlow = if FirstBar then low else if RangeTime and low < Rlow[1] then low else Rlow[1];

plot h = if RangeTime or SecondsTillTime(0930) > 0 then Double.NaN else Rhigh;
plot l = if RangeTime or SecondsTillTime(0930) > 0 then Double.NaN else Rlow;
}

def today = GetLastDay() == GetDay();
def ATR = WildersAverage(TrueRange(high, close, low), 6);

plot h30 = if !today then Double.NaN else OpenRange(30).h;
h30.SetDefaultColor(Color.GRAY);
plot l30 = if !today then Double.NaN else OpenRange(30).l;
l30.SetDefaultColor(Color.MAGENTA);

AddCloud(h30, l30, Color.LIGHT_GREEN);

# Plot yesterday's high/low
plot Yhigh = if !today then Double.NaN else high(period = "day" )[1];
Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.UPTICK);
Yhigh.SetLineWeight(2);
plot Ylow = if !today then Double.NaN else low(period = "day" )[1];
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.DOWNTICK);
Ylow.SetLineWeight(2);

# Plot pivot point
plot Pivot = if !today then Double.NaN else (high(period = "day" )[1] + low(period = "day" )[1] + close(period = "day" )[1]) / 3;
Pivot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Pivot.SetDefaultColor(Color.ORANGE);
Pivot.SetLineWeight(1);

# Plot 10 day and 30 day high/low
plot TenHigh = if !today then Double.NaN else Highest(high(period = "day" )[1], 10);
TenHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenHigh.SetDefaultColor(Color.UPTICK);
TenHigh.SetLineWeight(3);
plot ThirtyHigh = if !today then Double.NaN else Highest(high(period = "day" )[1], 30);
ThirtyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ThirtyHigh.SetDefaultColor(Color.UPTICK);
ThirtyHigh.SetLineWeight(3);
plot TenLow = if !today then Double.NaN else Lowest(low(period = "day" )[1], 10);
TenLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TenLow.SetDefaultColor(Color.DOWNTICK);
TenLow.SetLineWeight(3);
plot ThirtyLow = if !today then Double.NaN else Lowest(low(period = "day" )[1], 30);
ThirtyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ThirtyLow.SetDefaultColor(Color.DOWNTICK);
ThirtyLow.SetLineWeight(3);

# Plot intraday high and intraday low based on candle body
def h3 = close > Highest(close[-3], 3);
def dayHigh = if GetDay() != GetDay()[1] then max(open, close) else if h3 and close > dayHigh[1] then max
(open, close) else dayHigh[1];
def l3 = close < Lowest(close[-3], 3);
def dayLow = if GetDay() != GetDay()[1] then min(open, close) else if l3 and close < dayLow[1] then min(open,
close) else dayLow[1];

plot DH = if !today then Double.NaN else dayHigh;
DH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DH.SetDefaultColor(Color.UPTICK);
def countp = if IsNaN(dayHigh) and !IsNaN(dayHigh[1]) then 1 else countp[1] + 1;
plot peakext = if IsNaN(dayHigh) then GetValue(DH, countp) else Double.NaN;
peakext.SetPaintingStrategy
(PaintingStrategy.HORIZONTAL);
peakext.SetDefaultColor(Color.UPTICK);
plot DL = if !today then Double.NaN else dayLow;
DL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DL.SetDefaultColor(Color.DOWNTICK);
def countt = if IsNaN(dayLow) and !IsNaN(dayLow[1]) then 1 else countt[1] + 1;
plot valleyext = if IsNaN(dayLow) then GetValue(DL, countt) else Double.NaN;
valleyext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
valleyext.SetDefaultColor(Color.DOWNTICK);

# Plot daily ATR Range Levels
def DATR = WildersAverage(TrueRange(high(period = "day" ), close(period = "day" ), low(period = "day" )),
14);

plot UB = if today then low(period = "day" ) + DATR else Double.NaN;
UB.SetDefaultColor(Color.DOWNTICK);
UB.SetPaintingStrategy(PaintingStrategy.DASHES);
UB.SetStyle(Curve.SHORT_DASH);
plot LB = if today then high(period = "day" ) - DATR else Double.NaN;
LB.SetDefaultColor(Color.UPTICK);
LB.SetPaintingStrategy(PaintingStrategy.DASHES);
LB.SetStyle(Curve.SHORT_DASH);

# Plot daily moving average levels
def day2 = GetDay() > GetLastDay() - 2 and GetYear() == GetLastYear();
plot D200MA = if !day2 then double.NaN else ExpAverage(close(period = "day" ), 200);
D200MA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
D200MA.SetDefaultColor(Color.BLUE);
D200MA.SetLineWeight(1);
plot D55MA = if !day2 then double.NaN else ExpAverage(close(period = "day" ), 55);
D55MA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
D55MA.SetDefaultColor(Color.MAGENTA);
D55MA.SetLineWeight(1);
plot D21MA = if !day2 then double.Nan else ExpAverage(close(period = "day" ), 21);
D21MA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
D21MA.SetDefaultColor(Color.DARK_GREEN);
D21MA.SetLineWeight(1);
plot D8MA = if !day2 then double.NaN else ExpAverage(close(period = "day" ), 8);
D8MA.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
D8MA.SetDefaultColor(Color.DARK_GRAY);
D8MA.SetLineWeight(1);

# Add labels
AddLabel(yes, "30MH = " + Round(h30, 2), color.GRAY);
AddLabel(yes, "30ML = " + Round(l30, 2), color.MAGENTA);
AddLabel(yes, "IDH = " + Round(dayHigh[3], 2), color.UPTICK);
AddLabel(yes, "IDL = " + Round(dayLow[3], 2), color.DOWNTICK);
AddLabel(yes, "DATRH = " + Round(UB, 2), color.DOWNTICK);
AddLabel(yes, "DATRL = " + Round(LB, 2), color.UPTICK);
AddLabel(yes, "YH = " + Round(Yhigh, 2), color.UPTICK);
AddLabel(yes, "YL = " + Round(Ylow, 2), color.DOWNTICK);
AddLabel(yes, "PP = " + Round(Pivot, 2), color.ORANGE);
AddLabel(yes, "10DH = " + Round(TenHigh, 2), color.UPTICK);
AddLabel(yes, "10DL = " + Round(TenLow, 2), color.DOWNTICK);
AddLabel(yes, "30DH = " + Round(ThirtyHigh, 2), color.UPTICK);
AddLabel(yes, "30DL = " + Round(ThirtyLow, 2), color.DOWNTICK);
AddLabel(yes, "D8EMA = " + Round(D8MA, 2), color.DARK_GRAY);
AddLabel(yes, "D21EMA = " + Round(D21MA, 2), color.DARK_GREEN);
AddLabel(yes, "D55EMA = " + Round(D55MA, 2), color.MAGENTA);
AddLabel(yes, "D200EMA = " + Round(D200MA, 2), color.BLUE);




Advice for all readers: You should paper trade first and test any strategy/system yourself to see if it wins and master it before trading with real money. My posts, stock watch list and examples, and codes are for educational purposes only and do not constitute a recommendation to trade those stocks/equities or strategies. The holy grail of trading is patience, discipline and money management which includes mastering STEEP (stop loss, targets, entries, exits and position sizing) and not letting emotions, greed or fear influence you. The same strategy that could be a winner for one could become a loser for another due to these factors.

Hope that helps.



Edited 2 time(s). Last edit at 01/08/2016 03:45PM by tanman.
Re: Fun with ThinkScript
January 13, 2016 12:01PM
Robert,

I sent a PM would you please take a look into it.
Re: Fun with ThinkScript
January 13, 2016 12:47PM
Friends,

Please help me with the following, this is just a part of my project...

I am trying to get exact price when the condition is meet...

def buySignal = sma[0] > sma [1];
plot BUY = if buySignal then close else double.nan;
BUY.setDefaultColor(color.CYAN);
BUY.setLineWeight(5);
BUY.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);

What above code snippet plots is a triangle at the close of current bar when buySignal condition is meet isn't it?

What I am trying to get is exact price when that condition is meet not close or open or hlc3 etc.

I am aware that price might get repainted several times before bar is closed but that's what I want to find out...
Re: Fun with ThinkScript
January 13, 2016 04:47PM
Quote
mdaprasad
> I am trying to get exact price when the condition
> is meet...
>... What above code snippet plots is a triangle at the
> close of current bar when buySignal condition is
> meet isn't it?...
> What I am trying to get is exact price when that
> condition is meet not close or open or hlc3 etc.
>... I am aware that price might get repainted several
> times before bar is closed but that's what I want
> to find out...
mdaprasad, the way you wrote the code you'll get a signal for as long as the condition is True, i.e., continuous triangles. If you only want a signal when the condition first happens, then you want "crosses above" , not the ">" as you wrote it. Maybe I misunderstand but what I think is you want a signal for when the sma first curves upward, right? And you want the exact price for when that happens. You also want to know if the signal may come and go during the current bar; the answer is Yes. You've specified to display triangle at current Close when condition is True, and whatever the price is on the current bar is for the moment the Close. So the first time you see the triangle, that's the "exact price" when the condition is first True. But if you can't watch, you may want to set up an Alert, which would record when it was first True. I added two lines (in Blue) to help me see what was going on. Hope this helps.
def sma = average(close,5);
def buySignal = sma[0] crosses above sma [1];
plot mysma = sma;
plot BUY = if buySignal then close else double.nan;
BUY.setDefaultColor(color.CYAN);
BUY.setLineWeight(5);
BUY.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);



Edited 1 time(s). Last edit at 01/13/2016 04:49PM by baffled1.
Re: Fun with ThinkScript
January 13, 2016 05:13PM
Thanks baffled1, I really appreciate your time

even sma[0] crosses above sma[1] works but as I said I want the exact price or a triangle/line/bubble with exact price when that condition is meet.

"So the first time you see the triangle, that's the "exact price" when the condition is first True. But if you can't watch, you may want to set up an Alert, which would record when it was first True"

Above is helpful but can we store is somewhere on the chart via label/bubble or just a simple text it would be wonderful if I can store all those values and plot it in the same graph...
Re: Fun with ThinkScript
January 13, 2016 08:16PM
mdaprasad, sorry- bubbles are beyond me right now. Best I can suggest is their manual for bubbles at https://tlc.thinkorswim.com/center/charting/thinkscript/reference/Functions/Look---Feel/AddChartBubble
confused smiley
Re: Fun with ThinkScript
January 13, 2016 11:35PM
Alert is also not any help because it is just printing time and text...maybe I have to explore if I can take that time and find out price but not sure how to do it.
Re: Fun with ThinkScript
January 14, 2016 12:29AM
Maybe drill down to the 1-minute chart?
Re: Fun with ThinkScript
January 14, 2016 10:10AM
Hi Everyone.

Using the "AddChartBubble" function in TOS, does anyone know how to clamp that to a line on a chart? Like the ZigZag line for instance. When using something like the ZigZag line, I'd like to be able to latch the addchartbubble window the the center of that line. That way I can make it look more like the Autowave line in Qcharts. Is there anyone that can brief me on how to do that?
Re: Fun with ThinkScript
January 14, 2016 10:28AM
baffled1 Wrote:
-------------------------------------------------------
> Maybe drill down to the 1-minute chart?

Not needed somehow yesterday price was not showing up but not now I can see price information in Message Center....one step ahead, I guess what I have to do is collect each signal in rec variable and plot it. I have to find a way to do it, I hope I can do that.
Re: Fun with ThinkScript
January 14, 2016 12:38PM
mdaprasad and RichieRick, wish I could help with bubbles but can't. mdaprasad, if you're really desperate maybe use a spreadsheet? Been awhile since I did that but I'm sure you could find the commands easily.
Re: Fun with ThinkScript
January 14, 2016 04:43PM
baffled1 Wrote:
-------------------------------------------------------
> mdaprasad and RichieRick, wish I could help with
> bubbles but can't. mdaprasad, if you're really
> desperate maybe use a spreadsheet? Been awhile
> since I did that but I'm sure you could find the
> commands easily.

Spreadsheet? You mean we can transfer alerts data to spread sheet? I am not aware of this functionality..
Re: Fun with ThinkScript
January 14, 2016 05:19PM
Quote
mdaprasad
> Spreadsheet? You mean we can transfer alerts data
> to spread sheet? I am not aware of this
> functionality..
No, I meant get original price data someplace and put in a spreadsheet and create your algo in the spreadsheet then you could collect the data you want. But actually I came back here just now to give you something that "may" help with bubbles. I was looking for something else when I ran across it: http://investorshub.advfn.com/boards/read_msg.aspx?message_id=81374423 .
RichieRick, this "may" help you too.
Re: Fun with ThinkScript
January 14, 2016 09:54PM
baffled1 Wrote:
-------------------------------------------------------
> > > Spreadsheet? You mean we can transfer alerts
> data
> > to spread sheet? I am not aware of this
> > functionality..
>
> No, I meant get original price data someplace and
> put in a spreadsheet and create your algo in the
> spreadsheet then you could collect the data you
> want. But actually I came back here just now to
> give you something that "may" help with bubbles. I
> was looking for something else when I ran across
> it:
> [investorshub.advfn.com]
> ?message_id=81374423 .
> RichieRick, this "may" help you too.


Awesome!!! I'll go and check it out. Thanks!

I just read through that script you linked. Sadly there isn't anything I can use from it. Thanks anyways though smiling smiley



Edited 1 time(s). Last edit at 01/14/2016 10:01PM by RichieRick.
Re: Fun with ThinkScript
January 15, 2016 01:15PM
Sorry it didn't work out, RichieRick. I'll keep my eyes peeled.

Gamblers roll the dice; Traders load the dice.
JML
help with a script....
January 19, 2016 08:22AM
This is what I am looking for:
plot a line for the Friday 4pm EST close till the next Friday at 4 pm
plot the ATR value as a line above and below the Friday close.

If someone can help me with this, it would be appreciate.

Jack L
Re: Fun with ThinkScript
January 19, 2016 01:32PM
Jack L,

Let me know if this is what you wanted. It plots the Friday 4 pm close as a horizontal blue line with daily ATR values as horizontal dashed gray lines above and below the Friday close. These horizontal dashed lines will fluctuate from day to day depending on daily ATR values. Next week, these lines will be erased and new appropriate lines will be plotted. You can change the colors in the code itself to your liking.

def ThisWeek = GetWeek() == GetLastWeek();
def DATR = WildersAverage(TrueRange(high(period = "day" ), close(period = "day" ), low(period = "day" )),
14);

plot FridayClose = if !ThisWeek then Double.NaN else close(period = "week" )[1];
FridayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
FridayClose.SetDefaultColor(Color.BLUE);
FridayClose.SetLineWeight(2);
plot UB = if !ThisWeek then Double.NaN else close(period = "week" )[1] + DATR;
UB.SetPaintingStrategy(PaintingStrategy.DASHES);
UB.SetDefaultColor(Color.GRAY);
UB.SetLineWeight(1);
plot LB = if !ThisWeek then Double.NaN else close(period = "week" )[1] - DATR;
LB.SetPaintingStrategy(PaintingStrategy.DASHES);
LB.SetDefaultColor(Color.GRAY);
LB.SetLineWeight(1);



Edited 1 time(s). Last edit at 01/19/2016 01:37PM by tanman.
JML
Re: Fun with ThinkScript
January 19, 2016 07:14PM
Thanks Tanman

This is good but I would like the Friday 4 pm EST ATR value to stay the same for the whole week and not fluctuate daily.
Is that possible? Also can you add lines above and below for twice and 3 times the ATR value?

Thanks again for taking the time to help me out.

Jack L
Re: Fun with ThinkScript
January 20, 2016 05:45PM
Jack L,

Try this code. It will plot the Friday ATR value only; 3 dashed green ATR lines at ATR, ATR x 2 and ATR x 3 above the Friday close, and 3 dashed red ATR lines at ATR, ATR x 2 and ATR x 3 below the Friday close.



def ThisWeek = GetWeek() == GetLastWeek();
def DATR = WildersAverage(TrueRange(high(period = "day" ), close(period = "day" ), low(period = "day" )), 14);
def FridayATR = if GetDayOfWeek(getYYYYMMDD()) == 5 then DATR else FridayATR[1];

plot FridayClose = if !ThisWeek then Double.NaN else close(period = "week" )[1];
FridayClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);FridayClose.SetDefaultColor(Color.BLUE);
FridayClose.SetLineWeight(2);

plot UB = if !ThisWeek then Double.NaN else close(period = "week" )[1] + FridayATR;
UB.SetPaintingStrategy(PaintingStrategy.DASHES);
UB.SetDefaultColor(Color.UPTICK);
UB.SetLineWeight(1);
plot UB1 = if !ThisWeek then Double.NaN else close(period = "week" )[1] + FridayATR*2;
UB1.SetPaintingStrategy(PaintingStrategy.DASHES);
UB1.SetDefaultColor(Color.UPTICK);
UB1.SetLineWeight(1);
plot UB2 = if !ThisWeek then Double.NaN else close(period = "week" )[1] + FridayATR*3;
UB2.SetPaintingStrategy(PaintingStrategy.DASHES);
UB2.SetDefaultColor(Color.UPTICK);
UB2.SetLineWeight(1);

plot LB = if !ThisWeek then Double.NaN else close(period = "week" )[1] - FridayATR;
LB.SetPaintingStrategy(PaintingStrategy.DASHES);
LB.SetDefaultColor(Color.DOWNTICK);
LB.SetLineWeight(1);
plot LB1 = if !ThisWeek then Double.NaN else close(period = "week" )[1] - FridayATR*2;
LB1.SetPaintingStrategy(PaintingStrategy.DASHES);
LB1.SetDefaultColor(Color.DOWNTICK);
LB1.SetLineWeight(1);
plot LB2 = if !ThisWeek then Double.NaN else close(period = "week" )[1] - FridayATR*3;
LB2.SetPaintingStrategy(PaintingStrategy.DASHES);
LB2.SetDefaultColor(Color.DOWNTICK);
LB2.SetLineWeight(1);



Edited 2 time(s). Last edit at 01/20/2016 05:46PM by tanman.
JML
Re: Fun with ThinkScript
January 20, 2016 07:00PM
Perfect!!
Thanks Tanman
Programming Indicators Request
January 20, 2016 05:34PM
Hey,

I was wondering if I could get a quote for coding a few trading indicators, I have the indicators along with the formulas listed below

1) Regression Line Fractal Framework-this can be built in a spread
sheet I think?

Price: 10 Period Regression Line Current Price

Price: 270 Period Regression Line Current Price

Raw Opportunity=10 Period-270 Period Current Price

Reward: Opportunity %=Raw Opportunity/Current Price

Risk: ATR %=1x ATR (10)/Current Price

Opportunity Ratio=ATR's available, Opportunity %/ATR %, which gives a
standardized risk/reward

Reward: % distance between RL10 and RL270, opportunity is based on
reversion to the 270

Risk: normalized at 1x ATR
Video: [www.youtube.com]
[www.youtube.com]

2) Min/Max Pain-Range Compression Scanner Consolidations

10 Day Min Pain-Top 5-10 Symbols that have lost the least % of the 10 Day High

10 Day Max Pain-Top 5-10 Symbols that have lost the most % of the 10 Day High

3) Intraday Statistics


Rangestat:

a. acronym: Rstat (see daily report)

b. main idea: the maximum reasonable intraday move. We think of this as the limit of “Rational Exuberance” since only 1/6 of the previous 30 trading days experienced a larger intraday move.

c. Technique: based on the formula: AverageRange(30d) + 1 StDev of Range.

d. Preference: consider moves beyond the Rangestat intraday as “a gift”. Don’t give back professional profits earned in moves of less than a Rangestat ; don’t chase irrational exuberance, just decide how much you want to keep of it while preserving your professional profits



. Gapstat:

a. acronym: Gapstat (see daily report)

b. main idea: measure the size of the gaps of the last 30 days and describe them statistically in order to classify the current opening as a large, normal or small gap day. There is a persistent correlation between the size of the gap and the size of the follow-thru, but not the direction. In other words: large gaps correlate with large follow-throughs for the rest of the day, but the direction of the large move is not predictable.

c. Technique:

1. Compute: Close(-1) – Open(0)/Open(0) for the last 30 and 200 trading days.

2. Find: Max, Min, Average, and StDev.

3. Define LargeGap as a gap > Avg + 1StDev, Smallgap as Gap < Avg – 1 StDev, otherwise Normal gap.

4. On LargeGap days you shouldn’t be surprised if you see a move >= to Rangestat.

5. On SmallGap days be prepared for big results from SQC technique

d. Preference: Know this for all proposed trading targets. Prefer intraday targets with largest relative gaps.



Failstat:

a. acronym: Failstat (see daily report)

b. main idea: measure the distance from Open to LOD each day for the last 30 trading days. Compute statistics to identify the AverageFail. Be alert to morning reversals if there are signs of finding support after a gap down, and a selloff of a Failstat. That would be a normal place to reverse intraday after the opening 0-30 minutes

c. Technique: LargeGap days may go more than a Failstat without surprising us, SmallGap days may reverse sooner than a Failstat selloff.

d. Preference: Know this for all proposed trading targets. Look for support around a Failstat below the Open on gap-down days.



Gainstat:

a. acronym: Failstat (see daily report)

b. main idea: measure the distance from Open to HOD each day for the last 30 trading days. Compute statistics to identify the AverageGain. Be alert to morning reversals if there are signs of finding resistance after a gap up and a gains up to the Gainstat price level.. That would be a normal place to reverse intraday after the opening 0-30 minutes

c. Technique: LargeGap days may go more than a Gainstat without surprising us, SmallGap days may reverse sooner than a Gainstat up.

d. Preference: Know this for all proposed trading targets. Look for resistance around a Gainstat above the Open on gap-up days.


Signal:Noise ratio:

a. acronym: S/Nratio

b. main idea: measure the average size of the real body of the last 30 days and compare to the AverageRange of the last 30 days. The real body = signal, the wicks = Noise.

c. Technique: Signal/Range will be a number between 0 and 1 Compute for a population of peers to compare.

d. Preference: Know this for all proposed trading targets. Prefer intraday targets with largest S/N. For intraday trading, favor those with a higher relative S/N ratio because the intraday trends are more pure signal, more directional.
.
4) FQN FQN-Frog Quality Ratio >= 3 minimum, greater is better, also tells
me 1 Standard Deviation Frog Number

Calculate the FQN for all members of the sample population, using the
formula: AvgDailyRange(30) / StDev(30)

Focus intraday attention to the targets with the highest FQN value, to
create trade frames with the targets that have the highest expected
reward: risk ratios

Wait for 30 min after the open to make an entry decision

Evaluate the “froggish” candidates to select the most directional
target to enter,

Any instrument that has a high FQN (3.0 or above)

I was wondering a quote on the price of these indicators as a stand alone coded in tradestation easylanguage and possibly also into TDAmeritrade Thinkscript

I appreciate it, and thank you in advance



Edited 1 time(s). Last edit at 01/20/2016 05:35PM by socialintelligence99.
Sorry, only registered users may post in this forum.

Click here to login