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
May 16, 2017 07:58AM
I have a code for an inside bar. Does anyone know how to get it to color (paint bar) only after the bar closes as a true inside bar?

Also put that code in a watch-list so it will flag only after the bar closes? Thanks



plot Data = close;
def insideBar = if
(High[0] < High[1] && Low[0] > Low[1])

then
yes else no;

input price = close;

plot insideBarFlag = double.nan;

insideBarFlag.DefineColor("insidebarcolor", color.blue);

AssignPriceColor(if insideBar then insideBarFlag.color("insidebarcolor"winking smiley else
color.current);

# // End of script
Re: Fun with ThinkScript
May 22, 2017 02:17PM
" All of your drawings will be saved automatically and immediately, and they are stored in the cloud so, no matter where you log in to your thinkorswim, [you have no privacy]. "


and you can never completely delete any drawings.

the only way to retain your privacy is to never draw anything on your charts again ... ever.



Edited 2 time(s). Last edit at 05/22/2017 02:30PM by radingt.
Re: Fun with ThinkScript
May 24, 2017 06:42PM
I agree with your sentiment. This has to be the worst "upgrade" ever.

radingt Wrote:
-------------------------------------------------------
> " All of your drawings will be saved
> automatically and immediately, and they are stored
> in the cloud so, no matter where you log in to
> your thinkorswim, . "
>
>
> and you can never completely delete any drawings.
>
> the only way to retain your privacy is to never
> draw anything on your charts again ... ever.
Re: Fun with ThinkScript
May 30, 2017 09:44AM
Does anyone know if there's a way to write this script so it will give the lowest close for the day (instead of the lowest low)?

Low("period" = AggregationPeriod.DAY)

If not is there another script that will show the lowest close for the day during market hours? Thanks,
Re: Fun with ThinkScript
May 30, 2017 06:56PM
Deleted



Edited 5 time(s). Last edit at 06/12/2017 06:54PM by maru.
Re: Fun with ThinkScript
May 30, 2017 07:10PM
Deleted



Edited 3 time(s). Last edit at 06/12/2017 06:55PM by maru.
Re: Fun with ThinkScript
May 31, 2017 02:27PM
I'm attempting to add a 15min aggregation to the original TRIX indicator. Can anyone here please help me with this task?

Quote

declare lower;

input length = 9;
input colorNormLength = 14;
input price = close;
input signalLength = 3;

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), length), length), length);

plot TRIX = (tr - tr[1]) * 10000;
plot Signal = ExpAverage(TRIX, signalLength);
plot ZeroLine = 0;

TRIX.DefineColor("Highest", Color.YELLOW);
TRIX.DefineColor("Lowest", Color.LIGHT_RED);
TRIX.AssignNormGradientColor(colorNormLength, TRIX.color("Lowest" ), TRIX.color("Highest" ));
Signal.setDefaultColor(GetColor(3));
ZeroLine.SetDefaultColor(GetColor(5));


My line of thinking is that the aggregation line has to be placed in this portion of the code:
Quote

def tr = ExpAverage(ExpAverage(ExpAverage(Log(price), length), length), length);

however I can't figure it out...


Any help on this would be GREATLY appreciated!!!



Edited 3 time(s). Last edit at 06/12/2017 06:58PM by maru.
ALMA (moving average) in thinkscript
June 05, 2017 01:32PM
Has anyone been able to code the Arnaud Legoux moving average (ALMA) in Thinkscript?

I find this one appealing because its based on normal distribution. From what I can tell, when compared to other moving averages, it gives the best speed, with the best smoothness, and does it objectively (similar to splines). It's very similar to the Hull moving average, but does not have the overshoot (error) that Hull does.

It seems this moving average has been coded for most other platforms. I can't seem to find it for thinkscript.

I've attempted to recreate it using the code from other platforms as a guide, but have yet to be successful.
Re: Fun with ThinkScript
June 09, 2017 03:47PM
In the following code I would like the line to be drawn right beneath the low of the defined length. As is sometimes the scaling is a little out of whack:

