Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Fun with ThinkScript
October 08, 2015 03:43PM
baffled1 Wrote:
-------------------------------------------------------
> SARA Wrote:
> --------------------------------------------------
> -----
> > I put the code here but it didn't appear!!
> Hope you can figure out how to post it- I think
> it's interesting. All I could find was one that
> paints bars according to where an indicator is.
> Hm, might as well post it while we're on the
> subject:
>
> declare lower;
> input overbought1 = 80;
> input oversold1 = 20;
> plot MFI = MoneyFlowIndex();
> plot OverBought = overbought1;
> plot OverSold = oversold1;
>
> MFI.DefineColor("OverBought", Color.MAGENTA);
> MFI.DefineColor("OverSold", Color.PLUM);
>
> OverBought.SetDefaultColor(Color.MAGENTA);
> OverSold.SetDefaultColor(Color.PLUM);
>
> AssignPriceColor(if MFI >= OverBought then
> MFI.color("OverBought" ) else if MFI <=
> OverSold then MFI.color("OverSold" ) else
> Color.CURRENT);
> #Had to add a space (where you see blue type)
> between last quote mark and parenthesis to prevent
> Smilies.
>


=======================================

this is the code that I got, but it paints only one day 20 minutes, and also it counts the candles.
I want it to paint daily 20 minutes from (time : 0730 to 1400) as I explained above , also No need to show counting :



#Bgin code
AssignPriceColor( 
     if BarNumber() >=1 and BarNumber() <= 5 then Color.yellow
     else if BarNumber() >=6 and BarNumber() <=10 then Color.white
     else if BarNumber() >=11 and BarNumber() <=15 then Color.blue
     else if BarNumber() >=16 and BarNumber() <=20 then Color.red
     else Color.current);
#End code








=============

this also another script that show candles counting




#Begin Code
#BarCount
input start = 0730;
input end = 1400;
input paintbars = yes;
def stV = if SecondsTillTime(start) > 0 then 1 else 0;
def stVstart = if stV then BarNumber() else stVstart[1];
plot BarCount = BarNumber() - stVstart;
BarCount.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
AssignPriceColor( if !paintbars then Color.CURRENT else if BarCount > 0 and BarCount < 6 then Color.YELLOW else if BarCount > 5 and BarCount < 11 then Color.WHITE else if BarCount > 10 and BarCount < 16 then Color.BLUE else if BarCount > 15 and BarCount < 21 then Color.RED else Color.CURRENT);
#End Code



Edited 2 time(s). Last edit at 10/08/2015 04:01PM by SARA.
Re: thinkorswim custom scan study with variable
October 08, 2015 06:13PM
@baffled1 - thank you for testing it. i'm not sure what i did wrong, but you're correct it does indeed work as I wanted.
Re: Fun with ThinkScript
October 08, 2015 06:43PM
i hope someone can help me with this. i'm trying to create triggers that build a list.

all three scans are using the two minute interval.

first scan is a one time scan at the opening bell using -

def WAD = AccumDistBuyPr();
plot scan = (WAD < 0);

the second scan uses the stock list from the first scan -

def WAD = AccumDistBuyPr();
plot scan = (WAD > 0);

the last scan uses the list from the second scan -

def WAD = AccumDistBuyPr();
plot scan = (WAD < 0);

