Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: double.NaN alternative
February 01, 2019 02:36PM
getting an error message when i try that
Re: double.NaN alternative
February 01, 2019 04:05PM
as buy (or sell) is either yes or no, this should work


AddLabel(buy,((close[length]-open[length])*.25)+open[length] ,color.lighT_GREEN); 
AddLabel(sell, ((open[length]-close[length])*.75)+close[length] ,color.pink);

That will print the labels only when buy or sell are true



Edited 2 time(s). Last edit at 02/01/2019 04:08PM by rigel.
Re: double.NaN alternative
February 01, 2019 05:11PM
Thank you
Re: Fun with ThinkScript
February 06, 2019 07:21AM
Hello,

Looking for some help to add chart bubble on the following script.
I added it but it seems to plot it at the bottom of the screen instead
of plotting above or below the inside bar candle

Thank you so much.




#Plots InsideDay Bars
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5;
def insideDay = high < high[1] and low > low[1];
def range = high - low;
def NR4 = range < Lowest(range[1], 3);
plot signal = lowVol and insideDay and NR4;
    signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
    signal.SetDefaultColor(Createcolor(240, 98, 146));
    signal.SetLineWeight(3);
Alert(signal, getsymbol() + " inside & narrow range day.", alert.bar, sound.noSound);

## following code doesn't plot where I want to it. Have to work on it.
def SignalBar= IsNaN(close[-1]) and !IsNaN(close);
AddChartBubble(SignalBar[-2], signal, "IB",CreateColor(41, 182, 246));

Re: chartbubble position
February 06, 2019 11:53AM
Paperclips

I'm not totally sure what you are trying to do ... try this and will print the bubbles on top of the inside bar
#Plots InsideDay Bars
def lowVol = (VolatilityStdDev(6) / VolatilityStdDev(100)) < 0.5;
def insideDay = high < high[1] and low > low[1];
def range = high - low;
def NR4 = range < Lowest(range[1], 3);
plot signal = lowVol and insideDay and NR4;
   

## following code doesn't plot where I want to it. Have to work on it.
def SignalBar= IsNaN(close) and !IsNaN(close);
AddChartBubble(signal, high, "IB",CreateColor(41, 182, 246),yes);

 signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
    signal.SetDefaultColor(Createcolor(240, 98, 146));
    signal.SetLineWeight(3);
Alert(signal, getsymbol() + " inside & narrow range day.", alert.bar, sound.noSound);

Re: chartbubble position
February 06, 2019 02:52PM
Thank you soo much Rigel. It worked!



I hope you can see the image.



rigel Wrote:
-------------------------------------------------------
> Paperclips
>
> I'm not totally sure what you are trying to do ...
> try this and will print the bubbles on top of the
> inside bar
>
> #Plots InsideDay Bars
> def lowVol = (VolatilityStdDev(6) /
> VolatilityStdDev(100)) < 0.5;
> def insideDay = high < high[1] and low > low[1];
> def range = high - low;
> def NR4 = range < Lowest(range[1], 3);
> plot signal = lowVol and insideDay and NR4;
>
>
> ## following code doesn't plot where I want to it.
> Have to work on it.
> def SignalBar= IsNaN(close) and !IsNaN(close);
> AddChartBubble(signal, high, "IB",CreateColor(41,
> 182, 246),yes);
>
> signal.SetPaintingStrategy(PaintingStrategy.BOOLE
> AN_ARROW_DOWN);
> signal.SetDefaultColor(Createcolor(240, 98,
> 146));
> signal.SetLineWeight(3);
> Alert(signal, getsymbol() + " inside & narrow
> range day.", alert.bar, sound.noSound);
>
>
Re: chartbubble position
February 06, 2019 03:39PM
Happy that worked

ThinkScript question grinning smiley
February 12, 2019 06:51PM
Hi everyone,

Hope everyone is doing well. smiling smiley

I know there is a limitation concerning the watchlist columns within ToS. I'd like to have my column use a aggregation period other than 2 hours or 4 hours and use instead 233 mins, but ToS isn't doing it. I wonder if I can build a study that defines the 233 min time period and then have the watchlist column call on it, and show the results.

I think it will work, but I'm having a problem defining the 233 min aggregation period within my study. I'm sure it's something easy that I'm over looking. Also Google isn't being of much assistance either. smiling smiley
TCB
Re: ThinkScript question grinning smiley
February 12, 2019 08:44PM
I've contacted TOS and suggested adding the feature for custom time frames in columns several times. I think it can be done also. I really hope someone can figure this out.
Re: Fun with ThinkScript
February 14, 2019 01:25PM
HI i was checking [www.researchtrade.com] code of your and wondering how can we convert this study into scan ? is it possible?
Thanks for helping

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 = AvgTrueRange(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);

AddChartBubble(IsNaN(TL[1]) and !IsNaN(TL), TL, "Target 1\n" + Round(TL, 2), Color.GREEN, no);
AddChartBubble(IsNaN(SL[1]) and !IsNaN(SL), SL, "Stop\n" + Round(SL, 2), Color.RED);

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 + 2 * 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);