def lineLength = length;
def barNumber = BarNumber();
def barCount = highestAll(If(IsNaN(close), 0, barNumber));
def closeLine = if barNumber == 1 then Double.NaN else if barNumber == barCount - lineLength then close[-lineLength] else if barNumber == barCount then Double.NaN else closeLine[1];
plot data = closeLine*.99;
data.SetPaintingStrategy(PaintingStrategy.dASHES);
LBJ
Re: Fun with ThinkScript
June 16, 2017 02:32PM
Was hoping somebody could help me with a thinkscript question.

As an example lets say that when the close of bar X is greater than the previous day high on the chart i want to check from that point forward to the current bar for a condition, aka lets say that I want to see if the lowest low on any bars in the future is lower than the close of the bar X.

I am having trouble finding the code that would allow me to search for that condition as part of the code.

Thank you in advance for any help!
Scan a candle closing below 9 ema
June 16, 2017 08:17PM
Hello Robert

I am new to forum and thinkscript coding... I main focus on price action..

I want to scan a candle closing below 9ema also making sure the previous candle is red (close below open)...

Also how the code works for identifying position of moving average? I mean ema 9 should be below ema20

Thanks
Jack
Trading Sessions Indicator
June 17, 2017 05:59PM
Hi there...GREAT site...I have not able to find a suitable Trading Sessions Indicator for TOS...Halfwaybacktrading has one that might work with some modification...

Trying to plot H/L for the Trading Sessions London/New York/Sydney/Tokyo...
Only problem, it does not plot all the time frames properly...




Can anyone help?


Here is the code


# BWD_TradingWindows
#
# Author: BigWaveDave
# Bugs? support@halfwaybacktrading.com
#
# Description:
# Will not work correctly on tick aggregation period charts
# Or > 30 minute aggregation period charts
# I have no idea why this doesn't work on 1 or 4 hour charts...
# Anybody?
# I use this study mostly on the euro futures. So the default windows
# are for the european markets. This is an enhanced version of
# your typical trading windows study which attempts to illustrate the
# highs and lows of the window visually. I find it useful to help
# understand
# how an instrument moves within a trading window. The euro futures
# often trade their high or low of the day at or near the open. This
# study makes that easy to see. This study automates the task of having
# to manually draw rectangles around the trading windows and ranges.
# It also illustrates just how slow the euro gets after the european close.
# Makes it easy to see when you should be actively trading and when you
# should not.
# It's my first script so I'm sure there's room for improvement.
#
# Version 1.2 - 4/5/12
# + Added cloud color to be user configurable via 'global' in settings
#
# Version 1.1 - 3/12/12
# + Added code to adjust windows for DST differential between
# europe and the USA automagically. On by default. If
# you're not looking at a european instrument, turn it off.
# Even with it off, this new code hurts performance, no doubt.
# Feel free to rip it out if you don't care about it...
# Version 1.0 - 3/11/12
# + Initial Release



input DrawTradingWindowsForToday = yes;
input DisplayRangeHighAndLowTimes = yes;
input TradingWindowOpenTime = 0300;
input TradingWindowCloseTime = 1130;
input NoTradingWindowOpenTime = 1130;
input NoTradingWindowCloseTime = 1600;
input EnableDSTAutoAdjust = yes;
input DSTOffsetHours = 1;

#==========================================================================
# Figure out DST adjustment for diffence between USA and europe
#==========================================================================
#basically, if we are after the 2nd Sunday in March and before
#the last Sunday in March, we need to offset the Trading Windows by 1hr forward
#if we are after the last Sunday in Oct, until the 1st Sunday in Nov
# we need to offset the trading windows by 1hr backward...
def CurrentYear = getYear();
def CurrentMonth = getMonth();
def CurrentDOM = getDayOfMonth(getYyyyMmDd());

#What is the first day of the week for the 1st of this month?
def Day1DOW1 = getDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
def FirstSundayDOM1 = if Day1DOW1 < 7
then 7 - Day1DOW1 + 1
else 1;

