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 29, 2017 09:55AM
InfectionX24,

Try using "Color.LIGHT_GREEN" and "Color.PINK" instead of GREEN and RED. If you don't like how that looks, use the CreateColor( R,G,B ) function to pick a color that is closer to the background color.

- robert


Professional ThinkorSwim indicators for the average Joe



Edited 1 time(s). Last edit at 01/29/2017 10:35AM by robert.
Re: Fun with ThinkScript
January 30, 2017 12:51AM
I have a question on the TOS editor. Im new to editing these types of things so this is a very newbish question, but how would I add extra lines on my lower studies (RSI MACD and DMI) in the editor itself.

UPDATE: Figured it out never mind.



Edited 1 time(s). Last edit at 01/30/2017 01:02AM by FTS919.
Re: Fun with ThinkScript
February 07, 2017 02:43AM
So I want my strategy to buy the next bar open after I get my signal. My report currently is showing buying at the bar that gives the signal but this is skewed because the signal might reverse during this bar.

So I want the report to show that I bought at 2287.25 and not 2286.25 in trade number 50.

If anyone knows how to do this please let me know!

Thanks so much!

Image below


[imgur.com]



Edited 1 time(s). Last edit at 02/07/2017 02:46AM by traderdunn.
Re: Fun with ThinkScript
February 10, 2017 09:27AM
HMM I have some code here but the BuyPrice is still not working


BuyPrice = if (your condition) then open[-1] else open[-2]

Can any one help?



Edited 1 time(s). Last edit at 02/10/2017 09:28AM by traderdunn.
Re: Fun with ThinkScript
February 10, 2017 08:33PM
Okay I figured it out. If anyone wants to know I put the -1 there to buy the next bar open after I got the signal. Same with the sell side.

AddOrder(OrderType.SELL_TO_CLOSE, exit_long, open[-1], tradeSize, Color.RED, Color.RED);
Re: Harmonic patterns
February 11, 2017 08:03PM
awesome update today robert on your harmonic pattern scripts! i was actually trying the other day (and failed) to create the target zones, so was excited to see that as part of your enhancements today! thanks and i hope you consider expanding your harmonic package to other patterns like 5-0, ab=cd, 3-drives, etc.

mike
Re: Fun with ThinkScript
February 12, 2017 05:23PM
I have two thinkscripts I'm trying to combine into one. They're are both for an inside bar. Id like it to paint the inside bar magenta if its a complete inside bar, and cyan if its an inside bar with equal Highs and/or lows as the previous bar. Anyone know how this can be done? 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


def insideBar = if (high[0] <= high[1] && low[0] >= low[1]) then yes else no;
def greenBar = close > open;

plot insideBarFlag = Double.NaN;
insideBarFlag.SetDefaultColor(GetColor(1));
insideBarFlag.DefineColor("insidebarcolor", Color.CURRENT);
AssignPriceColor(if insideBar then if greenBar then Color.cyan else Color.magenta else Color.CURRENT);
Re: Fun with ThinkScript
February 12, 2017 07:03PM
Quote
mntman
awesome update today robert on your harmonic pattern scripts! i was actually trying the other day (and failed) to create the target zones, so was excited to see that as part of your enhancements today! thanks and i hope you consider expanding your harmonic package to other patterns like 5-0, ab=cd, 3-drives, etc.

mike

Thanks, Mike. I'm happy to hear that you like it.

I've been thinking of adding some new harmonic patterns when I get the time.

Quote
rob miller
I have two thinkscripts I'm trying to combine into one. They're are both for an inside bar. Id like it to paint the inside bar magenta if its a complete inside bar, and cyan if its an inside bar with equal Highs and/or lows as the previous bar. Anyone know how this can be done? Thanks

def insideBar = high <= high[1] and low >= low[1];
def insideMatch = insideBar and (high == high[1] or low == low[1]);
AssignPriceColor(if insideMatch then Color.CYAN else if insideBar then Color.MAGENTA else Color.CURRENT);



- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
February 13, 2017 10:21AM
Thanks!
past earnings moves by points and %
February 13, 2017 12:55AM
Hi,
Does anyone aware of a script that will analyze the avg move in points and % of previous earnings for the last x earnings?
Thanks
Re: past earnings moves by points and %
February 13, 2017 03:03AM
Re: Fun with ThinkScript
February 13, 2017 07:31PM
robert, Is there any way to put this code ( Inside Bar ) into a watch list column that would flag a color if it was an inside bar? Much like your bollinger band watch list. But have it only flag it if it closes as an inside bar? (Otherwise it would flag constantly on the open of each bar, except for gaps)
Thank you very much
Re: Fun with ThinkScript
February 13, 2017 08:25PM
Robert, Is there a way to scan for closes above or below the highs/lows of a previous inside bar?
Re: Fun with ThinkScript
February 14, 2017 08:30AM
I've got this far for an inside bar in a watch list. But how do I assign color? Thanks



