Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: MVWAP
July 14, 2018 10:43AM
Quote
trying to trade
Looking to see if MVWAP is useful. Anyone experienced with it?
I wanted to play with it but cannot find it in ToS. Looks like you need to calculate the VWAP which ToS does then average it over say 10 days

Not sure what you call MVWAP.... the vwap is in TOS and you can set it to reset daily, weekly and monthly.
Re: Centered Moving Average (CMA)
July 14, 2018 01:49PM
Rigel,

Here is the entire code for the Hurst but again I was only interested in the centered moving average and how it plots. Again it lags and is displaced 4 bars back and not sure it can be mimic without lagging.

# --- script begin ----
#

declare upper;

input price = hl2;
input length = 10;
input InnerValue = 1.6;
input OuterValue = 2.6;
input ExtremeValue = 4.2;
input showFlowPrice = NO;
input showPriceBar = YES;
input smooth = 1;

def displacement = (-length / 2) + 1;
def dPrice = price[displacement];

rec CMA = if !IsNaN(dPrice) then Average(dPrice, AbsValue(length)) else CMA[1] + (CMA[1] - CMA[2]);

plot CenteredMA = if !IsNaN(dPrice) then CMA else Double.NaN;
CenteredMA.SetDefaultColor(GetColor(1));
CenteredMA.SetLineWeight(2);