AddChartBubble(IsNaN(TH[1]) and !IsNaN(TH), TH, "Target 1\n" + Round(TH, 2), Color.GREEN);
AddChartBubble(IsNaN(SH[1]) and !IsNaN(SH), SH, "Stop\n" + Round(SH, 2), Color.RED, no);
Re: Fun with ThinkScript
February 15, 2019 09:13PM
There is a code on tradestation that I would like help to make a thinkscript, Its called breakout of X bar high. And also breakout of X bar low. Standard on tradestation. Couldnt find anything for it on ToS. This is how tradestation defines it.


Brkout of X Bar High marks the high of any bar whose High is higher than the High of any of the previous bars referenced by the study. The Length input specifies the number of bars considered by the study.

Brkout of X Bar High is most useful in trending markets and can indicate upward trending markets. Several bars marked consecutively could be an indication of a surge in price suggesting a possible breakout pattern. However, several bars marked consecutively may also indicate a trend is topping out and a reversal is imminent.

[help.tradestation.com]

[help.tradestation.com]

Thanks in advance.
Re: Fun with ThinkScript
February 17, 2019 03:09PM
Non-coder, hoping someone can help me turn this Lane Divergence indicator into a scan. Here is the thinkscript for the study that I use. Thanks in advance for any help!



declare lower;

input over_bought = 80.0;
input over_sold = 20.0;
input percentDLength = 3;
input percentKLength = 14;
input AudibleAlert = yes;



def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;
def avgrel = Average(Average(rel_diff, percentDLength), percentDLength);
def avgdiff = Average(Average(diff, percentDLength), percentDLength);
def SMIData = (avgrel / (avgdiff / 2) + 1) * 50;

def isLow = If (SMIData < SMIData[-1] and SMIData < SMIData[1], 1, 0);
def isHigh =   If (SMIData > SMIData[-1] and SMIData > SMIData[1], 1, 0);

rec prevLowSMI = CompoundValue(1, If(isLow[1], SMIData[1], prevLowSMI[1]), 

0);
rec prevHighSMI = CompoundValue(1, If(isHigh[1], SMIData[1], prevHighSMI

[1]), 0);

rec prevLow =  CompoundValue(1, If(isLow[1], low, prevLow[1]), low);
rec prevHigh =  CompoundValue(1, If(isHigh[1], high, prevHigh[1]), high);

def positiveDivergenceReg = If (SMIData > prevLowSMI and low < prevLow, 1, 

0);
def positiveDivergenceHid = If (SMIData < prevLowSMI and low > prevLow, 1, 

0);

plot posDiv = If(isLow and (positiveDivergenceReg or 

positiveDivergenceHid), SMIData, Double.NaN);
posDiv.AssignValueColor(if positiveDivergenceReg then Color.GREEN else 

Color.black);
posDiv.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
posDiv.SetLineWeight(2);


def negativeDivergenceReg =  If (SMIData < prevHighSMI and high > prevHigh, 

1, 0);
def negativeDivergenceHid = If (SMIData > prevHighSMI and high < prevHigh, 

1, 0);

