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
December 02, 2016 08:54AM
UGH - I'm an idiot.

I had almost this exactly, but I was inserting the average before defining WHAT I was averaging, so it was averaging everything both times.
Robert: 13 Sell/Buy Signal Script
December 02, 2016 11:16AM
Robert,

A well known successful trader named Chris Mercer from tradesight.com uses a study that uses bar signals based on 13, have you seen this study? Is there a way to re create it for thinkscript?

thanks

Dave
Re: Fun with ThinkScript
December 03, 2016 04:13AM
Hi,

I'm trying to use the ZigZagHighLow study to identify key highs and lows and compare current price to them but I haven't been able to figure out how to store the high/low values of the ZZ plot so that I can reference them. Not sure if that would entail using a recursive function or what not. Is there any way to store the values of the last high and last low so that they can be compared to current price?

Thanks,

Forrest
Re: Fun with ThinkScript
December 03, 2016 06:06AM
Here is a Squeeze Indicator that resemble to TTM_Squeez of John Carter , I wand only the code of Histogram , anyone please can modify it ?

======

declare lower;

input Length = 20; # Length for Avg True Range & Std. Dev Calcs

input Price = Close; # type of price to use

input minPriceMove = 1; # for scaling

input priceIncrement = 0.01;

input nK = 1.5; # Keltner Channel ATRs from Average

input nBB = 2; # Bollinger Band Std. Devs. from Average

input AlertLine = 1; # BBS_Index level at which to issue alerts

input SqueezeOnColor = 2;

input SqueezeOffColor = 6;



# scaling factor :

def LHMult = If (priceIncrement <> 0, (minPriceMove / priceIncrement), 0);



# Average True Range

def ATR = Average(TrueRange(high, close, low), Length);

# Standard Deviation

def SDev = StDev(Price, Length);



# -- Calculate Bollinger Band Squeeze Indicator --

# for alert

def Denom = (nK * ATR);

def BBS_Ind = If (Denom <> 0, ((nBB * SDev) / Denom), 0);



# -- Plot the Index & Alert Line -------------------------

plot BBS_Index = 0;

BBS_Index.AssignValueColor(if BBS_Ind < AlertLine then Color.RED else Color.BLUE);

BBS_Index.SetStyle(4);

BBS_Index.SetLineWeight(2);

# --------------------------------------------------------



# -- Plot delta of price from Donchian mid line ----------

# Inertia = LinearRegValue

def LinearRegValue = Inertia(Price - ((Highest(high, Length) + Lowest(low, Length)) / 2 + ExpAverage(close, Length)) / 2, Length);



#Plot the Green Values

def LRVGreens = If (LinearRegValue >= 0, LinearRegValue, 0);

plot BBSqueeze_Pos = LRVGreens * LHMult;

BBSqueeze_Pos.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

BBSqueeze_Pos.AssignValueColor(if LRVGreens > LRVGreens[1] then Color.GREEN else Color.DARK_GREEN);

BBSqueeze_Pos.SetLineWeight(2);



#Plot the Red Values

def LRVReds = If (LinearRegValue < 0, LinearRegValue, 0);

plot BBSqueeze_Neg = LRVReds * LHMult;

BBSqueeze_Neg.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

BBSqueeze_Neg.AssignValueColor(if LRVReds < LRVReds[1] then Color.RED else Color.DARK_RED);

BBSqueeze_Neg.SetLineWeight(2);



#Show Alert Dots

# SQUEEZE ON

def BBS_CrossOverAlert = If (BBS_Ind > BBS_Ind[1] and (BBS_Ind > AlertLine) and (BBS_Ind[1] < AlertLine), (LRVGreens * LHMult + 150 * minPriceMove), 0);

plot CrossOverAlert = if BBS_CrossOverAlert > 0 then BBS_CrossOverAlert else Double.NaN;

CrossOverAlert.SetPaintingStrategy(PaintingStrategy.POINTS);

CrossOverAlert.SetLineWeight(4);

CrossOverAlert.AssignValueColor(Color.LIGHT_GREEN);

CrossOverAlert.AssignValueColor(GetColor(SqueezeOnColor));

# Alert("BB Squeeze Alert"winking smiley;


def BBS_CrossUnderAlert = If (BBS_Ind < BBS_Ind[1] and (BBS_Ind < AlertLine) and (BBS_Ind[1] > AlertLine), (LRVReds * LHMult - 150 * minPriceMove), 0);

plot CrossUnderAlert = if BBS_CrossUnderAlert < 0 then BBS_CrossUnderAlert else Double.NaN;

CrossUnderAlert.SetPaintingStrategy(PaintingStrategy.POINTS);

CrossUnderAlert.SetLineWeight(4);

CrossUnderAlert.AssignValueColor(GetColor(SqueezeOffColor)); # Color.Light_red);


=======
Re: Fun with ThinkScript
December 03, 2016 12:34PM
In a watch list script that returns 1.0's and 0.0's in the column, is there anyway to write it so that the 1's will show the letter ‘F’ (in yellow) instead? Thank you, JM.


plot X = close[2] <= open[2];