def SecondSundayOfMonth = FirstSundayDOM1 + 7;
def isMarch = if (CurrentMonth == 3, 1, 0);
def SpringDSTShiftStart = if (isMarch and (SecondSundayOfMonth <= CurrentDOM), 1, 0);

#last sunday in march...
def SpringDSTShiftStop = if (isMarch and ((SecondSundayOfMonth + 14) > CurrentDOM), 1, 0);
def DoSpringShift = if (SpringDSTShiftStart and SpringDSTShiftStop and EnableDSTAutoAdjust, 1, 0);

def isOctober = if (CurrentMonth == 10, 1, 0);
def isNovember = if (CurrentMonth == 11, 1, 0);
def FallDSTShiftStart = if (isOctober and ((SecondSundayOfMonth + 14) <= CurrentDOM), 1, 0);
def FallDSTShiftStop = if (isNovember and FirstSundayDOM1 > CurrentDOM, 1, 0);
def DoFallShift = if (FallDSTShiftStart or FallDSTShiftStop and EnableDSTAutoAdjust, 1, 0);

def DSTOffsetAdjustment = if (DoSpringShift, DSTOffsetHours * 100, if (DoFallShift, -DSTOffsetHours * 100, 0));


#==========================================================================
# Determine and then plot the Trading Windows
#==========================================================================
#constants
def MinutesInADay = 60 * 24;

# Ok, figure out how many candles in each 'window'
# store aggregation period for current chart as 'minutes'
def MinutesPerCandle = (getAggregationPeriod() / 1000) / 60;

def TradingWindowOpenTimeOffset = TradingWindowOpenTime + DSTOffsetAdjustment;
def TradingWindowCloseTimeOffset = TradingWindowCloseTime + DSTOffsetAdjustment;
def NoTradingWindowOpenTimeOffset = NoTradingWindowOpenTime + DSTOffsetAdjustment;
def NoTradingWindowCloseTimeOffset = NoTradingWindowCloseTime + DSTOffsetAdjustment;

def TradingWindowOpenMinutes = (Floor(TradingWindowOpenTimeOffset / 100) * 60) + (TradingWindowOpenTimeOffset % 100);
def TradingWindowCloseMinutes = (Floor(TradingWindowCloseTimeOffset / 100) * 60) + (TradingWindowCloseTimeOffset % 100);

# get the bar count for the TradingWindow
def TradingWindowCandleCount = Floor((TradingWindowCloseMinutes - TradingWindowOpenMinutes) / MinutesPerCandle);

def NoTradingWindowOpenMinutes = (Floor(NoTradingWindowOpenTimeOffset / 100) * 60) + (NoTradingWindowOpenTimeOffset % 100);
def NoTradingWindowCloseMinutes = (Floor(NoTradingWindowCloseTimeOffset / 100) * 60) + (NoTradingWindowCloseTimeOffset % 100);

# get the bar count for the NoTradingWindow
def NoTradingWindowCandleCount = Floor((NoTradingWindowCloseMinutes - NoTradingWindowOpenMinutes) / MinutesPerCandle);

def isToday = if(getDay() == getLastDay(), 1, 0);

#PITA. SecondsTillTime only takes constants... Need to manually adjust for DST if it's enabled.
def DSTAdjust = if (DoSpringShift, DSTOffsetHours * 3600, if (DoFallShift, -DSTOffsetHours * 3600, 0));

def bTradingWindowOpen = if((secondsTillTime(TradingWindowOpenTime) + DSTAdjust > 0), 0, 1);
def bTradingWindowClosed = if((secondsTillTime(TradingWindowCloseTime) + DSTAdjust > 0), 0, 1);
def bOkToTradeWindow = if(bTradingWindowOpen and !bTradingWindowClosed, 1, 0);

def bNoTradingWindowOpen = if((secondsTillTime(NoTradingWindowOpenTime) + DSTAdjust > 0), 0, 1);
def bNoTradingWindowClosed = if((secondsTillTime(NoTradingWindowCloseTime) + DSTAdjust > 0), 0, 1);
def bNotOkToTradeWindow = if(bNoTradingWindowOpen and !bNoTradingWindowClosed, 1, 0);