plot ExtrapolatedMA = if !IsNaN(price) and IsNaN(dprice[-1]) then CMA else
Double.NaN;
ExtrapolatedMA.SetDefaultColor(GetColor(0));
ExtrapolatedMA.SetLineWeight(2);
ExtrapolatedMA.SetStyle(Curve.SHORT_DASH);
ExtrapolatedMA.DefineColor("Up", Color.Magenta);
ExtrapolatedMA.DefineColor("Down", Color.Yellow);
ExtrapolatedMA.AssignValueColor(if ExtrapolatedMA >= ExtrapolatedMA[1] then ExtrapolatedMA.color("Up"winking smiley else ExtrapolatedMA.color("Down"winking smiley);

def ExtremeBand = CMA * ExtremeValue / 100;;
def OuterBand = CMA * OuterValue / 100;
def InnerBand = CMA * InnerValue / 100;

plot UpperExtremeBand = if !IsNaN(price) then CMA + ExtremeBand else Double.Nan;
plot LowerExtremeBand = if !IsNaN(price) then CMA - ExtremeBand else Double.Nan;
plot UpperOuterBand = if !IsNaN(price) then CMA + OuterBand else Double.Nan;
plot LowerOuterBand = if !IsNaN(price) then CMA - OuterBand else Double.Nan;
plot UpperInnerBand = if !IsNaN(price) then CMA + InnerBand else Double.Nan;
plot LowerInnerBand = if !IsNaN(price) then CMA - InnerBand else Double.Nan;

UpperExtremeBand.SetDefaultColor(GetColor(4));
UpperExtremeBand.SetLineWeight(2);
LowerExtremeBand.SetDefaultColor(GetColor(4));
LowerExtremeBand.SetLineWeight(2);
UpperExtremeBand.hide();
LowerExtremeBand.hide();

UpperOuterBand.SetDefaultColor(GetColor(5));
UpperOuterBand.SetLineWeight(2);
LowerOuterBand.SetDefaultColor(GetColor(6));
LowerOuterBand.SetLineWeight(2);

UpperInnerBand.SetDefaultColor(GetColor(5));
UpperInnerBand.SetLineWeight(1);
UpperInnerBand.SetStyle(Curve.SHORT_DASH);
LowerInnerBand.SetDefaultColor(GetColor(6));
LowerInnerBand.SetLineWeight(1);
LowerInnerBand.SetStyle(Curve.SHORT_DASH);

# Turn AddClouds off by putting a #-sign at the first position of the lines
AddCloud(UpperOuterBand, UpperInnerBand, color.red);
AddCloud(LowerInnerBand, LowerOuterBand, color.green);

#Rev 2:
#def FlowValue = if close > close[1] then high else if close < close[1] then low else (high + low)/2;
def FlowValue =
if high >= high[1] and low <= low[1]
then
if close >= close[1] #or high >= high[2]
then high
else low
else
if high > high[1]
then high
else
if low < low[1]
then low
else
if close > close[1]
then high
else
if close < close[1]
then low
else (high + low) / 2;

plot FlowPrice = if showFlowPrice then Average(FlowValue, smooth) else double.nan;
FlowPrice.SetDefaultColor(GetColor(9));
FlowPrice.SetLineWeight(2);

hidePricePlot(!showPriceBar);

#
# --- script end ----
#
Re: MVWAP
July 15, 2018 01:25AM
Rigel thanks for the response. I think what you describe in the weekly or monthly vwap does not work the same as what I am describing. I guess it is plotting a moving average over a 10 day period of the daily vwap.
10 period MVWAP, they would simply wait for the first ten periods to elapse and then would average the first 10 VWAP calculations. This would provide the trader with the MVWAP that starts being plotted at period 10. To continue getting the MVWAP calculation, average the most recent 10 VWAP figures, include a new a VWAP from the most recent period and drop the VWAP from 11 periods earlier.
I may have to be some aggregate command but I cannot understand how to code it.
Re: MVWAP
July 15, 2018 09:02AM
As far as I know there are only two ways to use the vwap link

1. a continuous MA of price x volume
That is actually a weighted MA in which the weight is the volume.

2. Same calculation as above but the MA is reset every predefined period (the one is TOS)
Obviously, if you want to reset 10, 15, 25 or whatever day it would be necessary to build that vwap "variable" to reset accordingly.



Edited 1 time(s). Last edit at 07/16/2018 12:25PM by rigel.
Re: Centered Moving Average (CMA)
July 15, 2018 09:20AM
Chillic15

Short answer:
The displace you see is in the:
def displacement = (-length / 2) + 1;

To eliminate the displacement simply replace that with:
def displacement = 0;

Long answer:
If you read Hurst book, you will learn that he explains in detail that every MA is lagging, and the lag is half of the period. That means that in reality you will never know what is the corresponding real value. What you see (when there is no displacement) is actually the value of the MA half period ago. That is why Hurst prefers to plot with displacement and "forecast" or "project" the probable MA of the last points (the dash line in your script)



Edited 1 time(s). Last edit at 07/15/2018 05:30PM by rigel.
AddLabel finer points
July 18, 2018 10:01PM
I have a Thinkscript script with many AddLabel commands at the bottom of the script.

At Screen display time, they line up across the top of the Upper graph, left to right, until there is no more room to the right.
Then they flow automatically to the next line.
I have been trying to find a way to have a little more control over AddLabel positioning.

I have been looking for a way to insert a next line or carriage return to force half of the labels to display on the next line.
I do not find in the AddLabel command AddLabel(boolean visible, Any text, CustomColor color); a way to do this.

Does anyone know a trick to insert a next line in the middle of a bunch of AddLabel commnds?

Thanks for any ideas.
thinkscript - low and close of highest high
July 24, 2018 07:34PM
Hi,

this is my first post here. need help for think script.

this is how I think should be the script to get the highest high for 10 bars starting from 10 bars ago
def last10hi = highest(high[10], 10)

Need help in getting the low and close of this particular highest high. thanks in advance.
Re: Fun with ThinkScript
July 24, 2018 08:38PM
Referring to my prior post above:
Someone suggested that \n is a newline character in Thinkscript but it is not working in the Addlabel command.
I have tried a variety of Addlabel attempts to force a next line in Upper and at the top (only there):
Addlabel(yes, "\n", COLOR.WHITE);
Addlabel(yes, "/n", COLOR.WHITE);
Addlabel(yes, "\r", COLOR.WHITE);
Addlabel(yes, "\n\n", COLOR.WHITE);
Addlabel(yes, "&\n", COLOR.WHITE);

The only Addlabel that works is unreliable and that is
Addlabel(yes, " ", COLOR.WHITE); #lots of spaces between " " which are being cut out by this particular editor.
That pushes the other labels to the next line eventually but it depends upon the prior Addlabel text lengths.

I wonder about the special characters allowed in Thinkscript?



Edited 4 time(s). Last edit at 07/24/2018 08:41PM by RickT.
Re: Fun with ThinkScript
July 24, 2018 11:13PM
hey robert, or anyone out there willing to help. Mind plugging this in? Doesn't work as wanted. Yes it's very simple but today would be day 3 of this ne adventure...

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.EXPONENTIAL;

def Diff = MACD(fastLength, slowLength, MACDLength, averageTypeMACD).Diff;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageTypeStoch = AverageType.SIMPLE;
input lastPrice = close;

def SlowK = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageTypeStoch).FullK;


def SlowD = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageTypeStoch).FullD;