Is this possible in the ThinkorSwim platform? Am I in the right place for this? Thank you for ANY advice.
Re: Fun with ThinkScript
October 08, 2015 08:57PM
impecck1 Wrote:
-------------------------------------------------------
> i hope someone can help me with this. i'm trying
> to create triggers that build a list.
> all three scans are using the two minute
> interval.
> first scan is a one time scan at the opening bell
> using -
> def WAD = AccumDistBuyPr();
> plot scan = (WAD < 0);
> the second scan uses the stock list from the first
> scan -
> def WAD = AccumDistBuyPr();
> plot scan = (WAD > 0);
> the last scan uses the list from the second scan-
> def WAD = AccumDistBuyPr();
> plot scan = (WAD < 0);
>
> Is this possible in the ThinkorSwim platform? Am
> I in the right place for this? Thank you for ANY
> advice.
-------------------------------------------------------------------------
impecck1, spinning smiley sticking its tongue out I'll take that last sentence of yours as an invitation, despite my limited knowledge. I can't do it, but someone here can. But, your description of it, as it stands, is probably not do-able, ie, I don't know of any TS function that will create and then save a list of scanned securities and then re-filter them. So with all respect if I may rephrase your requirements to read: You want a scannable study that will generate a list of securities which have "property WAD<0" at open, then "property WAD>0" at a later time, then "property WAD<0" at a still later time. This would be a de- facto filtering system. I think such a study is writable and the journey starts with "SecondsTillTime" syntax. That's discussed in the TS manual at:
https://tlc.thinkorswim.com/center/charting/thinkscript/reference/Functions/Date---Time/SecondsTillTime.html
Well, you did say, "ANY advice", so I hope this helps you out.
Re: Fun with ThinkScript
October 08, 2015 09:09PM
SARA, thank you for posting that code. Could be very useful in some of my own work.
Re: Fun with ThinkScript
October 09, 2015 08:25AM
baffled1 Wrote:
-------------------------------------------------------
> impecck1 Wrote:
> --------------------------------------------------
> -----
> > i hope someone can help me with this. i'm
> trying
> > to create triggers that build a list.
> > all three scans are using the two minute
> > interval.
> > first scan is a one time scan at the opening
> bell
> > using -
> > def WAD = AccumDistBuyPr();
> > plot scan = (WAD < 0);
> > the second scan uses the stock list from the
> first
> > scan -
> > def WAD = AccumDistBuyPr();
> > plot scan = (WAD > 0);
> > the last scan uses the list from the second
> scan-
> > def WAD = AccumDistBuyPr();
> > plot scan = (WAD < 0);
> >
> > Is this possible in the ThinkorSwim platform?
> Am
> > I in the right place for this? Thank you for
> ANY
> > advice.
> --------------------------------------------------
> -----------------------
> impecck1, spinning smiley sticking its tongue out I'll take that last sentence of
> yours as an invitation, despite my limited
> knowledge. I can't do it, but someone here can.
> But, your description of it, as it stands, is
> probably not do-able, ie, I don't know of any TS
> function that will create and then save a list of
> scanned securities and then re-filter them. So
> with all respect if I may rephrase your
> requirements to read: You want a scannable study
> that will generate a list of securities which have
> "property WAD<0" at open, then "property WAD>0" at
> a later time, then "property WAD<0" at a still
> later time. This would be a de- facto filtering
> system. I think such a study is writable and the
> journey starts with "SecondsTillTime" syntax.
> That's discussed in the TS manual at:
> [tlc.thinkorswim.com]
> cript/reference/Functions/Date---Time/SecondsTillT
> ime.html
> Well, you did say, "ANY advice", so I hope this
> helps you out.

baffled1, thank you very much. i believe what you say is true, and i'll read up on your suggestion.

i took a look at [tlc.thinkorswim.com], does anyone have an actual working example?



Edited 1 time(s). Last edit at 10/09/2015 09:37AM by impecck1.
Re: Fun with ThinkScript
October 09, 2015 09:55AM
i'm thinking this may have a very simple answer that is staring me in the face. when you use the daily interval on a scan how many bars back does it begin? what i mean by that is if i use the following -

input length = 14;
input over_Bought = 70;
input over_Sold = 30;
input price = close;
input averageType = AverageType.WILDERS;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def RSI = 50 * (ChgRatio + 1);
def OverSold = over_Sold;
def OverBought = over_Bought;

def WAD = AccumDistBuyPr();

plot data3 = (RSI < 31) and (WAD < 0);

and compare the scan results on a 3 month daily chart it doesn't match up. from what i can tell i need to look at a one year daily chart for it to match. if this is the case my next question is how many bars in a one year daily chart (i tried the google machine)? what i'm trying to do is incorporate into the above code the following -

(RSI[x] > 30) and (WAD[x] > 0), where "x" would be the first bar in the chart.

essentially i'm trying to scan the first and last bar of a chart, whether it be a daily, 2min, or any other interval used in my scan.

thanks for the help. this topic is very interesting.
Re: Fun with ThinkScript
October 10, 2015 12:21PM
HI there,

new to the forum but not to the scripts. I love it.. it's not the best of the best to work with but at the end it does the job.

Here is something I try to achieve for a double of days and I can't find a way. In simple is 1 buy, 2 sell orders in 1 strategy.

Said that I want to show a strategy on my graph that Buy 100 shares at a given signal and then sell 50 of them with a price target is reached and the other 50 when a noter condition is reached.

I tried to duplicate my strategy having one called A and the other one B, I set the global parameters to allow 2 operations in the same directions when generated by 2 different strategy but looks like TorS will not take it correctly. For example I expected to have the entries plot at the same day ( they are the same condition to start with) well.. no the system shift them Day 1 day +2... even some time it doesn't generate the second at all... when for example the close or the first one append the next day... then it won't plot the second entry.

Looks like some sort of bug where the system can not plot 2 signal on the same day.
Mel
Re: Fun with ThinkScript
October 10, 2015 07:12PM
I am using the script for the AutoWave and 2 bubbles that I like to choose from. One has the price high or low and the other has point movement from high to low. Does anyone know how to add a date bubble? Below is what I use now.


AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , Round(chg, 2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp);

AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , Round(if isUp then high else low, 2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp);

Thanks,
Mel
The Price Divergence Indicator
October 13, 2015 02:35PM
Hello, I am looking for a study that would plot negative, positive and hidden divergences between DPO (Detrended Price Oscillator) and the price. Here is an example from today on /TF, range chart, ATR. [screencast.com]

Can somebody please write a code for this? Thank you very much.
Re: The Price Divergence Indicator
October 14, 2015 03:25AM
John7 Wrote:
-------------------------------------------------------
> Hello, I am looking for a study that would plot
> negative, positive and hidden divergences between
> DPO (Detrended Price Oscillator) and the price.
> Here is an example from today on /TF, range chart,
> ATR. [screencast.com]
>
> Can somebody please write a code for this? Thank
> you very much.
--------------------------------------------------------
John7, I've been working on this tonight. Part of the code that you really want is within Robert's post at http://www.researchtrade.com/forum/read.php?7,2258,5433#msg-5433 ,ie, it will display lines you want. It will take some modification to give you the two reads of:
1. DPO going up while price High going down, and;
2. DPO going down while price Low going up.
But what I offer below will simply show when Close and DPO are/are not diverging. I tested on EURUSD H1 and it does work as follows:
1. If plot colors are both Blue or Red, Close continues in same direction. (you can reset from chart screen to High, or HLC/3, etc)
2. After first bar of plot colors being Red/Blue, your specified price will change direction for at least 1 bar.
declare lower;
input price = close;
input evalperiod1 = 3;
input evalperiod2 = 3;
input evalperiod3 = 5;
def slope1 = price-price[evalperiod1];
def slope2 = average(slope1,evalperiod2);
def slope3 = average(slope1,evalperiod3);
def slope4 = (slope2/slope3)*100;
plot slope5 = slope4;
slope5.AssignValueColor(if slope5>= 0 then color.Blue else color.Red);

def myDPO = reference DetrendedPriceOsc;
def slope6 = myDPO-myDPO[evalperiod1];
def slope7 = average(slope6,evalperiod2);
def slope8 = average(slope6,evalperiod3);
def slope9 = (slope6/slope7)*100;
plot slope10 = slope9;
slope10.AssignValueColor(if slope10>= 0 then color.Blue else color.Red);
Re: Fun with ThinkScript
October 14, 2015 11:24PM
Hello,

I have the code for RSI, not DPO, I would like to have it for DPO that I use (please see the DPO study). I would like the lines to change color when there is a divergence. The studies plot lines that connect higher highs and lower lows. It is not perfect, because it does not catch everything, so if there is a better way to do it, I'm open to suggestions.

Thank you.

DPO
[www.dropbox.com]

Price High-Low Swing Lines
[www.dropbox.com]

RSI High-low Swing Lines
[www.dropbox.com]
Who can code a pinbar detection study for TOS?
October 16, 2015 03:36PM
Hi Thinkscripters

Can anyone do the world a favor and code a pinbar detection study for TOS when it comes out of bollinger bands ?


I am including the MT4 code of the detector below


Quote
//+------------------------------------------------------------------+
//| Pinbar Detector |
//| Copyright © 2011, EarnForex.com |
//| [url]http://www.earnforex.com/[/url] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, EarnForex"
#property link "[url]http://www.earnforex.com[/url]"

/*

Pinbar Detector - detects Pinbars on charts.
Has two sets of predefined settings: common and strict.
Fully modifiable parameters of Pinbar pattern.
Usage instructions:
[url]http://www.earnforex.com/forex-strategy[/url] ... ing-system

*/

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_color2 Lime
#property indicator_width2 2

extern bool UseAlerts = true;
extern bool UseEmailAlerts = false; // Don't forget to configure SMTP parameters in Tools->Options->Emails
extern bool UseCustomSettings = false; // true = use below parameters
extern double CustomMaxNoseBodySize = 0.33; // Max. Body / Candle length ratio of the Nose Bar
extern double CustomNoseBodyPosition = 0.4; // Body position in Nose Bar (e.g. top/bottom 40%)
extern bool CustomLeftEyeOppositeDirection = true; // true = Direction of Left Eye Bar should be opposite to pattern (bearish bar for bullish Pinbar pattern and vice versa)
extern bool CustomNoseSameDirection = false; // true = Direction of Nose Bar should be the same as of pattern (bullish bar for bullish Pinbar pattern and vice versa)
extern bool CustomNoseBodyInsideLeftEyeBody = false; // true = Nose Body should be contained inside Left Eye Body
extern double CustomLeftEyeMinBodySize = 0.1; // Min. Body / Candle length ratio of the Left Eye Bar
extern double CustomNoseProtruding = 0.5; // Minmum protrusion of Nose Bar compared to Nose Bar length
extern double CustomNoseBodyToLeftEyeBody = 1; // Maximum relative size of the Nose Bar Body to Left Eye Bar Body
extern double CustomNoseLengthToLeftEyeLength = 0; // Minimum relative size of the Nose Bar Length to Left Eye Bar Length
extern double CustomLeftEyeDepth = 0.1; // Minimum relative depth of the Left Eye to its length; depth is difference with Nose's back