# Do some prepping for converting BarNumber() into a time...
def CandlesPerDay = (60 * 24) / MinutesPerCandle;
def CandlesPerHour = CandlesPerDay / 24;

# Ok, now for the real pain in the tukkus.
# On the very first bar of a 'window' we need to look forward
# to setup the high and low for the window. For all subsequent bars
# in the window, we'll simply use the same high and low that
# we found during our first bar processing...
def bFirstTradingWindowBar = if ((bOkToTradeWindow and !bOkToTradeWindow[1]) or (bNotOkToTradeWindow and !bNotOkToTradeWindow[1]), 1, 0);

# The guts. Do something so seemingly simple... Figure out the high and low for the 'forward' range
def loop = if (bOkToTradeWindow, TradingWindowCandleCount, NoTradingWindowCandleCount);

#really hackey way to get this thing to loop based on anything but an input variable. Basically, set the actual fold <end> value really high and use the exit <while> condition to test the loop count and force an exit when the 'real' loop count is reached or we hit an empty 'right bar'.
rec RangeHigh = if (bFirstTradingWindowBar, (fold index = 0 to MinutesInADay with dHigh = high while (index < loop and !IsNaN(getValue(open, -index))) do if getValue(high, -index) > dHigh then getValue(high, -index) else dHigh),
if (high > RangeHigh[1], high, RangeHigh[1]));

rec RangeLow = if (bFirstTradingWindowBar, (fold index1 = 0 to MinutesInADay with dLow = low while (index1 < loop and !IsNaN(getValue(open, -index1))) do if getValue(low, -index1) < dLow then getValue(low, -index1) else dLow),
if (low < RangeLow[1], low, RangeLow[1]));

#Ok we have the data... now decide whether or not to draw it
plot TradingWindowHigh;
plot TradingWindowLow;
plot NoTradingWindowHigh;
plot NoTradingWindowLow;

if (bOkToTradeWindow and ((DrawTradingWindowsForToday and isToday) or !isToday))
{
TradingWindowHigh = RangeHigh;
TradingWindowLow = RangeLow;
NoTradingWindowHigh = double.nan;
NoTradingWindowLow = double.nan;
}
else if (bNotOkToTradeWindow and ((DrawTradingWindowsForToday and isToday) or !isToday))
{
TradingWindowHigh = double.nan;
TradingWindowLow = double.nan;
NoTradingWindowHigh = RangeHigh;
NoTradingWindowLow = RangeLow;
}
else
{
TradingWindowHigh = double.nan;
TradingWindowLow = double.nan;
NoTradingWindowHigh = double.nan;
NoTradingWindowLow = double.nan;
}

#what? no easy way to get the time of a bar?
#Figure out the bar offset from the start of our known window start time.
rec WindowStartBar = if (bFirstTradingWindowBar, barNumber(), WindowStartBar[1]);

#What's the offset from the start of the Trading Window?
#How about the offset of the start of the trading window itself?
def AdjustedBarNumber = (TradingWindowOpenMinutes / MinutesPerCandle) + (barNumber() - WindowStartBar);

#Oh the humanity. Oh the hackery.
def Hours = Floor(AdjustedBarNumber / CandlesPerHour);
def Minutes10s = Floor(((AdjustedBarNumber % CandlesPerHour) * MinutesPerCandle) / 10);
def Minutes1s = ((AdjustedBarNumber % CandlesPerHour) * MinutesPerCandle) % 10;

# need to track if we have already displayed a bubble for this range's high
# and low
rec RangeHighBubbleExists = compoundValue(1, if (bFirstTradingWindowBar[-1], 0, if (DisplayRangeHighAndLowTimes and bOkToTradeWindow and (high == TradingWindowHigh), 1, RangeHighBubbleExists[1])), 0);
rec RangeLowBubbleExists = compoundValue(1, if (bFirstTradingWindowBar[-1], 0, if (DisplayRangeHighAndLowTimes and bOkToTradeWindow and (low == TradingWindowLow), 1, RangeLowBubbleExists[1])), 0);