def buy = (SlowK[1] < SlowD[1]) and (SlowK > SlowD) and (lowest(SlowK[1], 3) < 50) and (Diff[1] < Diff);
def sell = (lastPrice < (EntryPrice() * 0.5)) or (lastPrice > (EntryPrice() * 1.005));

AddOrder(OrderType.BUY_TO_OPEN, buy, 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Entry @ " + lastPrice);

AddOrder(OrderType.SELL_TO_CLOSE, sell, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Exit @ " + lastPrice);

What's unfortunate as you see in the "def sell" line, is it's not getting what I really want out of it... It's literally stopping out of the position on the very next candle no matter what. Thanks to whoever sees this!

Mike
does the wolf wave have audio alert
July 25, 2018 12:00PM
does the wolf wave have audio alert when entry signal triggers ? if not could one be added to this study
Re: does the wolf wave have audio alert
July 25, 2018 05:25PM
OptionMaster Wrote:
-------------------------------------------------------
does the wolf wave have audio alert when entry
signal triggers ? if not could one be added to
this study


Code?
Re: does the wolf wave have audio alert
July 26, 2018 07:57AM
yes rigel, is their a way to add a code
Re: Fun with ThinkScript
July 26, 2018 10:43PM
Reply to MoneyMonkey4321

The number precision of Open, Close, Price in Thinkscript or TOS is hard to find in the documentation.
If anyone knows it, please chime it.
I find a lot of Thinkscript examples using 2 decimal places like 1.00, 5.00 etc.

So:
If EntryPrice() has two decimal places, then it is possible that (EntryPrice() * 1.005) is multiplied by 1.00.
That means a lastPrice 1 penny above EntryPrice would make the Sell statement true,
(lastPrice > (EntryPrice() * 1.005));



Edited 2 time(s). Last edit at 07/26/2018 10:48PM by RickT.
Re: Fun with ThinkScript
July 28, 2018 02:26AM
Hey Rigel, Ive had a Stochastic Divergence Indicator for awhile and it isn't showing my trendlines connecting the higher highs, lower lows, higher lows, or lower highs on my lower Stochastic plot itself but rather beneath it, it gives me the values but its its also lagging...could you give me some help as to where the coding may be wrong where I could get my trendlines actually plotted on my Stochastic and also stop the lag...I know its a lot..but I believe alot would be interested...im also a newbie trader...It would be very much appreciated sir!!!!!!

declare lower;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input slowing_period = 3;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
plot FullK = MovingAverage(averageType, FastK, slowing_period);
plot FullD = MovingAverage(averageType, FullK, DPeriod);

plot OverBought = over_bought;
plot OverSold = over_sold;

def upK = FullK crosses above OverSold;
def upD = FullD crosses above OverSold;
def downK = FullK crosses below OverBought;
def downD = FullD crosses below OverBought;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
UpSignal = Double.NaN;
DownSignal = Double.NaN;
case "On FullK":
UpSignal = if upK then OverSold else Double.NaN;
DownSignal = if downK then OverBought else Double.NaN;
case "On FullD":
UpSignal = if upD then OverSold else Double.NaN;
DownSignal = if downD then OverBought else Double.NaN;
case "On FullK & FullD":
UpSignal = if upK or upD then OverSold else Double.NaN;
DownSignal = if downK or downD then OverBought else Double.NaN;
}

UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No"winking smiley;
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No"winking smiley;

FullK.SetDefaultColor(GetColor(5));
FullD.SetDefaultColor(GetColor(0));
OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# ----- define a valley as any point which is lower than the three preceding lows and the three following lows
def Valley = low < Lowest(low[1], 3) and low < Lowest(low[-3], 3);

def Peak = high > Highest (high[1], 3) and high > highest(high[-3], 3);
# ----- mark each valley with an up arrow -----
# ----- mark each peak with a down arrow -----
plot ArrowDown =Peak;
ArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowDown.SetDefaultColor(Color.RED);
ArrowDown.SetLineWeight(4);
#---------------------------------------
plot ArrowUP = Valley;
ArrowUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowUP.SetDefaultColor(Color.GrEEN);
ArrowUP.SetLineWeight(4);

# May 27 2012 - FractalTrader
#
#This script will show support and resistance lines based on either
# user-defined price pivots, or automatically based on pivot points
# calculated by the script. In the case of automatic determination, only
# the last two matching points are used.
#hint numBars: For automatic pivot calculation: How many bars to use in calculation of pivotPoints. ie. current high is higher than both prior X bars and following X bars
#hint showLines: Show a line extending from high and low price pivots
#hint showValues: Show the numeric value of price occurring at the pivot point
#hint showBarNumbers: For manually entered pivots: used to determine bar numbers for two price pivot points to connect. It is recommended to temporarily turn off showValues.
#hint TrendResistanceStart: Starting point of a resistance trend line (connecting the highs), entered as a bar number. It is recommended to turn on showBarNumbers temporarily to determine the value.
#hint TrendResistanceEnd: Ending point of a resistance trend line, entered as a bar number. It is recommended to turn on showBarNumbers temporarily to determine the value.
#hint TrendSupportStart: Starting point of a support trend line (connecting the lows), entered as a bar number. It is recommended to turn on showBarNumbers temporarily to determine the value.
#hint TrendSupportEnd: Ending Point of a support trend line (connecting the lows), entered as a bar number. It is recommended to turn on showBarNumbers temporarily to determine the value.
input numBars = 5;
input showLines = yes;
input showValues = yes;
input showBarNumbers = yes;
input TrendResistanceStart = 0;
input TrendResistanceEnd = 0;
input TrendSupportStart = 0;
input TrendSupportEnd = 0;

def UserSetResistance = TrendResistanceStart > 0 and TrendResistanceEnd > 0;
def UserSetSupport = TrendSupportStart > 0 and TrendSupportEnd > 0;
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 UserSetResistance and ( currentBar == TrendResistanceStart or currentBar == TrendResistanceEnd ) then currentHigh else if !UserSetResistance and (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 UserSetSupport and ( currentBar == TrendSupportStart or currentBar == TrendSupportEnd ) then currentLow else if !UserSetSupport and (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 PLBar = if UserSetSupport then TrendSupportEnd else if !IsNaN(PL) then currentBar else PLBar[1];
rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec priorPHBar = if UserSetResistance then TrendResistanceStart else if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];
rec priorPLBar = if UserSetSupport then TrendSupportStart else 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
#isFinalTwoHighPivots
ph>0 then PH else Double.NaN;
plot pivotHighLine = if PHL > 0 and isFinalTwoHighPivots then PHL else Double.NaN;

plot ResistanceLine = pivotHigh;
plot ResistanceExtension = if ResistanceExtend then (currentBar - PHBar) * ResistanceSlope + PHL else Double.NaN;
plot pivotLow = if
#isFinalTwoLowPivots
pl>0 then PL else Double.NaN;
plot pivotLowLine = if PLL > 0 and isFinalTwoLowPivots then PLL else Double.NaN;
plot SupportLine = pivotLow;
plot SupportExtension = if SupportExtend then (currentBar - PLBar) * SupportSlope + PLL else Double.NaN;
plot BN = currentBar;
plot PivotDot = if !IsNaN(pivotHigh) then pivotHigh else if !IsNaN(pivotLow) then pivotLow else Double.NaN;
plot BisectLine = if !isNaN(pivotHigh) then pivotHigh else if !isNaN(pivotLow) then pivotLow else double.NaN;
pivotHigh.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
pivotHigh.SetHiding(!showValues);
pivotLow.SetDefaultColor(GetColor(4));
pivotLow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
pivotLow.SetHiding(!showValues);
ResistanceLine.EnableApproximation();
ResistanceLine.SetDefaultColor(GetColor(7));
ResistanceLine.SetStyle(Curve.SHORT_DASH);
ResistanceExtension.SetStyle(Curve.SHORT_DASH);
ResistanceExtension.SetDefaultColor(GetColor(7));
SupportLine.EnableApproximation();
SupportLine.SetDefaultColor(GetColor(7));
SupportLine.SetStyle(Curve.SHORT_DASH);
SupportExtension.SetDefaultColor(GetColor(7));
SupportExtension.SetStyle(Curve.SHORT_DASH);
pivotHighLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotHighLine.SetHiding(!showLines);
pivotLowLine.SetPaintingStrategy(PaintingStrategy.DASHES);
pivotLowLine.SetHiding(!showLines);
BisectLine.EnableApproximation();
BisectLine.SetLineWeight(2);
PivotDot.SetDefaultColor(GetColor(7));
PivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotDot.SetLineWeight(3);
BN.SetDefaultColor(GetColor(0));
BN.SetHiding(!showBarNumbers);
BN.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
Re: Fun with ThinkScript
July 28, 2018 10:38PM
Robert,

Do we have anything like this on this board or is it possible to create this.


[youtu.be]
Thinkscript - Stochastic divergence.
July 28, 2018 08:07PM
Hi. Need help in scripting a TOS scan for stochastic divergence. I'm new to thinkscript and struggling to write this script. Any help or direction where and how to start will be helpful. Thanks.
Retrace or EMA touch alert
July 27, 2018 12:43PM
Hi -

I am fairly new to TOS platform. I have just switched from Fidelity so it feels like a whole new world!

Thank you to Robert and all the technical Gurus for providing quick responses and scripts.

I am looking for a script that will do the following:

When a Hammer or doji candlestick pins the 8 EMA or 20 EMA (do the following):

1. Alert as a ding and receive a text message
2. Alert to show up on watchlist. Maybe a seperate column that will show the price or is highligthed?
3. Indicator arrow to show buy and sell signal

thank you in advance for your help.
NMR
Re: Fun with ThinkScript
August 01, 2018 01:48PM
Hi everyone:
I'd like to write a simple scan that analyzes stocks that have:

1) a 50 MA angling down, but price is considerably above the MA

&

2) a 50 MA angling up, but price is considerably below the MA