def insideBar = high < high[1] and low > low[1];

plot iBar = insideBar;
Re: Fun with ThinkScript
February 15, 2017 11:09AM
Maybe something like this...

plot insideBar = high < high[1] and low > low[1];

insideBar.AssignValueColor(if insideBar then Color.LIGHT_GREEN else Color.BLACK);
AssignBackgroundColor(if insideBar then Color.LIGHT_GREEN else Color.BLACK);
Re: Fun with ThinkScript
February 15, 2017 06:46PM
netarchitech, that didnt work. error codes. Any other suggestions?
Re: Fun with ThinkScript
February 15, 2017 07:19PM
Just wondering...are you inserting the thinkscript in a Custom Quote column?

If so, try the following to see if it works:

plot insideBar = high < high[1] and low > low[1];
def insideMatch = insideBar and (high == high[1] or low == low[1]);

AssignPriceColor(if insideMatch then Color.CYAN else if insideBar then Color.MAGENTA else Color.CURRENT);
AssignBackgroundColor(if insideMatch then Color.CYAN else if insideBar then Color.MAGENTA else Color.CURRENT);

Hope this helps...
Re: Fun with ThinkScript
February 16, 2017 08:29AM
Weird, some of them flagged a color and some didn't. For example, DOW and FB were inside bars yesterday, my scan pulled them up, painted the bar on the chart, but did not flag a color in the watch list.
Re: Fun with ThinkScript
February 16, 2017 08:31AM
Also, a ton of them pulled up and flagged magenta in the watchlist that are not inside bars.
Re: Fun with ThinkScript
February 16, 2017 03:38PM
hmmm...

maybe this...

plot insideBar = high < high[1] and low > low[1];
def insideMatch = insideBar and (high == high[1] or low == low[1]);

insideMatch.AssignPriceColor(if insideMatch then Color.CYAN else if insideBar then Color.MAGENTA else Color.CURRENT);
AssignBackgroundColor(if insideMatch then Color.CYAN else if insideBar then Color.MAGENTA else Color.CURRENT);

hope this helps...
Re: Fun with ThinkScript
February 16, 2017 03:47PM
still no, its giving me an error on insidematch, anything else?

Here is the custom thinkscript I use to scan. 33 so far today. maybe add assign color after this somewhere?

def count = 1;
def range = high - low;
def inside_bar = high <=high[1] and low >= low[1];
plot s = inside_bar && lowest(range,count)within 1 bars;
Re: Fun with ThinkScript
February 16, 2017 06:27PM
def insideBar = high <= high[1] and low >= low[1];
def insideMatch = insideBar and (high == high[1] or low == low[1]);
AddLabel(yes, " " );
AssignBackgroundColor(if insideMatch then Color.CYAN else if insideBar then Color.MAGENTA else Color.CURRENT);



- robert


Professional ThinkorSwim indicators for the average Joe
Re: Fun with ThinkScript
February 17, 2017 07:31AM
Thank you!
Re: Fun with ThinkScript
February 17, 2017 04:46PM
Hi Robert,

So I saw this code in the forum and am trying to tweak it to meet my parameters. I wish I understood this code better so I can figure out what i'm doing when I change the iBars or iRatio. Anyways, here are my parameters:


Pin nose/tail + body>=2/3rds the entire candle
Pin nose/tail must be at least 4 times as large as the body of the candle
pin nose/tail must be at least twice as large as non-pin wick.

Thanks!



# from our russian friends
# How to trade:
# [www.dukascopy.com]
# by jaimepinto@rogers.com
# Oct/16/2015

input iRatio =2;
input iBars = 4;

def iTelo=absValue (close-open);
def bPinUp = (((high - low)/(iTelo )) >iRatio) and high > high[1] and low>low[1] and max(open,close)<high-((high-low)/2);
def bPinDown =(((high - low)/(iTelo )) >iRatio) and high < high[1] and low<low[1] and min(open,close)>low+((high-low)/2);

def bTrendUp = fold TUbar = 1 to iBars+1 with TUsumm=1 do if (close[TUbar]-open[TUbar]>0) then TUsumm*1 else TUsumm*0;
def bTrendUp2 = fold TUbar2 = 1 to iBars with TUsumm2=1 do if (high[TUbar2]==highest(high[TUbar2],iBars)) then TUsumm2*1 else TUsumm2*0;