// Indicator buffers
double Down[];
double Up[];

// Global variables
int LastBars = 0;
double MaxNoseBodySize = 0.33;
double NoseBodyPosition = 0.4;
bool LeftEyeOppositeDirection = true;
bool NoseSameDirection = false;
bool NoseBodyInsideLeftEyeBody = false;
double LeftEyeMinBodySize = 0.1;
double NoseProtruding = 0.5;
double NoseBodyToLeftEyeBody = 1;
double NoseLengthToLeftEyeLength = 0;
double LeftEyeDepth = 0.2;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator buffers mapping
SetIndexBuffer(0, Down);
SetIndexBuffer(1, Up);
//---- drawing settings
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 74);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 74);
//----
SetIndexEmptyValue(0, EMPTY_VALUE);
SetIndexEmptyValue(1, EMPTY_VALUE);
//---- indicator labels
SetIndexLabel(0, "Bearish Pinbar"winking smiley;
SetIndexLabel(1, "Bullish Pinbar"winking smiley;
//----
if (UseCustomSettings)
{
MaxNoseBodySize = CustomMaxNoseBodySize;
NoseBodyPosition = CustomNoseBodyPosition;
LeftEyeOppositeDirection = CustomLeftEyeOppositeDirection;
NoseSameDirection = CustomNoseSameDirection;
LeftEyeMinBodySize = CustomLeftEyeMinBodySize;
NoseProtruding = CustomNoseProtruding;
NoseBodyToLeftEyeBody = CustomNoseBodyToLeftEyeBody;
NoseLengthToLeftEyeLength = CustomNoseLengthToLeftEyeLength;
LeftEyeDepth = CustomLeftEyeDepth;
}
return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int NeedBarsCounted;
double NoseLength, NoseBody, LeftEyeBody, LeftEyeLength;

if (LastBars == Bars) return(0);
NeedBarsCounted = Bars - LastBars;
LastBars = Bars;
if (NeedBarsCounted == Bars) NeedBarsCounted--;

for (int i = NeedBarsCounted; i >= 1; i--)
{
// Won't have Left Eye for the left-most bar
if (i == Bars - 1) continue;

// Left Eye and Nose bars's paramaters
NoseLength = High[i] - Low[i];
if (NoseLength == 0) NoseLength = Point;
LeftEyeLength = High[i + 1] - Low[i + 1];
if (LeftEyeLength == 0) LeftEyeLength = Point;
NoseBody = MathAbs(Open[i] - Close[i]);
if (NoseBody == 0) NoseBody = Point;
LeftEyeBody = MathAbs(Open[i + 1] - Close[i + 1]);
if (LeftEyeBody == 0) LeftEyeBody = Point;

// Bearish Pinbar
if (High[i] - High[i + 1] >= NoseLength * NoseProtruding) // Nose protrusion
{
if (NoseBody / NoseLength <= MaxNoseBodySize) // Nose body to candle length ratio
{
if (1 - (High[i] - MathMax(Open[i], Close[i])) / NoseLength < NoseBodyPosition) // Nose body position in bottom part of the bar
{
if ((!LeftEyeOppositeDirection) || (Close[i + 1] > Open[i + 1])) // Left Eye bullish if required
{
if ((!NoseSameDirection) || (Close[i] < Open[i])) // Nose bearish if required
{
if (LeftEyeBody / LeftEyeLength >= LeftEyeMinBodySize) // Left eye body to candle length ratio
{
if ((MathMax(Open[i], Close[i]) <= High[i + 1]) && (MathMin(Open[i], Close[i]) >= Low[i + 1])) // Nose body inside Left Eye bar
{
if (NoseBody / LeftEyeBody <= NoseBodyToLeftEyeBody) // Nose body to Left Eye body ratio
{


Pinbar Detector
[www.earnforex.com]

Pinbar Trading System
[www.earnforex.com]
Re: Who can code a pinbar detection study for TOS?
October 16, 2015 04:35PM
I got it .. but without Bollinger bands ..
Please read "How to trade PinBar" on this link :
[www.dukascopy.com]

Quote
# from our russian friends
# How to trade:
# [url]https://www.dukascopy.com/fxcomm/fx-article-contest/?Price-Action-Pin-Bar-Strategy=&action=read&id=2195&language=en[/url]
# by [email]jaimepinto@rogers.com[/email]
# Oct/16/2015

input iRatio = 2.5;
input iBars = 2;

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);




Edited 1 time(s). Last edit at 10/16/2015 04:36PM by SARA.
Re: Fun with ThinkScript
October 18, 2015 09:08PM
Hi Robert,

I am new to TOS and writing codes and wanted to start off by saying thanks for all your efforts on this site and in helping turn scan/trade ideas into useful codes. I have been reading everything on writing scripts on this website and the TOS learning center so I can also write my own scripts. While searching this site, I came across 5 minute opening range code (copied below) you wrote for Tanman and attempted to enter it into TOS. However, I am getting an error message saying " secondary period not allowed: 1 hour".
Any help you can give on how to resolve would be greatly appreciated.

James.



#Calculate 5 min open range
def FirstMinute = if SecondsFromTime(0930) < 60 then 1 else 0;
def OpenRangeTime = if SecondsFromTime(0930) < 300 then 1 else 0;
def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1];
def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1];

#Define yesterday's high / low
def Yhigh = high(period = "day" )[1];
def Ylow = low(period = "day" )[1];

#Define combined trend
def t60 = close > ExpAverage(close(period = "1 hour" ), 8);
def t15 = close > ExpAverage(close(period = "15 min" ), 8);
def t5 = close > ExpAverage(close(period = "5 min" ), 8);
def upTrend = t60 and t15 and t5;
def dnTrend = !t60 and !t15 and !t5;

#Define Signals
def ATR = WildersAverage(TrueRange(high, close, low), 14);

def bull = upTrend and close > (Max(ORHigh, Yhigh) + ATR / 2);
def bear = dnTrend and close < (Min(ORLow, Ylow) - ATR / 2);
def neut = !bull and !bear;

#Add Labels
AddLabel(bull, " Go ", Color.GREEN);
AddLabel(bear, " Go ", Color.PINK);
AddLabel(neut, " No-Go ", Color.LIGHT_GRAY);
Re: Fun with ThinkScript
October 19, 2015 10:57AM
Robert,

Thank you for all you've done for those of us trying to learn ThinkScript to improve our trading. If it's possible, will you please create separate scripts for the conditions below? I will gladly contribute to your tip jarsmiling smiley



1) Overlay the Weekly, Daily and 4hr indicators (CC, StochRSI, MacD, Dir) so that they show on one single chart (ie. Three time frames on one chart)


2) Using your FP/HRFP script, add a vertical line on a stock chart ONLY when the following condition is met:

- FP/HRFP on 4hr chart of either $DJI, COMP, SPX, /YM, /NQ, or /ES


3) Using your FP/HRFP script, add a different color vertical line on the 4hr stock chart ONLY when the following condition is met:

- FP/HRFP on 4hr and FP/HRFP on Daily at the same time




For GW students that are diligently working hard every day to improve, I believe this would greatly help a lot with practice.


GOD BLESSsmiling smiley
Re: Fun with ThinkScript
October 20, 2015 01:47AM
Just ran into this very nice thread. I'm wondering if either Robert or others have coded thinkscript for Support/Resistance as well as Trendlines, drawn automatically for x-period of one's choosing?
Re: Fun with ThinkScript
October 22, 2015 12:08PM
Hi, I got this code from previous post by Robert. I like to know how I can turn it into a scan. I would like to scan for stock when price is ABOVE ENTRY(DH) level BUT BELOW TARGET HIGH(Target sell price).




script OpenRange {
input ORtime = 5;

def FirstBar = GetDay() != GetDay()[1];
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 then Double.NaN else Rhigh;
plot l = if RangeTime then Double.NaN else Rlow;
}

def first30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) >= 0;
def today = GetLastDay() == GetDay();
def ATR = Average(TrueRange(high, close, low), 10);

plot yHigh = if !today then Double.NaN else high(period = "day" )[1];
yHigh.SetDefaultColor(Color.CYAN);
plot yLow = if !today then Double.NaN else low(period = "day" )[1];
yLow.SetDefaultColor(Color.PINK);

plot h5 = if !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).h;
h5.SetDefaultColor(Color.YELLOW);
plot l5 = if !today then Double.NaN else if !first30 then Double.NaN else OpenRange(5).l;
l5.SetDefaultColor(Color.YELLOW);
plot h30 = if !today then Double.NaN else OpenRange(30).h;
h30.SetDefaultColor(Color.YELLOW);
plot l30 = if !today then Double.NaN else OpenRange(30).l;
l30.SetDefaultColor(Color.YELLOW);

def lowConf = if first30 then Min(yLow, l5) - ATR else Min(yLow, l30) - ATR;
def highConf = if first30 then Max(yHigh, h5) + ATR else Max(yHigh, h30) + ATR;

plot lc1 = if first30 then lowConf else Double.NaN;
lc1.SetDefaultColor(Color.ORANGE);
plot lc2 = if !first30 then lowConf else Double.NaN;
lc2.SetDefaultColor(Color.ORANGE);
plot hc1 = if first30 then highConf else Double.NaN;
hc1.SetDefaultColor(Color.ORANGE);
plot hc2 = if !first30 then highConf else Double.NaN;
hc2.SetDefaultColor(Color.ORANGE);

def decisionL = if close > lowConf then Double.NaN else if close crosses below lowConf then low else decisionL[1];
def decisionH = if close < highConf then Double.NaN else if close crosses above highConf then high else decisionH[1];

plot dL = if !today then Double.NaN else decisionL;
dL.SetDefaultColor(Color.WHITE);
plot dH = if !today then Double.NaN else decisionH;
dH.SetDefaultColor(Color.WHITE);

def TL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(TL[1]) then TL[1] else if close crosses below dL then dL - 2 * ATR else Double.NaN, Double.NaN);
def SL = CompoundValue(1, if IsNaN(dL) then Double.NaN else if !IsNaN(SL[1]) then SL[1] else if close crosses below dL then dL + 2 * ATR else Double.NaN, Double.NaN);

plot Target1Low = if !today then Double.NaN else TL;
Target1Low.SetDefaultColor(Color.GREEN);
Target1Low.SetStyle(Curve.SHORT_DASH);
plot Stop1Low = if !today then Double.NaN else SL;
Stop1Low.SetDefaultColor(Color.RED);
Stop1Low.SetLineWeight(2);


def TH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(TH[1]) then TH[1] else if close crosses above dH then dH + 5 * ATR else Double.NaN, Double.NaN);
def SH = CompoundValue(1, if IsNaN(dH) then Double.NaN else if !IsNaN(SH[1]) then SH[1] else if close crosses above dH then dH - 2 * ATR else Double.NaN, Double.NaN);

plot Target1High = if !today then Double.NaN else TH;
Target1High.SetDefaultColor(Color.GREEN);
Target1High.SetStyle(Curve.SHORT_DASH);
plot Stop1High = if !today then Double.NaN else SH;
Stop1High.SetDefaultColor(Color.RED);
Stop1High.SetLineWeight(2);
Watchlist Column tracking Hi/Lo TOS Chart Bubbles
October 23, 2015 06:09PM
Robert:

To help spot reversals I'm looking for some TOS code so I can spot intraday reversals for the stocks in my watchlist
without having to look at charts.

TOS charts, if set to show TODAY timeframe in the aggregation period field will show
the intraday Hi and Lo of a stock on the chart using bubbles (Hi: xx / Lo: xx)
These are great as it's often a good place to watch for a reversal trade.
However if you don't have the chart for a particular stock opened you won't see it.

My need is for a Custom Column in my watchlist where these Hi and Lo indications can be seen, even if the chart for that stock is not open. I work on 5 or 15 min time frame generally during the day.
The column field could show "H" if stock is X bars lower than high of day.
and "L" if stock is X bars higher than low of day.
Change to a blank field if price is Y bars above or below the above X parameters.
as the move may have already played out as far as a good scalp.

Is this something you have already scripted or if not can you create something that
would function this way ?
I have used and appreciated some of your other scripts (paid and free) with great results.

Aram



Edited 2 time(s). Last edit at 10/25/2015 05:51PM by Aram.
Re: Watchlist Column tracking Hi/Lo TOS Chart Bubbles
October 25, 2015 11:29AM
i guess everyone knows that robert is on hiatus, right?

hey, i'm just as sad about it as the next guy, if not more, but until he returns, just understand that's why you're not getting a reply.
Re: Fun with ThinkScript
October 25, 2015 01:29PM
Guys! I have one question. I just bought a script from Robert's website but I don't have the code? How am i suppose to receive it?
NEED HELP WITH A ToS SCANNER!
October 28, 2015 01:35AM
Hi! I really need help with creating a scanner that tells me when a stock's price nears/hits/breaks the Upper Vwap, Vwap, or lower Vwap as shown on the picture. Preferably the scanner will show the percentage that a stock is away from the upper,lower or middle vwap. I know it'll be hard to make a scanner that shows the percentage for the vwap plus it's deviations, so I was wondering if you guys could help me write 3 scanners. One for the percentage that a stock is away from the upper vwap, one for for the percentage that a stock is away from the middle vwap, etc. Thanks in advance, I would really appreciate the help.

Below is a picture to hopefully show what I mean.
[imgur.com]
info question?
October 29, 2015 09:04PM
I am new to trading and TOS ThinkDesk trading software. I just found this site and will be going through it soon and hope to
learn more about the software and thinkscript.

I also found a yahoo group tos_thinkscript@yahoogroups, that I think will help me out while learning more about TOS software.
The problem I am having is I can't get in touch with the list owner of that group to join it. Is there anyone here that is in that group
that can tell me how to join that list? Has the list owner quit or having trouble? Anyone here know what the problem may be as far as
getting in touch with the list owner and joining the list?

Thanks for your time,
Help with thinkscript aggregation
November 10, 2015 10:15AM
I have been trying to figure out why this script won't work. I'm working on defining a variable that will limit a system to entering a trade based on its next earnings report, but first I need to make number of bars variable depending on time scale.

def AG = getAggregationPeriod();
def thelimit;
if AG = AggregationPeriod.HOUR {
thelimit = 60;
} else {
thelimit = 20;
}

Thanks for the help.
Re: Fun with ThinkScript
November 10, 2015 07:59PM
Robert: Hope all has been going well.

I've looked but can't find...

Can ThinkScript send a text message alert from the code?

For the code:

Alert(Cond1,GetSymbol() + " Near Support1", Alert.BAR, Sound.Chimes);

If possbile, where would the SMS text alert be?

Thanks
Re: Fun with ThinkScript
November 14, 2015 12:16AM
Hi Robert

I'm new here not sure if this been already answer by you ,I'm using TOS platform, I like to put horizontal line for on Previous day regular session High and Low and same for over night session High & low for previous day (also for Daily,Weekly and monthly time frame) with Right side extension ,also I like to put text in middle of the horizontal line with price

Also when price cross and previous day High or low
or Over Night High or Low it give me a audio alert

Text :
Previous Day High (with High price)
Previous Day Low (with Low price)
Over Night High
Over Nigh Low

Thanks In advance
Using levels from EOD charts in intraday charts
November 15, 2015 06:21PM
This works for daily charts but when I switch to Intraday 15 min chart the levels are different, however yesterdays close level is correct.

def HHV = Highestall(high);
def LLV = Lowestall(low);
def x = ((HHV - LLV) / 8);
def limit = x * .4;
def z = (x -limit)*1.2;
def Long=Close(period = "day" ) from 1 bars ago - limit;
def Short=Close(period = "day" ) from 1 bars ago + limit;

input ShowTodayOnly = yes;

def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay();
plot HighLW = if !today then Double.NaN else long;
HighLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLW.SetDefaultColor(Color.green);
plot LowLW = if !today then Double.NaN else short;
LowLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLW.SetDefaultColor(Color.RED);
plot Clz = if !today then Double.NaN else close( period="day" ) from 1 bars ago;
Clz.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Clz.SetDefaultColor(Color.white);
Re: Using levels from EOD charts in intraday charts
November 18, 2015 02:54PM
First let me say that I did not write this. So I'm not gonna take any credit for it. But I'm having a problem getting this to show on my charts. If I move the chart down to see the 0.00 dollar line then I can see the very short histo lines, but I can't get the times to extend up the price chart and past the current price. Anyone know how to fix that so the histo lines can extend? I know for a fact that it worked on TOS back in 2013, but I'm not sure if they changed something with the code since then.

declare upper;

input WiggleRoom = 1;

#
# DMI Code
#

def DIr = DIPlus(5);
def DIg = DIMinus(5);
def ADXlength = 13;

def hiDiff = high - high[1];
def loDiff = low[1] - low;

def hiDiffPrev = high[WiggleRoom] - high[WiggleRoom + 1];
def loDiffPrev = low[WiggleRoom + 1] - low[WiggleRoom];

def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;

def plusDMPrev = if hiDiffPrev > loDiffPrev and hiDiffPrev > 0 then hiDiffPrev else 0;
def minusDMPrev = if loDiffPrev > hiDiffPrev and loDiffPrev > 0 then loDiffPrev else 0;

#
# StochRSI Code
#

input RSI_length = 13;
input over_bought = 80;
input over_sold = 20;
input RSI_price = close;
input KPeriod = 21;
input DPeriod = 5;
input slowing_period = 3;

def NetChgAvg = ExpAverage(RSI_price - RSI_price[1], RSI_length);
def TotChgAvg = ExpAverage(AbsValue(RSI_price - RSI_price[1]), RSI_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def NetChgAvgPrev = ExpAverage(RSI_price[WiggleRoom] - RSI_price[WiggleRoom + 1], RSI_length);
def TotChgAvgPrev = ExpAverage(AbsValue(RSI_price[WiggleRoom] - RSI_price[WiggleRoom + 1]), RSI_length);
def ChgRatioPrev = if TotChgAvgPrev != 0 then NetChgAvgPrev / TotChgAvgPrev else 0;

def RSI = 50 * (ChgRatio + 1);
def RSIPrev = 50 * (ChgRatioPrev + 1);

def lowest_k = Lowest(RSI, KPeriod);
def c1 = RSI - lowest_k;
def c2 = Highest(RSI, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def lowest_kPrev = Lowest(RSIPrev, KPeriod);
def c3 = RSIPrev - lowest_kPrev;
def c4 = Highest(RSIPrev, KPeriod) - lowest_kPrev;
def FastKPrev = if c4 != 0 then c3 / c4 * 100 else 0;

def FullK = Average(FastK, slowing_period);
def FullD = Average(FullK, DPeriod);
def FullKPrev = Average(FastKPrev, slowing_period);
def FullDPrev = Average(FullKPrev, DPeriod);

#
# MACD Code
#

input fastLength = 8;
input slowLength = 21;
input MACDLength = 5;

def Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
def Avg = ExpAverage(Value, MACDLength);

def prevValue = ExpAverage(close[WiggleRoom], fastLength) - ExpAverage(close[WiggleRoom], slowLength);
def prevAvg = ExpAverage(prevValue, MACDLength);

#
# FP/HRFP Check
#

def ChristmasCrossUp = SimpleMovingAvg(close, 2) > SimpleMovingAvg(close, 3, -3) and SimpleMovingAvg(close[WiggleRoom], 2) <= SimpleMovingAvg(close[WiggleRoom], 3, -3);
def RSICrossUp = FullK > FullD and FullKPrev <= FullDPrev;
def MACDCrossUp = Value > Avg and prevValue <= prevAvg;
def DMICrossUp = WildersAverage(plusDM, ADXlength) > WildersAverage(minusDM, ADXlength) and WildersAverage(plusDMPrev, ADXlength) <= WildersAverage(minusDMPrev, ADXlength);

def ChristmasCrossDown = SimpleMovingAvg(close, 2) < SimpleMovingAvg(close, 3, -3) and SimpleMovingAvg(close[WiggleRoom], 2) >= SimpleMovingAvg(close[WiggleRoom], 3, -3);
def RSICrossDown = FullK < FullD and FullKPrev >= FullDPrev;
def MACDCrossDown = Value < Avg and prevValue >= prevAvg;
def DMICrossDown = WildersAverage(plusDM, ADXlength) < WildersAverage(minusDM, ADXlength) and WildersAverage(plusDMPrev, ADXlength) >= WildersAverage(minusDMPrev, ADXlength);

def crossingDownSum = ChristmasCrossDown + RSICrossDown + MACDCrossDown + DMICrossDown;
def crossingUpSum = ChristmasCrossUp + RSICrossUp + MACDCrossUp + DMICrossUp;

plot FatPitchUp = crossingUpSum == 3;
plot HomeRunFatPitchUp = crossingUpSum == 4;
plot FatPitchDown = crossingDownSum == 3;
plot HomeRunFatPitchDown = crossingDownSum == 4;

FatPitchUp.SetDefaultColor(GetColor(1));
FatPitchUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
FatPitchUp.SetLineWeight(1);

HomeRunFatPitchUp.SetDefaultColor(GetColor(1));
HomeRunFatPitchUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
HomeRunFatPitchUp.SetLineWeight(2);

FatPitchDown.SetDefaultColor(GetColor(5));
FatPitchDown.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
FatPitchDown.SetLineWeight(1);

HomeRunFatPitchDown.SetDefaultColor(GetColor(5));
HomeRunFatPitchDown.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
HomeRunFatPitchDown.SetLineWeight(2);
Re: Using levels from EOD charts in intraday charts
November 18, 2015 03:10PM
Not sure what you mean but I just ran it by right-click the flattened study, then USE LEFT AXIS, and I only get tall vertical bars the full height of chart, which in fact are pretty good indicators. Hope this helps.
smiling bouncing smiley
Re: Using levels from EOD charts in intraday charts
November 18, 2015 04:00PM
Yeah the left axis thing worked. THANKS!!!!

It was flattened for me until I clicked on Use left axis. It'd be nice if there was a way to move the bar behind the candles and make them much more transparent.

My daily chart is sort of zoomed in a bit, Usually only showing about 50 candles or so. When set like that my histogram lines and candlesticks tend to get much fatter than I would like. Since these lines are actually histogram lines they are negatively affected by "zooming" in as well.
Sorry, only registered users may post in this forum.

Click here to login