plot negDiv = If(isHigh and ( negativeDivergenceReg or 

negativeDivergenceHid), SMIData, Double.NaN);
negDiv.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
negDiv.AssignValueColor(if negativeDivergenceReg then Color.RED else 

Color.black);
negDiv.SetLineWeight(2);



plot AvgSMI = Average(SMIData, percentDLength);
AvgSMI.SetDefaultColor(Color.GRAY);

plot overbought = over_bought;
overbought.SetDefaultColor(Color.WHITE);
overbought.SetStyle(Curve.SHORT_DASH);

plot oversold = over_sold;
oversold.SetDefaultColor(Color.WHITE);
oversold.SetStyle(Curve.SHORT_DASH);

plot SMI = SMIData;
SMI.AssignValueColor(if SMI > SMI[1] then Color.GREEN else Color.RED);
SMI.SetLineWeight(2);



# Sound alerts

Alert(AudibleAlert and positiveDivergenceReg, "Time TO Buy", Alert.BAR, 

Sound.Ring);


Alert(AudibleAlert and negativeDivergenceReg, "Time TO Sell", Alert.BAR, 

Sound.Ring);



Edited 2 time(s). Last edit at 02/17/2019 03:11PM by Dennis W.
Re: Fun with ThinkScript
February 18, 2019 03:37PM
@DennisW,

Try this...

def percentDLength = 3;
def percentKLength = 14;

def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;
def avgrel = Average(Average(rel_diff, percentDLength), percentDLength);
def avgdiff = Average(Average(diff, percentDLength), percentDLength);
def SMIData = (avgrel / (avgdiff / 2) + 1) * 50;

def isLow = If (SMIData < SMIData[-1] and SMIData < SMIData[1], 1, 0);
def isHigh =   If (SMIData > SMIData[-1] and SMIData > SMIData[1], 1, 0);

rec prevLowSMI = CompoundValue(1, If(isLow[1], SMIData[1], prevLowSMI[1]), 0);
rec prevHighSMI = CompoundValue(1, If(isHigh[1], SMIData[1], prevHighSMI[1]), 0);

rec prevLow =  CompoundValue(1, If(isLow[1], low, prevLow[1]), low);
rec prevHigh =  CompoundValue(1, If(isHigh[1], high, prevHigh[1]), high);

def positiveDivergenceReg = If (SMIData > prevLowSMI and low < prevLow, 1, 0);
def positiveDivergenceHid = If (SMIData < prevLowSMI and low > prevLow, 1, 0);


plot posDiv = If(isLow and (positiveDivergenceReg or positiveDivergenceHid), SMIData, Double.NaN);


def negativeDivergenceReg =  If (SMIData < prevHighSMI and high > prevHigh, 1, 0);
def negativeDivergenceHid = If (SMIData > prevHighSMI and high < prevHigh, 1, 0);


#plot negDiv = If(isHigh and ( negativeDivergenceReg or negativeDivergenceHid), SMIData, Double.NaN);