X.AssignValueColor
(if X
then color.Yellow

else color.Black);
Re: Fun with ThinkScript
December 06, 2016 01:04PM
Robert,

I have been trying to code a script for the volume point of control (POC) as it develops but am having some difficulty. Basically we know the Point of Control changes throughout the trading day so I would like to see where that point moves to throughout the day. Is this possible? My simplistic code is below but it is not doing what I want. Right now all I am getting is the POC for the time periods defined in the script (every 15 minutes); which helps but is not what I'm looking for. Any assistance is appreciated.

Many Thanks,
Mike

#StartScript;

def yyyymmdd = GetYYYYMMDD();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));


def FirstBar = SecondsFromTime(0945) >= 0 and SecondsFromTime(0945) < 60 or SecondsFromTime(1000) >= 0 and SecondsFromTime(1000) < 60 or SecondsFromTime(1015) >= 0 and SecondsFromTime(1015) < 60 or SecondsFromTime(1030) >= 0 and SecondsFromTime(1030) < 60 or SecondsFromTime(1045) >= 0 and SecondsFromTime(1045) < 60 or SecondsFromTime(1100) >= 0 and SecondsFromTime(1100) < 60 or SecondsFromTime(1115) >= 0 and SecondsFromTime(1115) < 60 or SecondsFromTime(1130) >= 0 and SecondsFromTime(1130) < 60 or SecondsFromTime(1145) >= 0 and SecondsFromTime(1145) < 60 or SecondsFromTime(1200) >= 0 and SecondsFromTime(1200) < 60 or SecondsFromTime(1215) >= 0 and SecondsFromTime(1215) < 60 or SecondsFromTime(1230) >= 0 and SecondsFromTime(1230) < 60 or SecondsFromTime(1245) >= 0 and SecondsFromTime(1245) < 60 or SecondsFromTime(1300) >= 0 and SecondsFromTime(1300) < 60 or SecondsFromTime(1315) >= 0 and SecondsFromTime(1315) < 60 or SecondsFromTime(1330) >= 0 and SecondsFromTime(1330) < 60 or SecondsFromTime(1345) >= 0 and SecondsFromTime(1345) < 60 or SecondsFromTime(1400) >= 0 and SecondsFromTime(1400) < 60 or SecondsFromTime(1415) >= 0 and SecondsFromTime(1415) < 60 or SecondsFromTime(1430) >= 0 and SecondsFromTime(1430) < 60 or SecondsFromTime(1445) >= 0 and SecondsFromTime(1445) < 60 or SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) < 60 or SecondsFromTime(1515) >= 0 and SecondsFromTime(1515) < 60 or SecondsFromTime(1530) >= 0 and SecondsFromTime(1530) < 60 or SecondsFromTime(1545) >= 0 and SecondsFromTime(1545) < 60 or SecondsFromTime(1600) >= 0 and SecondsFromTime(1600) < 60;


def cond = firstbar;
profile VP = VolumeProfile(pricePerRow = PricePerRow.TICKSIZE, startNewProfile = cond, onExpansion = no);
VP.Show(color = Color.BLACK, "volume poc color" = Color.BLUE);

plot VPOC = VP.GetPointOfControl();
VPOC.SetPaintingStrategy(PaintingStrategy.DASHES);
VPOC.SetDefaultColor(GetColor(9));

#EndScript
Re: Fun with ThinkScript
December 06, 2016 11:03PM
Does anyone know how to alter a script to show the price the stock is at when a Stochastic crossover occurs?

StochasticSlow("k period" = 9, "d period" = 9)."SlowK" crosses above StochasticSlow("k period" = 9, "d period" = 9)."SlowD"


Thanks, JM.
Re: Fun with ThinkScript
December 07, 2016 09:28AM
Need some help with a scan.

I am trying to scan that will show results when ADX is increasing and above 25



Edited 2 time(s). Last edit at 12/07/2016 09:32AM by TexasJohn.
Re: Fun with ThinkScript
December 07, 2016 09:33AM
Ralph53 Wrote:
-------------------------------------------------------
> Does anyone know how to alter a script to show the
> price the stock is at when a Stochastic crossover
> occurs?
>
> StochasticSlow("k period" = 9, "d period" =
> 9)."SlowK" crosses above StochasticSlow("k period"
> = 9, "d period" = 9)."SlowD"
>
>
> Thanks, JM.

Ralph - you can add a vertical line with the name plus the close of the bar it crosses at.

Do it like this....

def Bullish = SlowK crosses above SlowD;
def Bearish = SlowD crosses above SlowK;

AddVerticalLine(Bullish, "X Up @: " +close, Color.GREEN, Curve.POINTS);
AddVerticalLine(Bullish, "X Dn @: " +close, Color.RED, Curve.POINTS);
Re: Fun with ThinkScript
December 07, 2016 12:52PM
Thanks devildriver6 it looks great. I tinkered with it and came up with this;

# Stochastic Crossover Line On Chart #
def SlowK = StochasticSlow("k period" = 9, "d period" = 9)."SlowK";
def SlowD = StochasticSlow("k period" = 9, "d period" = 9)."SlowD";

def Bearish = SlowD crosses above SlowK;
def Bullish = SlowK crosses above SlowD;