I've started with this- but am at a loss to figure out how I put in the angle- I was thinking of only 5 or 10 cangles worth of a move:

Open Scan Tab and click on Add Study Filter button.
On the left hand side there is a dropbox with a Criteria caption, open it and choose Custom field (the one on the bottom of dropdown list)
Scanner Custom Filter window will appear. Open ThinkscriptEditor tab.
Delete ADXCrossover() line.


#TOS 50 MA angle scan
def ma = SimpleMovingAvg(close,50);
def s = ma*0.05;
plot scan = absvalue(close - ma) is less than or equal to s;
#
#aggregation period= D
#

If anyone is interested in why I want to do this- or what it does: I am looking for trades that have a potential to revert back to or through the mean. So for example the 50 MA is angling down, the stock has been in a downtrend, it pops back up above the 50, and turns, angles down and goes down... I can explain more if anyone is interested. I can also do a follow-up to this thread on my success (or failure) with it. I'd like to share how to use it and why it [should] work. Have a great day everyone !
Re: Fun with ThinkScript
August 01, 2018 04:09PM
I am trying this script on the SPX, don't seem to work. any ideas. Thank you
Re: Fun with ThinkScript
August 02, 2018 10:32AM
not getting entry whit line on my chart
Problems with this study
August 02, 2018 11:44AM
not getting open white line, Trade line




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
August 06, 2018 08:20AM
Taurean