You can only test for one plot at a time, so comment out ( # ) either the posDiv or the negDiv plot statement...currrently it is set to identify positive divergences...

Good Luck and Good Trading smiling smiley
Re: Fun with ThinkScript
February 19, 2019 08:58AM
Thanks so much netarchitech!
Re: Fun with ThinkScript
February 19, 2019 05:46PM
Hi,
I have tried to make scanner but i know it's not working right as i am not able to get yesterday high and low right. If anyone can help will be grateful thanks in advance. Here is my code


 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];
    
    def h = if RangeTime or secondstilltime(0930) > 0 then Double.NaN else Rhigh;
    def l = if RangeTime or secondstilltime(0930) > 0 then Double.NaN else Rlow;
    
    input ORtime30 = 30;
    def RangeTime30 = SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) < 60 * ORtime30;
    def Rhigh30 = if FirstBar then high else if RangeTime30 and high > Rhigh30[1] then high else Rhigh30[1];
    def Rlow30 = if FirstBar then low else if RangeTime30 and low < Rlow30[1] then low else Rlow30[1];
    
    def h301 = if RangeTime30 or secondstilltime(0930) > 0 then Double.NaN else Rhigh30;
    def l301 = if RangeTime30 or secondstilltime(0930) > 0 then Double.NaN else Rlow30;    
    
    
    def first30 = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) >= 0;
    def today = GetLastDay() == GetDay();
    def ATR = Average(TrueRange(high,  close,  low),  10);
    
    #def yHigh = if !today then Double.NaN else high(period = "day" )[1];
    #def yLow = if !today then Double.NaN else low(period = "day" )[1];
    
    def yHigh = if !today then Double.NaN else highest(today[1]);
    def yLow = if !today then Double.NaN else lowest(today[1]);
    
    def h5 = if !today then Double.NaN else if !first30 then Double.NaN else h;
    def l5 = if !today then Double.NaN else if !first30 then Double.NaN else l;
    def h30 = if !today then Double.NaN else h301;
    def l30 = if !today then Double.NaN else l301;
    
    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;
    
    def lc1 = if first30 then lowConf else Double.NaN;
    def lc2 = if !first30 then lowConf else Double.NaN;
    def hc1 = if first30 then highConf else Double.NaN;
    def hc2 = if !first30 then highConf else Double.NaN;

    
    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];
    
    def dL = if !today then Double.NaN else decisionL;    
    def dH = if !today then Double.NaN else decisionH;
    
    
    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);
    
    def priceDiff = dL - TL;
    
    def Target1Low = if !today then Double.NaN else TL;    
    def Stop1Low = if !today then Double.NaN else SL;    
    
    
    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 + 2 * 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);
    
    def Target1High = if !today then Double.NaN else TH;    
    def Stop1High = if !today then Double.NaN else SH;

    plot scan = dH;
# plot scan = dL;

Need fix in these lines... please help

  def yHigh = if !today then Double.NaN else highest(today[1]);
   def yLow = if !today then Double.NaN else lowest(today[1]);

Thanks.
Re: Fun with ThinkScript
February 21, 2019 01:51PM
I found the below script on the net and would like a coder to help me with this, what is probably a simple request?
The code plots arrows at swing highs and swing lows.
What I want is to have the script plot colored points-dots in place of the arrows.
Also because of many charts that I have seen that plot dots-points seem to plot them on the bars or right at the top or bottom of the bars,
I would like to be able to control the distance from the high or low of the bar and the dots-points. So I could plot say the swing highs right at the top of the bar or X amount above the high of the bar etc. Basicly as close or as far away as I want the point-dot to be plotted to the high or low of that bar.

So what I would like is:

1. Plot points-dots instead of arrows.
2. Be able to plot the points-dots any distance I want from the high or low of the bar that have the points-dots plotted.

the code I found is below:

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 Double.NaN;
plot peakline = peakvalue;
peakline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
peakline.SetDefaultColor(Color.DOWNTICK);
peakline.SetLineWeight(1);


# define and plot the most recent valley
def valley = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude);
def valleyvalue = if BarNumber() < magnitude then Double.NaN else if valley then low else Double.NaN;
plot valleyline = valleyvalue;
valleyline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
valleyline.SetDefaultColor(Color.UPTICK);
valleyline.SetLineWeight(1);


I also have another question about plotting something, but I will ask it in the next post.
Thanks,
Re: Fun with ThinkScript
February 21, 2019 02:00PM
This is my other question about plotting points-dots.
I would like to be able to plot points-dots on a keltner channel say when the 5 avg. crosses 16 avg?
Like if the 5 avg crosses above the 16 avg. plot a colored point-dot on the upper Keltner Channel.
Would aslo like to be able to make the keltner indicator invisable, but still see the points-dots.
Basicly just using the keltner channels to plot the points-dots on, but no really using the keltner channels themselves in the charts.
Also instead of keltner channels, it cound be a mov. avg. channel etc. Just want something like this for the plots to be on.

How I explained this OK?

Thanks,
Re: Fun with ThinkScript
February 21, 2019 09:07PM
@styx,

With regard to your first requests, try this:

input magnitude = 3;
input peak_spacer = 8;
input valley_spacer = 8;