def bTrendDown = fold TDbar = 1 to iBars+1 with TDsumm=1 do if (open[TDbar]-close[TDbar]>0) then TDsumm*1 else TDsumm*0;
def bTrendDown2 = fold TDbar2 = 1 to iBars with TDsumm2=1 do if (low[TDbar2]==lowest(low[TDbar2],iBars)) then TDsumm2*1 else TDsumm2*0;

def bSignalUp = bPinUp and bTrendUp and bTrendUp2;
def bSignalDown = bPinDown and bTrendDown and bTrendDown2;

plot up = if bSignalUp then high else double.NaN;
plot down = if bSignalDown then high else double.NaN;
up.SetPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_down);
down.SetPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_up);
up.setDefaultColor(color.MAGENTA);
down.setDefaultColor(color.CYAN);
LLP
Limitations to Opposite orders with conditions
February 17, 2017 07:52PM
New to the forum and about 4 months experience with TOS Software and thinkscript. I would like to post the following issue to see if anyone has a solution for it.
I need to place two opposite OPENING orders at the same time (Long and Short) to have only one of them executed upon the fulfillment of a complex condition (Study).
Right now I see one of the following solutions:
Approach #1: Each of the above orders to have two conditions:
i) one that triggers the moment at which the order should be placed; let’s call it LG-cond for the buy order and SH-Cond for the Sell order and ,
ii) another to cancel the order once the opposite is executed (that is, cancel the sell order the moment the LG-cond occurs or cancel the buy order the moment the SH-cond occurs.

Problems encountered with Approach #1:
1) "plain Market OPEN orders may not be part of OCO group",
2) TOS would not allow a cancelling OPENING order at Market price with cancelling conditions.

Approach #2: Each order to include only one condition:
1) Condition to determine the moment at which the order should be placed but include code prevents so if any other order (Long or short) has been previously issued.

Problem encountered with Approach #2:
1) Recursiveness (or Total Sum) is not allowed on studies used as conditions to placement of orders.
2) I have not found any non-recursive code if an orders has been issued without using recursive functions.

Hope someone has a solution or a different approach to solve this.

Thanks,
paint today
February 18, 2017 01:35AM
input timeFrame = {default day};
input showOnlyToday = no;

def day = getday();
def lastday = getLastday();
def isToday = if(day >= lastday, 1, 0);


def shouldPlot = if(showOnlyToday and isToday, 1, if(!showOnlyToday, 1, 0));
#-----------------------------
#input paintBars = yes;
#-------------
plot UpperVolatility = isToday;
plot LowerVolatility = !isToday;
#-----------------------

UpperVolatility.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
UpperVolatility.SetLineWeight(3);
UpperVolatility.SetDefaultColor(Color.GREEN);
UpperVolatility.hide();
#----------------------------
LowerVolatility.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
LowerVolatility.SetLineWeight(3);
LowerVolatility.SetDefaultColor(Color.RED);
LowerVolatility.hide();
#------------------------------------------
#( today bars )
DefineGlobalColor("up", Color.GREEN);
DefineGlobalColor("dwn", Color.red);

# ( not today bars )
DefineGlobalColor("invisi", Color.black);

# if not paint bars then paint normal ... if condition1 then bullish scheme ... if condition2 then bearish scheme ... else normal

AssignPriceColor(
if !showonlytoday
#!paintBars
then Color.CURRENT

else
# ( is today then normal paint )
if UpperVolatility
then
if close > open then globalColor("up"winking smiley else globalColor("dwn"winking smiley
#globalColor( "up"winking smiley

else
# ( is not today then black)
if LowerVolatility
then globalColor( "invisi"winking smiley
else Color.CURRENT);
Override chart defaults
February 19, 2017 02:30PM
In TOS flexible charts I want to display the results of a study using addlabel. My problem is that I want to show the study results using 4 different aggregation periods (1 hour, 2 hour, 4 hour and day) on the same chart regardless of the period of the chart. When I run the study I just get the results for the chart period and do not know how to override it to get 4 separate results. The study is a premium study so no source is available just the plots for the result data.
Thanks.
Re: Fun with ThinkScript
February 20, 2017 01:51AM
Beautiful coding I hope to get as good as you one day. I was wondering if you could make me a code that for strangely that plots intraday high and low throughout the trading day. Also one for extended hours as well
Re: Fun with ThinkScript
February 20, 2017 04:42AM
How do I turn this code into a stragety
Re: Fun with ThinkScript
February 20, 2017 07:50AM
perhaps this one for HOD...

def hday = if hday[1]==0
then high
else if high>hday[1]
then high
else hday[1];
plot scan = if high==hday
then 1
else 0 within 1 bar;
Sorry, only registered users may post in this forum.

Click here to login