Not sure what you want to achieve. This is what I see:

You have TWO scripts merged:
One for plotting the stochastic and other for the fractal thing.

Now they are both plotted in a lower panel because of the instruction
declare lower;

Then you have an scale problem: the fractal part will have the values of the stock price while the stochastic willl have its normal small values (compared to stock prices). That is why the fractal part will be all cluttered (unreadable) above the stochastic plot
You can see in this picture all the clustered fractal part separated now in the upper panel. (I have separated the two scripts)


From that, I imagine that in first instance, what you want is to plot in the upper panel the fractal part as shown PLUS the arrows originated from the stochastic, but actually you don't want the stochastic plotted... is that right?

In other words, you need to define where and what plots do you want before trying to solve further problems with the indicators.
Re: Problems with this study
August 06, 2018 08:34AM
Optionmaster

You have made several questions but sorry, they are not clear.

Quote
Optionmaster

does the wolf wave have audio alert when entry
signal triggers ? if not could one be added to
this study

I am trying this script on the SPX, don't seem to work. any ideas. Thank you

not getting open white line, Trade line

1. For the wolf wave you need to post the code, then probably I will be able to help you

2. For the script you posted, I see a white line... I don't know what you call Trade line
Re: Fun with ThinkScript
August 06, 2018 11:40AM
Hey Rigel!!!!! Thanks for the response I just want the price deviations from the Stochastic when it's making higher highs or lower lows and price is doing the opposite...i didn't know how to separate the fractals for the highs and lows from price...i also didn't want it to lag and didn't know how to plot a linear line on the Stochastic when the criteria was met...Thanks alot!!!!!!!!!!!!!! You're a life saver
Re: Fun with ThinkScript
August 06, 2018 12:00PM
Maybe this has been asked before and is now lost in the 75 pages of this thread.

Anyone know how to add a Quarterly chart to ThinkorSwim??? Seems to be about the only thing missing.


My apologies if this has been covered and I missed it.
Re: Problems with this study
August 07, 2018 11:49AM
thanks regal just wondering if you can add a alert code to the wolf wave when stop tigers
Re: Problems with this study
August 07, 2018 01:47PM
OptionMaster

I don't have the wolf script. You need to post it and then I could add the alerts.



Edited 1 time(s). Last edit at 08/07/2018 01:48PM by rigel.
Re: Problems with this study
August 07, 2018 05:12PM
well the problem is i bought the study on here, and don't want to give the code out for everyone, so is there a way to send to u so it is not posted?

also thank you for getting back to me
ADD ALERTS
August 07, 2018 05:16PM
Can i get help with adding sound alerts and window pop up when targets are hit on this study script


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

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: Problems with this study
August 08, 2018 02:57AM
OptionMaster

You can send me the code by Private message.


rgds
Rigel



Edited 1 time(s). Last edit at 08/08/2018 03:01AM by rigel.
Sorry, only registered users may post in this forum.

Click here to login