# 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 Double.NaN;
#plot peakline = peakvalue;
plot peakline = if peakvalue[0] then (high + peak_spacer * tickSize()) else Double.NAN;
#peakline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
peakline.SetPaintingStrategy(PaintingStrategy.POINTS);
peakline.SetDefaultColor(Color.DOWNTICK);
peakline.SetLineWeight(1);


# define and plot the most recent valley
def valley = low <= Lowest(low[1], magnitude) and low <= Lowest(low[-magnitude], magnitude);
def valleyvalue = if BarNumber() < magnitude then Double.NaN else if valley then low else Double.NaN;
#plot valleyline = valleyvalue;
plot valleyline = if valleyvalue[0] then (low - valley_spacer * tickSize()) else Double.NAN;
#valleyline.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
valleyline.SetPaintingStrategy(PaintingStrategy.POINTS);
valleyline.SetDefaultColor(Color.UPTICK);
valleyline.SetLineWeight(1);

FYI:
1. The input "spacers" should accomodate any distance you would like between a bar and the corresponding "point"
2. The "SetLineWeight" controls the size of the "point" (1 is smallest and 5 is largest)

Good Luck and Good Trading smiling smiley
Re: Fun with ThinkScript
February 22, 2019 01:04PM
HEY, Robert I recently purchased your VBOX study. I was wandering if you could help me with using it on higher time frames. Such as yearly, quarterly, monthly to find support and resistance.
Re: Fun with ThinkScript
February 22, 2019 08:05PM
I have not used that as of yet. Is it good? I love the new harmonics and wolfwave. Money well spent. most vbox shine on the 15m time frame. for long term I would look at the kelts….Kelt life.
Re: Fun with ThinkScript
February 22, 2019 11:51PM
netarchitech,

Thanks for help. That does what I wanted and works fine.
As a non-coder I had never seen or knew anything about spacer being used in scripts for this. That is something I would have never figured
out on my own.

Thanks again!
Re: ThinkScript question grinning smiley
February 23, 2019 03:05PM
RichieRick Wrote:
-------------------------------------------------------
> Hi everyone,
>
> Hope everyone is doing well. smiling smiley
>
> I know there is a limitation concerning the
> watchlist columns within ToS. I'd like to have my
> column use a aggregation period other than 2 hours
> or 4 hours and use instead 233 mins, but ToS isn't
> doing it. I wonder if I can build a study that
> defines the 233 min time period and then have the
> watchlist column call on it, and show the
> results.
>
> I think it will work, but I'm having a problem
> defining the 233 min aggregation period within my
> study. I'm sure it's something easy that I'm over
> looking. Also Google isn't being of much
> assistance either. smiling smiley
Re: ThinkScript question grinning smiley
February 23, 2019 06:43PM
@RichieRick,

AFAIK, thinkorswim does not provide custom aggregation periods. The list of available aggregation periods can be found here...

Good Luck and Good Trading smiling smiley
Re: Fun with ThinkScript
February 24, 2019 09:19PM
Yeah I know about those already. I was just hoping to find a way to "trick" ToS into giving me what I needed. smiling smiley

I was hoping that I could build a study and then I could have watchlist column call on the study to give me what I needed, but probably not gonna happen.
Re: Fun with ThinkScript
March 02, 2019 09:13PM
Im New here .please help me with this code

// Java program to find n-th Fibonacci number

class GFG
{
// Approximate value of golden ratio
static double PHI = 1.6180339;

// Fibonacci numbers upto n = 5
static int f[] = { 0, 1, 1, 2, 3, 5 };

// Function to find nth
// Fibonacci number
static int fib (int n)
{
// Fibonacci numbers for n < 6
if (n < 6)
return f[n];

// Else start counting from
// 5th term
int t = 5;
int fn = 5;

while (t < n) {
fn = (int)Math.round(fn * PHI);
t++;
}

return fn;
}

// Driver code
public static void main (String[] args)
{
int n = 9;
System.out.println(n + "th Fibonacci Number = "
+fib(n));
}
}

// This code is contributed by Anant Agarwal.






// Java Program to find sum
// of Fibonacci numbers in
// O(Log n) time.
import java.io.*;
import java.util.*;