# no way to easily do leading zeros? drat.
# what a hack.
AddChartBubble(DisplayRangeHighAndLowTimes and bOkToTradeWindow and (high == TradingWindowHigh) and !RangeHighBubbleExists[1], high,
concat(concat(concat(Hours, ":"winking smiley, Minutes10s), Minutes1s), color.dark_green);

AddChartBubble(DisplayRangeHighAndLowTimes and bOkToTradeWindow and (low == TradingWindowLow) and !RangeLowBubbleExists[1], low, concat(concat(concat(Hours, ":"winking smiley, Minutes10s), Minutes1s), color.dark_red, no);

TradingWindowHigh.SetDefaultColor(color.dark_green);
TradingWindowLow.SetDefaultColor(color.dark_green);
NoTradingWindowHigh.SetDefaultColor(color.dark_red);
NoTradingWindowLow.SetDefaultColor(color.dark_red);

#Hide some things we don't really want to show unless the user overrides us in the settings...
#TradingWindowHigh.hidePricePlot(yes);
TradingWindowHigh.HideBubble();
TradingWindowHigh.HideTitle();

#TradingWindowLow.hidePricePlot(yes);
TradingWindowLow.HideBubble();
TradingWindowLow.HideTitle();

#NoTradingWindowHigh.hidePricePlot(yes);
NoTradingWindowHigh.HideBubble();
NoTradingWindowHigh.HideTitle();

#NoTradingWindowLow.hidePricePlot(yes);
NoTradingWindowLow.HideBubble();
NoTradingWindowLow.HideTitle();

DefineGlobalColor("Trade Zone Color", color.dark_green);
DefineGlobalColor("No Trade Zone Color", color.dark_red);

AddCloud(TradingWindowHigh, TradingWindowLow, globalColor("Trade Zone Color"winking smiley, globalColor("Trade Zone Color"winking smiley);
AddCloud(NoTradingWindowHigh, NoTradingWindowLow, globalColor("No Trade Zone Color"winking smiley, globalColor("No Trade Zone Color"winking smiley);
Wolfe Wave Indicator
June 18, 2017 08:17PM
Hi, can someone share TOS polynomial regression channel and the wolfe wave indicators if they have, I really appreciate your help, thanks
Re: Wolfe Wave Indicator
June 25, 2017 02:08AM
Counting Bars in Moving average
June 25, 2017 02:06AM
Hello id like to be able to count the last 10 bars in moving average of volume.

exmaple :

last 10 bars moving average = 15,000
last 10 bars volume = 5000

I dont want to just count the bars, i want to count the difference in volume average and current volume in the last 10 bars at 1 mintue 1 day.
Re: Fun with ThinkScript
July 01, 2017 05:45PM
I need just the 'open' part of this script to use the daily Aggregation (close AGG = MIN);


def X = Round(close(“GOOG"winking smiley - open(“GOOG”)[1]);

I can’t figure out how to add a day Aggregation script to it so TOS will accept it;

("period" = AggregationPeriod.DAY)


Does anyone know how to do this? Thanks.
Re: Fun with ThinkScript
July 02, 2017 04:41AM
Quote
Ralph53
I need just the 'open' part of this script to use the daily Aggregation (close AGG = MIN);

def X = Round(close(“GOOG" ) - open(“GOOG”)[1]);

I can’t figure out how to add a day Aggregation script to it so TOS will accept it;

("period" = AggregationPeriod.DAY)

Does anyone know how to do this? Thanks.

def x = Round(close("GOOG" ) - open("GOOG", period = "day" )[1]);

- robert


Professional ThinkorSwim indicators for the average Joe



Edited 2 time(s). Last edit at 07/02/2017 07:26AM by robert.
Re: Fun with ThinkScript
July 02, 2017 04:45AM
Quote
kalthetrader
Hello id like to be able to count the last 10 bars in moving average of volume.

exmaple :

last 10 bars moving average = 15,000
last 10 bars volume = 5000

I dont want to just count the bars, i want to count the difference in volume average and current volume in the last 10 bars at 1 mintue 1 day.

def avgVol = Average(volume, 10);
def diff = volume - avgVol;
def sumDiff = Sum(diff, 10);

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
July 02, 2017 07:30AM
Quote
jackmantos
Hello Robert

I am new to forum and thinkscript coding... I main focus on price action..

I want to scan a candle closing below 9ema also making sure the previous candle is red (close below open)...

Thanks
Jack

def ema9 = ExpAverage(close, 9);
def redCandle = close < open;
plot scan = redCandle[1] and close crosses below ema9;

- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
July 02, 2017 09:57AM
Any help to solve the problem with this code (Gann's Square of Nine ), the chart became folded !!

#
input period = aggregationPeriod.TEN_MIN;
plot sl = low(period = period);

sl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
sl.SetDefaultColor(Color.Green);
def data45 = -sqrt(sl)+ (45/180);
def data1 = power(data45, .00025);
plot line45 = data1;
line45.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line45.SetDefaultColor(Color.red);

def data90 = sqrt(sl)+ (90/180);
def data2 = power(data90, .00025);
plot line90 = data2;
line90.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line90.SetDefaultColor(Color.red);

def data135 = sqrt(sl)+ (135/180);
def data3 = power(data135, .00025);
plot line135 = data3;
line135.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line135.SetDefaultColor(Color.red);


def data180 = sqrt(sl)+ (180/180);
def data4 = power(data180, .00025);
plot line180 = data4;
line180.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line180.SetDefaultColor(Color.red);


def data225 = sqrt(sl)+ (225/180);
def data5 = power(data225, .00026);
plot line225 = data5;
line225.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line225.SetDefaultColor(Color.red);


def data270 = sqrt(sl)+ (270/180);
def data6 = power(data270, .00025);
plot line270 = data6;
line270.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line270.SetDefaultColor(Color.red);


def data315 = sqrt(sl)+ (315/180);
def data7 = power(data315, .00025);
plot line315 = data7;
line315.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line315.SetDefaultColor(Color.red);

def data360 = sqrt(sl)+ (360/180);
def data8 = power(data360, .00025);
plot line360 = data8;
line360.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line360.SetDefaultColor(Color.red);
#
Re: Fun with ThinkScript
July 03, 2017 12:40PM
Thanks, Robert. Do you know a way to get this similar script to work?

def X = SimpleMovingAvg("goog"winking smiley - SimpleMovingAvg("goog"winking smiley[1];


(Where's your tip jar these days?)
Re: Fun with ThinkScript
August 07, 2017 01:41PM
Hi All,

I'm new here and have a simple question. From the TS manual I found the following:

..."AddOrder(type, condition, price, tradeSize, tickColor, arrowColor, name);
Aside from previously described “type” and “condition”, arguments also include price, trade size, tick color, arrow color and name. Argument “price” defines price at which the order is added (by default, it is the Open of the following bar),"...

So a CONDITION is met and the order is executed on THE NEXT BAR.

Is there a way to specify that the order is executed when the condition is met and not on the following bar.

Thank you in advance for any help.

R
Re: Fun with ThinkScript
August 07, 2017 02:02PM
Hi Robert, Is there anyway to modify this code to include any candle that closes inside the previous candle? Right now it shows inside bars, Id like to add another color (paint bar) if it wicks above / below but still closes inside the previous bar. Thank you


plot Data = close;
def insideBar = if
(High[0] < High[1] && Low[0] > Low[1])

then
yes else no;

input price = close;

plot insideBarFlag = double.nan;

insideBarFlag.DefineColor("insidebarcolor", color.blue);

AssignPriceColor(if insideBar then insideBarFlag.color("insidebarcolor"winking smiley else
color.current);

# // End of script
Volume Bar questions
August 08, 2017 01:55PM
Hey guys great blog, I am looking for a volume indicator that only plots bars that have above average volume. I would like them to show red for down bars and green for up bars. I have tried everything I know and no luck. This would be a blank indicator on days that had no bars over the average volume say on a 5 minute time frame, would like to be able to change time frames though. I know I can rub to pieces of coal together long enough and I will have a diamond also.


TY
Kelly
plot line between current low and prior low
August 11, 2017 03:41PM
I may be late to the game, as this thread doesn't seem very active lately... but I thought I would post my question anyway.

First, thank you all for the information provided here. It has been very helpful in getting my feet wet with thinkscript and learning some basic things I can write.

    [*] I want to plot a line between current low and prior low.
      [*] by reading through this thread I found the recursive variable to count the bars.
      [*] def run = if Valley then 1 else run[1] + 1;
    [*] Using that I have been able to access the historical low value I want.
      [*] but I cannot seem to figure out the plot syntax to put a line between the two.

one would think drawing a line between point A and point B would be a simple task; but then again thinkscript does seem overtly complicated.

Thank you in advance for any help you may be able to provide.

Marshal
Re: Fun with ThinkScript
September 04, 2017 01:57PM
Rasna Wrote:
-------------------------------------------------------
> Hi All,
>
> I'm new here and have a simple question. From the
> TS manual I found the following:
>
> ..."AddOrder(type, condition, price, tradeSize,
> tickColor, arrowColor, name);
> Aside from previously described “type” and
> “condition”, arguments also include price,
> trade size, tick color, arrow color and name.
> Argument “price” defines price at which the
> order is added (by default, it is the Open of the
> following bar),"...
>
> So a CONDITION is met and the order is executed on
> THE NEXT BAR.
>
> Is there a way to specify that the order is
> executed when the condition is met and not on the
> following bar.
>
> Thank you in advance for any help.
>
> R


Rasna -- You'd want to be specific about the actual price at which the condition is met, then place the "price" one bar back.
For example, if you wanted to buy the value of a moving average as price crosses it, it'd look something like this....

def Avg = average(close, 20);
plot TickAvg = round(Avg / ticksize(), 0) * ticksize();

** you have to be sure the value you're buying is an actual price at which you can buy - for instance, in the ES, you can only buy 0.25.
** so, for this example, I've rounded the 20 period simple moving average to the closest tick size.
** then, the buy logic....

def BuySignal =
if high crosses above TickAvg
then TickAvg
else if close crosses above TickAvg
then TickAvg
else double.nan;

** this way, if any part of a bar crosses above the moving average, it's a buy signal....

addorder(
ordertype.BUY_AUTO,
BuySignal[-1],
BuySignal[-1],
name = “B: $“ +BuySignal[-1],
arrowcolor = color.green,
tickcolor = color. green);

** by using [-1], it places the buy signal AT the cross, not the following bar. Of course, you always have to check signal validity.
** in cases like gaps over the moving average, it'll show the buy at a price not buyable, if that makes sense.
Close of the highest volume bar
September 06, 2017 04:56AM
Hi Robert

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

Thanks
Rigel
mov. avg. formulas?
September 11, 2017 11:00AM
In the mov. avg. inputs they have many different choices like close, open, (H+L)/2, and so on.
What I was wondering how to do a mov. avg. with your own input formulas?
Like say have a mov. avg. that plots the the point between the mid-point of open and the close and the close?
Meaning if the close was 10 and the low was 6, the mid-point would be 8. So the avg. would be a 7 bar avg.
between mid-point8 an d close 10.
So it seems it would be?

Close +open /2 + Close/2
Not sure it that is correct or not?

Can anyone write a mov. avg. code to do the above?

Thanks,
Re: mov. avg. formulas?
September 11, 2017 12:25PM
After some thinking and head scratching, I figured it out. So I have what I need about the above post.
As an older non-programmer, it ain't easy.
I do have other stuff I may ask about if I can't figure it out.

Thanks,
Re: Fun with ThinkScript
September 12, 2017 08:52PM
Hi all,

I was wondering if anyone has a scan for red to green or green to red moves?

Thanks in advance
Sorry, only registered users may post in this forum.

Click here to login