AddVerticalLine(Bearish, "Up @: " +close, Color.Red, Curve.Short_Dash);
AddVerticalLine(Bullish, "Dn @: " +close, Color.Green, Curve.Short_Dash);



Do you know if there's a way to script for the price value at the bottom of each line? I need to add that value to another script.
I think it would look like this only in Thinkscript;

Plot ( Price @ Crossover Point ) = ( @: " +close );



Edited 2 time(s). Last edit at 12/07/2016 12:55PM by Ralph53.
Re: Fun with ThinkScript
December 07, 2016 01:14PM
Ralph53 Wrote:
-------------------------------------------------------
> Thanks devildriver6 it looks great. I tinkered
> with it and came up with this;
>
> # Stochastic Crossover Line On Chart #
> def SlowK = StochasticSlow("k period" = 9, "d
> period" = 9)."SlowK";
> def SlowD = StochasticSlow("k period" = 9, "d
> period" = 9)."SlowD";
>
> def Bearish = SlowD crosses above SlowK;
> def Bullish = SlowK crosses above SlowD;
>
> AddVerticalLine(Bearish, "Up @: " +close,
> Color.Red, Curve.Short_Dash);
> AddVerticalLine(Bullish, "Dn @: " +close,
> Color.Green, Curve.Short_Dash);
>
>
> Do you know if there's a way to script for the
> price value at the bottom of each line? I need to
> add that value to another script.
> I think it would look like this only in
> Thinkscript;
>
> Plot ( Price @ Crossover Point ) = ( @: " +close
> );


Not sure what you're asking here.
Which lines are you wanting to plot which price on exactly?
Re: Fun with ThinkScript
December 07, 2016 02:02PM
That was quick. I had an idea I've been working on. The way the previous script is the price is on the line at the bottom of the chart ( $53.21 ). I wanted to use the price value at the crossover ( $53.21 ) in another script. I'm actually trying to plot the point when the stock goes .50 cents above (or below) the crossover price. This way I'll know if the crossover has movement behind it. The idea looks like this, but I need what's in red converted to ThinkScript;

def P = ( Price @ Crossover Point );

Plot X = Close >= P +.50;


I've never come across anything like this and I don't know if it can be done. Thanks again.
Re: Fun with ThinkScript
December 07, 2016 02:20PM
Ralph53 Wrote:
-------------------------------------------------------
> Thanks devildriver6 it looks great. I tinkered
> with it and came up with this;
>
> # Stochastic Crossover Line On Chart #
> def SlowK = StochasticSlow("k period" = 9, "d
> period" = 9)."SlowK";
> def SlowD = StochasticSlow("k period" = 9, "d
> period" = 9)."SlowD";
>
> def Bearish = SlowD crosses above SlowK;
> def Bullish = SlowK crosses above SlowD;
>
> AddVerticalLine(Bearish, "Up @: " +close,
> Color.Red, Curve.Short_Dash);
> AddVerticalLine(Bullish, "Dn @: " +close,
> Color.Green, Curve.Short_Dash);
>
>
> Do you know if there's a way to script for the
> price value at the bottom of each line? I need to
> add that value to another script.
> I think it would look like this only in
> Thinkscript;
>
> Plot ( Price @ Crossover Point ) = ( @: " +close
> );


I gotcha.

So, if you use a REC, it'll save that data, and you can even plot it as a line on the chart.
Like this....

(added below your existing script)

def SlowK = StochasticSlow("k period" = 9, "d period" = 9)."SlowK";
def SlowD = StochasticSlow("k period" = 9, "d period" = 9)."SlowD";

def Bearish = SlowD crosses above SlowK;
def Bullish = SlowK crosses above SlowD;

AddVerticalLine(Bearish, "Dn @: " +close, Color.Red, Curve.Short_Dash);
AddVerticalLine(Bullish, "Up @: " +close, Color.Green, Curve.Short_Dash);

rec CrossUpPrice = if Bullish then close else CrossUpPrice[1];
plot XUp = CrossUpPrice;

rec CrossDnPrice = if Bearish then close else CrossDnPrice[1];
plot XDn = CrossDnPrice;

XUp.setpaintingStrategy(paintingStrategy.HORIZONTAL);
XUp.setdefaultColor(color.green);

XDn.setpaintingStrategy(paintingStrategy.HORIZONTAL);
XDn.setdefaultColor(color.red);



These will save the price until the next existence of the same crossover.
In other words, the CrossUpPrice will be the same until the next time the Bullish condition triggers, and same as CrossDownPrice.

This will allow you to track that occurrence and movement from it.






Edited 3 time(s). Last edit at 12/07/2016 02:30PM by devildriver6.
Re: Fun with ThinkScript
December 07, 2016 02:59PM
Thanks again.
Re: Fun with ThinkScript
December 10, 2016 12:39AM
I was messing with this simple Recursive Variable script idea;

rec Up = close >= Highest(Open,6);
plot X = Up;


In a watch list column it only gives a yes or no indication. Is there any way to get a Recursive Variable to plot the actual price when the last (close >= Highest(Open,6)) occurred or does it only work that way with crossovers of actual studies like MACD or Stochastics?

Thanks, JM.
Re: Fun with ThinkScript
December 10, 2016 05:25AM
Ralph53 Wrote:
-------------------------------------------------------
> I was messing with this simple Recursive Variable
> script idea;
>
> rec Up = close >= Highest(Open,6);
> plot X = Up;
>
> In a watch list column it only gives a yes or no
> indication. Is there any way to get a Recursive
> Variable to plot the actual price when the last
> (close >= Highest(Open,6)) occurred or does it
> only work that way with crossovers of actual
> studies like MACD or Stochastics?
>
> Thanks, JM.


Sure... that would look something like this.
Also, there's no need for the usage of a recursive variable in this instance.

The code will only provide what you tell it to.
So, in your example, you were asking it to return whether or not the condition existed.
In mine below, I'm telling it to provide me either the close, if the condition exists, or nothing, if it does not.
See the difference?


def Up = close >= Highest(Open,6);
plot X = if Up then close else no;

X.assignvalueColor(if Up then color.black else color.current);
#Hint: this makes the text color black when the background is yellow upon confirmation of this condition.

assignbackgroundColor(if Up then color.yellow else color.current);
#Hint: This makes the background yellow upon confirmation of this condition.

The last column is what it would look like w/ aggregation set to DAILY.
(after taking the pic, I changed the code from double.nan to a simple no... no shows a 0 value, whereas a double.nan shows a NaN value when the condition isn't present)


Re: Fun with ThinkScript
December 10, 2016 02:29PM
I gave you the wrong script last night but I think a Recursive Variable is not what I need (and doesn't work in my situation).

How can I get the the Open Price value of the candle when plot X hits;

Plot X = Close >= Open;


Thanks, JM.
Re: Fun with ThinkScript
December 10, 2016 03:06PM
Ralph53 Wrote:
-------------------------------------------------------
> I gave you the wrong script last night but I think
> a Recursive Variable is not what I need (and
> doesn't work in my situation).
>
> How can I get the the Open Price value of the
> candle when plot X hits;
>
> Plot X = Close >= Open;
>
>
> Thanks, JM.

Any variation of the same thing I posted before.

## Define a Condition you want to confirm.
def Condition = Close >= Open;


## Plot the info you want upon confirmation.
Plot ConditionConfirmed = if Condition then Open else double.nan;


## Assign the value color for the text (opposite from the background).
ConditionConfirmed.assignvalueColor(if Condition then color.black else color.current);


## Finally, assign the background color (opposite from the text coloring).
assignbackgroundColor(if Condition then color.yellow else color.current);


Re: Fun with ThinkScript
December 10, 2016 04:28PM
If someone could please help me with the following, I would be extremely grateful.

I am trying to create a study that provides a score of "1" everytime the market ends the day above the 5 minute opening range, and provides a score of "-1" everytime it ends the day below the opening range. From here, I will keep a score for the last 10 days, by adding the most recent 10 days "1s" and "-1s" together, which I will then use the "addlabel" function so I can quickly see the daily running total on my 5-minute chart.

#Here is my opening range formula which is working fine:

def mybarcount = RoundUp((SecondsFromTime(0930) / (ORminutes * 60)), 0);
def orHigh = GetValue(high, mybarcount);
def orLow = GetValue(low, mybarcount);

Here is a sample of the code that I am trying to use to calculate the the running totals (that is not working correctly):

def u1 = if close > orHigh then 1 else 0;
def u2 = if close[1] > orHigh[1] then 1 else 0;

In simple English, what I am looking for in the above formulas is the following:

"If today's close is higher than today's opening range high, then 1, else 0."
"If yesterday's close is higher than yesterday's opening range high, then 1, else 0."


Once I get correct these formulas, I have a simple summation formula that will add each days results together, giving me a running total score.

Can anyone please help me with this?



Edited 2 time(s). Last edit at 12/10/2016 04:30PM by SMcTrader.
Re: Fun with ThinkScript
December 10, 2016 05:13PM
TexasJohn Wrote:
-------------------------------------------------------
> Need some help with a scan.
>
> I am trying to scan that will show results when
> ADX is increasing and above 25


This should work for either a scan, or a watchlist.
Set the aggregation as needed...

input length = 14;
input averageType = AverageType.WILDERS;

def ADX = DMI(length, averageType).ADX;

def Condition = ADX >= 25 && ADX >= ADX[1];

plot Confirmed = if Condition then ADX else double.nan;
Confirmed.assignValueColor(if Condition then color.black else color.current);

assignbackgroundColor(if Condition then color.yellow else color.current);
Re: Fun with ThinkScript
December 10, 2016 05:28PM
SARA Wrote:
-------------------------------------------------------
> Here is a Squeeze Indicator that resemble to
> TTM_Squeez of John Carter , I wand only the code
> of Histogram , anyone please can modify it ?
>
> ======
>
> declare lower;
>
> input Length = 20; # Length for Avg True Range &
> Std. Dev Calcs
>
> input Price = Close; # type of price to use
>
> input minPriceMove = 1; # for scaling
>
> input priceIncrement = 0.01;
>
> input nK = 1.5; # Keltner Channel ATRs from
> Average
>
> input nBB = 2; # Bollinger Band Std. Devs. from
> Average
>
> input AlertLine = 1; # BBS_Index level at which to
> issue alerts
>
> input SqueezeOnColor = 2;
>
> input SqueezeOffColor = 6;
>
>
>
> # scaling factor :
>
> def LHMult = If (priceIncrement <> 0,
> (minPriceMove / priceIncrement), 0);
>
>
>
> # Average True Range
>
> def ATR = Average(TrueRange(high, close, low),
> Length);
>
> # Standard Deviation
>
> def SDev = StDev(Price, Length);
>
>
>
> # -- Calculate Bollinger Band Squeeze Indicator
> --
>
> # for alert
>
> def Denom = (nK * ATR);
>
> def BBS_Ind = If (Denom <> 0, ((nBB * SDev) /
> Denom), 0);
>
>
>
> # -- Plot the Index & Alert Line
> -------------------------
>
> plot BBS_Index = 0;
>
> BBS_Index.AssignValueColor(if BBS_Ind < AlertLine
> then Color.RED else Color.BLUE);
>
> BBS_Index.SetStyle(4);
>
> BBS_Index.SetLineWeight(2);
>
> #
> --------------------------------------------------
> ------
>
>
>
> # -- Plot delta of price from Donchian mid line
> ----------
>
> # Inertia = LinearRegValue
>
> def LinearRegValue = Inertia(Price -
> ((Highest(high, Length) + Lowest(low, Length)) / 2
> + ExpAverage(close, Length)) / 2, Length);
>
>
>
> #Plot the Green Values
>
> def LRVGreens = If (LinearRegValue >= 0,
> LinearRegValue, 0);
>
> plot BBSqueeze_Pos = LRVGreens * LHMult;
>
> BBSqueeze_Pos.SetPaintingStrategy(PaintingStrategy
> .HISTOGRAM);
>
> BBSqueeze_Pos.AssignValueColor(if LRVGreens >
> LRVGreens[1] then Color.GREEN else
> Color.DARK_GREEN);
>
> BBSqueeze_Pos.SetLineWeight(2);
>
>
>
> #Plot the Red Values
>
> def LRVReds = If (LinearRegValue < 0,
> LinearRegValue, 0);
>
> plot BBSqueeze_Neg = LRVReds * LHMult;
>
> BBSqueeze_Neg.SetPaintingStrategy(PaintingStrategy
> .HISTOGRAM);
>
> BBSqueeze_Neg.AssignValueColor(if LRVReds <
> LRVReds[1] then Color.RED else Color.DARK_RED);
>
> BBSqueeze_Neg.SetLineWeight(2);
>
>
>
> #Show Alert Dots
>
> # SQUEEZE ON
>
> def BBS_CrossOverAlert = If (BBS_Ind > BBS_Ind[1]
> and (BBS_Ind > AlertLine) and (BBS_Ind[1] <
> AlertLine), (LRVGreens * LHMult + 150 *
> minPriceMove), 0);
>
> plot CrossOverAlert = if BBS_CrossOverAlert > 0
> then BBS_CrossOverAlert else Double.NaN;
>
> CrossOverAlert.SetPaintingStrategy(PaintingStrateg
> y.POINTS);
>
> CrossOverAlert.SetLineWeight(4);
>
> CrossOverAlert.AssignValueColor(Color.LIGHT_GREEN)
> ;
>
> CrossOverAlert.AssignValueColor(GetColor(SqueezeOn
> Color));
>
> # Alert("BB Squeeze Alert"winking smiley;
>
>
> def BBS_CrossUnderAlert = If (BBS_Ind < BBS_Ind[1]
> and (BBS_Ind < AlertLine) and (BBS_Ind[1] >
> AlertLine), (LRVReds * LHMult - 150 *
> minPriceMove), 0);
>
> plot CrossUnderAlert = if BBS_CrossUnderAlert < 0
> then BBS_CrossUnderAlert else Double.NaN;
>
> CrossUnderAlert.SetPaintingStrategy(PaintingStrate
> gy.POINTS);
>
> CrossUnderAlert.SetLineWeight(4);
>
> CrossUnderAlert.AssignValueColor(GetColor(SqueezeO
> ffColor)); # Color.Light_red);
>
>
> =======


Sara -
I have one that's identical to TTM, but it's broken into the upper histogram and lower histogram, like the one you posted.
I haven't seen one yet with the two consolidated.

BBSqueeze_Pos and BBSqueeze_Neg are the two histograms.

What exactly are you looking to do with this?
Re: Fun with ThinkScript
December 10, 2016 05:32PM
4XTycoon Wrote:
-------------------------------------------------------
> Hi,
>
> I'm trying to use the ZigZagHighLow study to
> identify key highs and lows and compare current
> price to them but I haven't been able to figure
> out how to store the high/low values of the ZZ
> plot so that I can reference them. Not sure if
> that would entail using a recursive function or
> what not. Is there any way to store the values of
> the last high and last low so that they can be
> compared to current price?
>
> Thanks,
>
> Forrest


Forrest -
This zig zag code stores the PRICEH and PRICEL, plots bubbles (optional), so on and so forth.
Could be a start for you in what you're looking for...

#ZigZagHL_Avg_SupplyDemand_FibExt_FibRet_Volume
#TOS version ZigZagHighLow modified in part by Linus' and Lar's code
input method = {default average, high_low};
input bubbleoffset = .0005;
input percentamount = .01;
input revAmount = .05;
input atrreversal = 3.0;
input atrlength = 5;
input pricehigh = high;
input pricelow = low;
input averagelength = 5;
input averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def zz = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == priceh then priceh else pricel) - GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
plot zzp = if zzd <= 1 then zz else Double.NaN;
zzp.AssignValueColor(if zzd == 1 then Color.GREEN else if zzd == 0 then Color.RED else Color.DARK_ORANGE);
zzp.SetStyle(Curve.FIRM);
zzp.EnableApproximation();
zzp.HideBubble();
#Price Change between zigzags
def xxhigh = if zzSave == priceh then priceh else xxhigh[1];
def chghigh = priceh - xxhigh[1];
def xxlow = if zzSave == pricel then pricel else xxlow[1];
def chglow = pricel - xxlow[1];
input showBubbleschange = no;
AddChartBubble(showBubbleschange and !IsNaN(zz) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , "$" + chg , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);
#Price at High/Low
input showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(zz) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then "$" + priceh else "$" + pricel , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);
#Label for Confirmed/Unconfirmed Status of Current Zigzag
AddLabel(BarNumber() != 1, (if isConf then "Confirmed " else "Unconfirmed "winking smiley + "ZigZag: " + chg + " ATRev " + Round(reference ATR(atrlength) * atrreversal, 2) + " RevAmt " + Round(reversalAmount, 2), if !isConf then Color.DARK_ORANGE else if isUp then Color.GREEN else Color.RED);
#Bar Count between zigzags
rec zzcount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzcount[1] + 1 else 0;
def zzcounthilo = if zzcounthilo[1] == 0 and (zzSave == priceh or zzSave == pricel) then 1 else if zzSave == priceh or zzSave == pricel then zzcounthilo[1] + 1 else zzcounthilo[1];
def zzhilo = if zzSave == priceh or zzSave == pricel then zzcounthilo else zzcounthilo + 1;
def zzcounthigh = if zzSave == priceh then zzcount[1] else Double.NaN;
def zzcountlow = if zzSave == pricel then zzcount[1] else Double.NaN;
input showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(zz) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if zzSave == priceh then zzcounthigh else zzcountlow, if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no );
#Arrows
def zzL = if !IsNaN(zz) and !isUp then pricel else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then priceh else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] or pricel == zzL[1] and pricel == zzSave then 1 else if zzH != zzH[1] or priceh == zzH[1] and priceh == zzSave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < zzH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
input showarrows = no;
plot U1 = showarrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showarrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);
#Alerts
input usealerts = no;
Alert(usealerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(usealerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
rec data1 = CompoundValue(1, if (zzSave == priceh or zzSave == pricel) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
input numbersuppdemandtoshow = 0;
input showSupplyDemand = {default Pivot, Arrow, None};
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;
if signal crosses 0 {
rLow = pricel[idx];
rHigh = priceh[idx];
} else {
rLow = rLow[1];
rHigh = rHigh[1];
}
plot HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

plot LowLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

input showsupplydemandcloud = no;
AddCloud(if showsupplydemandcloud then hlUp else Double.NaN, LowLine, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showsupplydemandcloud then hlDn else Double.NaN, LowLine, Color.LIGHT_RED, Color.LIGHT_RED);
#Store Previous Data
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
rec priorzz1 = if zzsave2 != zzsave2[1] then zzsave2[1] else priorzz1[1];
rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];
#Fibonacci Extensions
rec data = CompoundValue(1, if (zzSave == priceh or zzSave == pricel) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
input numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
input showFibExtLines = no;
input showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) * 1
else extfib1[1];
plot extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
extfib100.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100.SetDefaultColor(Color.RED);
extfib100.SetLineWeight(1);
extfib100.HideBubble();
def extfib1a = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) * 0.382
else extfib1a[1];
plot extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
extfib382.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib382.SetDefaultColor(Color.RED);
extfib382.SetLineWeight(1);
extfib382.HideBubble();
def extfib2 = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2[1];
plot extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0 then extfib2[1] else Double.NaN;
extfib618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618.SetDefaultColor(Color.RED);
extfib618.SetLineWeight(1);
extfib618.HideBubble();
def extfib3 = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3[1];
plot extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3) and dir < 0 and cpo != 0 then extfib3[1] else Double.NaN;
extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618.SetDefaultColor(Color.RED);
extfib1618.SetLineWeight(1);
extfib1618.HideBubble();
def extfib3a = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) *
2.000 else extfib3a[1];
plot extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a) and dir < 0 and cpo != 0 then extfib3a[1] else Double.NaN;
extfib2000.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2000.SetDefaultColor(Color.RED);
extfib2000.SetLineWeight(1);
extfib2000.HideBubble();
def extfib4 = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4[1];
plot extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0 and cpo != 0 then extfib4[1] else Double.NaN;
extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618.SetDefaultColor(Color.RED);
extfib2618.SetLineWeight(1);
extfib2618.HideBubble();
def extfib5 = if zzSave == priceh then priceh - AbsValue(priorzz2 - priorzz1) *
3.618 else extfib5[1];
plot extfib3618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0 and cpo != 0 then extfib5[1] else Double.NaN;
extfib3618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib3618.SetDefaultColor(Color.RED);
extfib3618.SetLineWeight(1);
extfib3618.HideBubble();
def extfib1_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) * 1
else extfib1_[1];
plot extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100_.SetDefaultColor(Color.GREEN);
extfib100_.SetLineWeight(1);
extfib100_.HideBubble();
def extfib1a_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) * 0.382
else extfib1a_[1];
plot extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
extfib382_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib382_.SetDefaultColor(Color.GREEN);
extfib382_.SetLineWeight(1);
extfib382_.HideBubble();
def extfib2_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2_[1];
plot extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0 and cpo != 0 then extfib2_[1] else Double.NaN;
extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618_.SetDefaultColor(Color.GREEN);
extfib618_.SetLineWeight(1);
extfib618_.HideBubble();
def extfib3_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3_[1];
plot extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0 and cpo != 0 then extfib3_[1] else Double.NaN;
extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618_.SetDefaultColor(Color.GREEN);
extfib1618_.SetLineWeight(1);
extfib1618_.HideBubble();
def extfib3a_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) *
2.000 else extfib3a_[1];
plot extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0 and cpo != 0 then extfib3a_[1] else Double.NaN;
extfib2000_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2000_.SetDefaultColor(Color.GREEN);
extfib2000_.SetLineWeight(1);
extfib2000_.HideBubble();
def extfib4_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4_[1];
plot extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0 and cpo != 0 then extfib4_[1] else Double.NaN;
extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618_.SetDefaultColor(Color.GREEN);
extfib2618_.SetLineWeight(1);
extfib2618_.HideBubble();
def extfib5_ = if zzSave == pricel then pricel + AbsValue(priorzz2 - priorzz1) *
3.618 else extfib5_[1];
plot extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0 and cpo != 0 then extfib5_[1] else Double.NaN;
extfib3618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib3618_.SetDefaultColor(Color.GREEN);
extfib3618_.SetLineWeight(1);
extfib3618_.HideBubble();
input fibextbubblespacesinexpansion = 8;
def b = fibextbubblespacesinexpansion;
def direction = if !isUp then 1 else 0;
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1[b + 2], "100%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1a[b + 2], "38.2%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib2[b + 2], "61.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3[b + 2], "161.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3a[b + 2], "200%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib4[b + 2], "261.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib5[b + 2], "361.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1_[b + 2], "100%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1a_[b + 2], "38.2%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib2_[b + 2], "61.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3_[b + 2], "161.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3a_[b + 2], "200%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib4_[b + 2], "261.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib5_[b + 2], "361.8%", Color.GREEN, yes);
#Volume at Reversals
def vol = if BarNumber() == 0 then 0 else volume + vol[1];
def vol1 = if BarNumber() == 1 then volume else vol1[1];
def xxvol = if zzSave == priceh or zzSave == pricel then TotalSum(volume) else xxvol[1];
def chgvol = if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
input showBubblesVolume = no;
AddChartBubble(showBubblesVolume and !IsNaN(zz) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset), chgvol, if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no );