class GFG {
static int MAX = 1000;

// Create an array for memoization
static int f[] = new int[MAX];

// Returns n'th Fibonacci
// number using table f[]
static int fib(int n)
{
Arrays.fill(f, 0);
// Base cases
if (n == 0)
return 0;
if (n == 1 || n == 2)
return (f[n] = 1);

// If fib(n) is already computed
if (f[n] == 1)
return f[n];
int k;
if((n & 1) == 1)
k = (n + 1) / 2 ;
else
k = n / 2;

// Applying above formula
// [Note value n&1 is 1
// if n is odd, else 0].
if((n & 1) == 1)
f[n] = (fib(k) * fib(k) +
fib(k - 1) * fib(k - 1));
else
f[n] = (2 * fib(k - 1) + fib(k)) * fib(k);

return f[n];
}

// Computes value of first
// Fibonacci numbers
static int calculateSum(int n)
{
return fib(n + 2) - 1;
}

// Driver program
public static void main(String args[])
{
int n = 4;
System.out.println( "Sum of Fibonacci numbers is : "
+ calculateSum(n));

}
}


/*This code is contributed by Nikita Tiwari.*/
Re: Fun with ThinkScript
March 13, 2019 06:45PM
Hi everyone!
This is my forst post so I must say this is by far the best forum on TOS, I´m learing a lot.
Before I ask for some helpd I´d like to share TOS code for Elliot oscillator with breakout band same used in A-Get to
identify wave 3 behaviour, wave 4 and end of wave 5 by divergence over the oscillator. Works pretty well for me, more information
can be found searching for "applying technical analysis" pdf on google where this and other aget features are explained in detail,
was a great source of information for me.

Now I´d like to ask if someone could helpme adding some fetures to ZigZagSign TOMO code.
So far wors great, but i´d like to add some information in the bubble at the end of each swing. I´d like to add
Total bar count for each swing
Accumulated volume of each swing
End price(price pivots), not price change as it is shown now.

I´m trying to get close to WavesSwingPro i used on ninjatrader, very powerful tool that can be linked to Elliot oscillator and plot bullish and bearish divergence to identify 123 moves.

Thanks!

#
# --- script begin ----
#

declare lower;

input price = hl2;
input HistoType = {default STD, ROC};
input SmoothLength = 5;

def valueDiff;
def value;
def showBands;
switch (HistoType) {
case STD:
value = double.nan;
valueDiff = (Average(price, 5) - Average(price, 35));
showBands = 1;
case ROC:
# ROC is smoothed with a SMA
value = (Average(price, 10) - Average(price, 70));
valueDiff = Average(value - value[1], SmoothLength);
showBands = 0;
}

# --- start Breakout Bands logic ---
#
# AdvanceGetOscillator Breakout Bands logic ported
# from [codebase.mql4.com]
# and [fxcodebase.com]...

def coeff_num = 2;
def coeff_denom = 39;

def barNum = if IsNaN( close ) then Double.NaN else barNumber();
def coeff = coeff_num / ( coeff_denom + 1 );
def diff = ValueDiff;

rec _upLine = if barNum == 1 then
if diff >= 0 then
diff * coeff + diff * ( 1 - Coeff )
else
0
else
if diff >= 0 then
diff * coeff + _upLine[1] * ( 1 - Coeff )
else
_upLine[1];
rec _dnLine = if barNum == 1 then
if diff < 0 then
diff * coeff + diff * ( 1 - Coeff )
else
0
else
if diff < 0 then
diff * coeff + _dnLine[1] * ( 1 - Coeff )
else
_dnLine[1];

plot UpLine = if showBands then _upLine else double.nan;
plot DownLine = if showBands then _dnLine else double.nan;

UpLine.SetDefaultColor(GetColor(9));
UpLine.SetLineWeight(2);
DownLine.SetDefaultColor(GetColor(9));
DownLine.SetLineWeight(2);

# --- end Breakout Band logic ---

plot Osc = valueDiff;
Osc.SetDefaultColor(GetColor(5));
Osc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Osc.SetLineWeight(3);
Osc.DefineColor("Positive and Up", Color.GREEN);
Osc.DefineColor("Positive and Down", Color.DARK_GREEN);
Osc.DefineColor("Negative and Down", Color.RED);
Osc.DefineColor("Negative and Up", Color.DARK_RED);
Osc.AssignValueColor(if Osc > 0 then if Osc > Osc[1] then Osc.color("Positive and Up"winking smiley else Osc.color("Positive and Down"winking smiley else if Osc < Osc[1] then Osc.color("Negative and Down"winking smiley else Osc.color("Negative and Up"winking smiley);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(7));
Study filter - hourly intraday - condition met for any of 7 candles
March 17, 2019 07:40AM
Good morning everyone

I have a study filter setup for hourly scan. when condition is true it returns the stock list results for current bar however on next hour new list is populated.

Now, how do I get stock list for every hour that condition is met for that day.

Thanks
se
count highs and lows
March 17, 2019 08:54PM
Hi, I am trying to use ThinkScript to count the successive differences between highs and lows and also to count the number of highs and lows in a given period. And then use AddLabel or AddChartBubble to show the results on the chart. However, the variables do not paint values in either AddChartBubble or AddLabel and I can't figure out why? The code comes from different public sources, including your own.
Thanks,
SE

input numBars = 5;
input showLines = no;
input showValues = yes;
input showBarNumbers = no;

def currentHigh = high;
def currentLow = low;
def currentBar = BarNumber();
def PH;
def PL;
def isHigherThanNextBars = fold i = 1 to numBars + 1 with p = 1
while p do currentHigh > GetValue(high, -i);
###########################
PH = if ( currentBar == 0) then currentHigh else if (currentBar > numBars and currentHigh == Highest(currentHigh, numBars) and isHigherThanNextBars) then currentHigh else Double.NaN;
#################################
def isLowerThanNextBars = fold j = 1 to numBars + 1 with q = 1
while q do currentLow < GetValue(low, -j);
PL = if ( currentBar == 0 ) then currentLow else if (currentBar > numBars and currentLow == Lowest(currentLow, numBars) and isLowerThanNextBars) then currentLow else Double.NaN;
#rec PHBar = if UserSetResistance then TrendResistanceEnd else if !IsNaN(PH) then currentBar else PHBar[1];
rec PHBar = if !IsNaN(PH) then currentBar else PHBar[1];
rec PLBar = if !IsNaN(PL) then currentBar else PLBar[1];
rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec priorPHBar = if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];
rec priorPLBar = if  PLL != PLL[1] then PLBar[1] else priorPLBar[1];
def isFinalTwoHighPivots = currentBar >= HighestAll(priorPHBar);
def isFinalTwoLowPivots = currentBar >= HighestAll(priorPLBar);
def ResistanceFinishOffset = if isFinalTwoHighPivots then currentBar - PHBar else 0;
def ResistanceStartOffset = if isFinalTwoHighPivots then currentBar - priorPHBar else 0;
def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) - GetValue(PH, ResistanceStartOffset)) / (PHBar - priorPHBar);
def SupportFinishOffset = if isFinalTwoLowPivots then currentBar - PLBar else 0;
def SupportStartOffset = if isFinalTwoLowPivots then currentBar - priorPLBar else 0;
def SupportSlope = (GetValue(PL, SupportFinishOffset) - GetValue(PL, SupportStartOffset)) / (PLBar - priorPLBar);
rec ResistanceExtend = if currentBar == HighestAll(PHBar) then 1 else ResistanceExtend[1];
rec SupportExtend = if currentBar == HighestAll(PLBar) then 1 else SupportExtend[1];
########################################
plot pivotHigh = if PH > 0 then PH else Double.NaN;
plot pivotLow = if PL > 0 then PL else Double.NaN;
#####################################################################
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#pivotHigh.SetHiding(!showValues);
pivotLow.SetDefaultColor(GetColor(4));
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
def countUp = Sum(pivotHigh, 100);

def peakValue = ph;
def valleyValue = pl;
def diff = peakValue - valleyValue;
def count = if pivotHigh[1] then 1 else count[1] + 1; ## needed??
plot peakArrow = pivotHigh;
     peakArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plot valleyArrow = pivotLow;
     valleyArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