input usemanualfibskip = no;#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.
input fibskip = .50;#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.
input showBubblesfibratio = no;
input showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
input showfiblines = no;
input fib1level = .236;
input fib2level = .382;
input fibMlevel = .500;
input fib3level = .618;
input fib4level = .786;
#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
input numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def zzfibh = if zzSave == priceh and AbsValue(zzSave - zzSave[1]) > priceh * fibskipit * .01 then priceh else zzfibh[1];
def zzfibl = if zzSave == pricel and AbsValue(zzSave - zzSave[1]) > priceh * fibskipit * .01 then pricel else zzfibl[1];
def range = zzfibh - zzfibl;
plot fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibh else Double.NaN;
plot fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibl else Double.NaN;
plot fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibl + range * fibMlevel else Double.NaN;
plot fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibl + range * fib1level else Double.NaN;
plot fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibl + range * fib2level else Double.NaN;
plot fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibl + range * fib3level else Double.NaN;
plot fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then zzfibl + range * fib4level else Double.NaN;
fibH.SetPaintingStrategy(PaintingStrategy.DASHES);
fibL.SetPaintingStrategy(PaintingStrategy.DASHES);
fibH.SetLineWeight(2);
fibL.SetLineWeight(2);
fibM.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fib4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
fibH.SetDefaultColor(Color.GREEN);
fibL.SetDefaultColor(Color.RED);
fibM.SetDefaultColor(Color.WHITE);
fib1.SetDefaultColor(Color.CYAN);
fib2.SetDefaultColor(Color.YELLOW);
fib3.SetDefaultColor(Color.YELLOW);
fib4.SetDefaultColor(Color.CYAN);
fibH.HideBubble();
fibL.HideBubble();
fibM.HideBubble();
fib1.HideBubble();
fib2.HideBubble();
fib3.HideBubble();
fib4.HideBubble();

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - zzfibl) / (range))), if close > zzfibl then Color.GREEN else if zzfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(zz) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - zzfibl) / (range)) else AsPercent((pricel - zzfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);
Re: Fun with ThinkScript
December 10, 2016 10:57PM
Thanks for your time devildriver6. Some more tinkering and I've come up with something that works and is very close to what I'm looking for;


def Condition = Close <= Open;

Plot ConditionConfirmed = if Condition then Close - Highest(Open, 4) else double.nan;



I don't want to use Highest(Open, 4). What I'm trying to do is have the script keep counting the distance from the point of 'ConditionConfirmed' until this point is reached ( Close > Open ). Then stop until the next 'ConditionConfirmed' point is reached. Then the cycle starts all over again.

Can this be done? Thanks, JM.
Re: Fun with ThinkScript
December 11, 2016 12:15AM
Is this a daily aggregation you're looking at, or something smaller?

it helps if I have all the ideas and intentions in order to figure this out.
Looking for volume alert with sound or pop up window
December 11, 2016 12:46AM
Hi,

I just found this forum. Thanks for all your hard work. I am horrible at coding/scripting. Can anyone help me create a script so when volume on 1 minute or 5 minute chart surpasses "x" volume(x=5000, for example), it will alert via either sound or pop up window?

Much thanks in advance.
Calculate angle like tredline
December 11, 2016 09:41PM
Hi,
does anybody know if it is possible to calculate the angle between two points so for example angle between HlC3 from 5 bars ago till today?
I know ATAN is supposed to calculate angle but I don't think I am using it correctly.
Re: Fun with ThinkScript
December 12, 2016 12:22AM
It's 1 Minute devildriver6. What I'm trying to do is calculate the distance in cents from any point on a chart. Not just from crossover points. This will be a very useful script to have if it can be done because it will tell the size of any up thrust from anywhere in its cycle.



Edited 6 time(s). Last edit at 12/12/2016 12:23PM by Ralph53.
Re: Looking for volume alert with sound or pop up window
December 12, 2016 01:15AM
Mr. Bond; 'X' Volume might not be what you want because each stock will react differently to 'X' (whatever you pick). Try this Add Label on a chart it uses TOS's Volume Average on a 1 minute candle. It's simple but useful and gives you the 1 minute percentage above or below the average;

# Add Label Volume/Volume Average #
input length = 50;

def Vol = volume;
def VA = Average(volume, length);
def V = round(Vol/VA);
Def CU = Close >= Open;

AddLabel(yes, "⇑ VA " + V + "% ",

(if V >= +8.00 and CU
then color.White

else if V >= +5.00 and CU
then color.Yellow

else if V >= +1.00 and CU
then color.Green

else if V >= +0.75 and CU
then color.Dark_Green

else if V >= +0.50 and CU
then color.Dark_Gray

else color.Dark_Red));



If you only want up candles make the last color .Black;


This should work as a lower study on a chart instead of the regular Volume colors;


# Chart - Volume/Volume Average #
input length = 50;

def Vol = volume;
def VA = Average(volume, length);
def V = round(Vol/VA);
Def CU = Close >= Open;

Plot X = V;

X.AssignValueColor

(if V >= +8.00 and CU
then color.White

else if V >= +5.00 and CU
then color.Yellow

else if V >= +1.00 and CU
then color.Green

else if V >= +0.75 and CU
then color.Dark_Green

else if V >= +0.50 and CU
then color.Dark_Gray

else color.Dark_Red);



and this should work as an alert. You can change the bottom number to the percent value that you want; (PS. This won't work for 1 minute at the open because unless you're only on 1 stock you'll hear nothing but alerts going off continuously)


# Alert Volume/Volume Average #
input length = 50;

def Vol = volume;
def VA = Average(volume, length);
def V = round(Vol/VA);
Def CU = Close >= Open;

Plot X = V >= 1;



Hope this helps.



Edited 4 time(s). Last edit at 12/12/2016 10:19AM by Ralph53.
Re: Looking for volume alert with sound or pop up window
December 12, 2016 03:05AM
Hi Ralph53,

Thanks for your insight. I actually need the alert solely for CL(crude oil). I use volume so that when it is goes higher than "x" on 1 minute chart or "y" on 5 minute chart, then I look to fade the move at the next candle. So, I just need a script that will alert me once the volume crosses the threshold on either 1 or 5 minute chart as I have two charts up on my screen. My preference is to not use VolAvg but volume w/ an alert attached to it. Would you be able to help me with this?



Edited 2 time(s). Last edit at 12/12/2016 03:14AM by JamesBond.
Re: Calculate angle like tredline
December 12, 2016 04:54AM
Quote
strategynode
is possible to calculate the angle between two points

im not sure if this is what your looking for but below is the only example I'm familiar with. near the end of the script robert calculates the slope between two points. hope it helps.

http://www.researchtrade.com/forum/read.php?7,2258,5433#msg-5433
Sorry, only registered users may post in this forum.

Click here to login