def theDiff = peakValue - valleyValue[1];  # the problem is here??
def sumPeak = sum(pivotHigh,100);
def sumValley = sum(pivotLow,100);
AddChartBubble(peakValue, high + .01, high + " " + sumPeak , Color.WHITE);
def nextPeak = peakValue;
def thisLow = valleyValue[1];
#def lowPlusdiff = thisLow + theDiff;
def lowPlusdiff = thisLow + Diff;
AddChartBubble(valleyValue[1], thisLow[1] - 2, lowPlusDiff + "\n"+ diff + "\n"+ thisLow, Color.green, no
);
AddLabel(sumPeak, "p"+sumPeak, Color.green);
AddLabel(sumPeak, "v"+sumValley, Color.RED);



Edited 4 time(s). Last edit at 03/17/2019 11:20PM by se.
Re: Fun with ThinkScript RMO questions?
March 18, 2019 09:32AM
I found the below script and would like someone to explain to me what the code is doing for each part of the indicator as far as wht the formula is actually doing? I see that it is bunch of mov. avgs. etc. but being a non-coder I don't really understand what the script is doing and how.
Like how is SwingTrd_1 getting it info to plot? And the same for Swing Trd 2 and 3

The cose is below:
Thanks,



# Rahul Mohindar Osc (RMO) - lower study, also see upper study. RMO is a complete trading method, composed of 3 or 4 indicators, which was consolidated to one lower indicator,by a veteran scripter in TS, by my request. Rahul Mohindar has 4 seminars on U-tube on how his indicator should be used.
# translated from a Metastock script by rhouser
declare lower;

input length = 2;
input rmoLength = 81;
input swingTrdLen = 30;

def mva01 = MovingAverage( AverageType.SIMPLE, close, length );
def mva02 = MovingAverage( AverageType.SIMPLE, mva01, length );
def mva03 = MovingAverage( AverageType.SIMPLE, mva02, length );
def mva04 = MovingAverage( AverageType.SIMPLE, mva03, length );
def mva05 = MovingAverage( AverageType.SIMPLE, mva04, length );
def mva06 = MovingAverage( AverageType.SIMPLE, mva05, length );
def mva07 = MovingAverage( AverageType.SIMPLE, mva06, length );
def mva08 = MovingAverage( AverageType.SIMPLE, mva07, length );
def mva09 = MovingAverage( AverageType.SIMPLE, mva08, length );
def mva10 = MovingAverage( AverageType.SIMPLE, mva09, length );

def SwingTrd_1 = 100 *( close - ( ( mva01 + mva02 + mva03 + mva04 + mva05 + mva06 + mva07 + mva08 + mva09 + mva10 ) / 10 ) ) / ( Highest( close, 10 ) - Lowest( close, 10 ) );

plot RMO = MovingAverage( AverageType.EXPONENTIAL, Swingtrd_1, rmoLength );

plot SwingTrd_2 = MovingAverage( AverageType.EXPONENTIAL, SwingTrd_1, swingTrdLen );
plot SwingTrd_3 = MovingAverage( AverageType.EXPONENTIAL, SwingTrd_2, swingTrdLen );

plot ZeroLine = 0;

RMO.SetPaintingStrategy( PaintingStrategy.HISTOGRAM );
RMO.AssignValueColor(if RMO > 0 then Color.GREEN else Color.Magenta);
RMO.SetLineWeight( 3 );


SwingTrd_2.AssignValueColor(if SwingTrd_2 > 0 then Color.GREEN else Color.Magenta);
SwingTrd_2.SetLineWeight( 2 );


SwingTrd_3.SetPaintingStrategy( PaintingStrategy.LINE );
SwingTrd_3.SetDefaultColor( Color.BLUE );
SwingTrd_3.SetLineWeight( 2 );
ZeroLine.SetDefaultColor( Color.BLACK );

AssignPriceColor(if SwingTrd_2 > SwingTrd_3 then Color.Green else if SwingTrd_2 < SwingTrd_3 then Color.Red else Color.Yello
trial
March 19, 2019 03:04AM
xx



Edited 2 time(s). Last edit at 03/19/2019 03:09AM by rigel.
Sorry, only registered users may post in this forum.

Click here to login