Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Problems with this study
August 08, 2018 06:30AM
great. i will send to you today and thank you
Re: ADD ALERTS
August 08, 2018 01:20PM
OptionMaster Wrote:
-------------------------------------------------------
> Can i get help with adding sound alerts and window
> pop up when targets are hit on this study script

Add this code to the end of your script

Alert(Crosses(close, TH, CrossingDirection.ABOVE), "Target high crossed",alert.bar,Sound.Ring);
Alert(Crosses(close, TL, CrossingDirection.BELOW), "Target low crossed",alert.bar,Sound.Ring);

Re: Fun with ThinkScript
August 09, 2018 03:29AM
Quote
NMR
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 angles worth of a move:

A fellow coder once posted this, please check if this is what you need for your scan

#hint: Plots the tangent angle of the inputted average declare lower; 
input length = 9;#hint length:The number agg-bars of the average 
input price = close;#hint Price:The price choice being evaluated 


for lack of interest of the requester the rest of the code is removed

Note: All....... I'd appreciate if after giving some advice/code I receive back a comment...



Edited 4 time(s). Last edit at 08/10/2018 08:38AM by rigel.
thinkscript formula for adding the netchange
August 09, 2018 12:06PM
Hi all. Im sure this is easy to do but Im new and learning thinkscript. I basically want to add the dollar net change of two different stocks say like googl and nflx. Once it spits out that sum i then want to see what the trend is between the two which ill do manually. Can anyone help? Much appreciated!
Re: Centered Moving Average (CMA)
August 12, 2018 09:54PM
Rigel,

Thanks and I understand what you meant in the long answer.

Thanks again.
MetaTrader Convesion
August 12, 2018 09:58PM
Below is a script for the ALMA and seeing if anyone can convert it from meta to TOS.

Thanks in advance.


//+------------------------------------------------------------------+
//| ALMA_v2.mq5 |
//| ALMA by Arnaud Legoux / Dimitris Kouzis-Loukas |
//| www.arnaudlegoux.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| [finance.groups.yahoo.com] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010-12, TrendLaboratory"
#property link "[finance.groups.yahoo.com];
#property description "Arnaud Legoux Moving Average"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1

#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 Silver,DeepSkyBlue,OrangeRed
#property indicator_width1 2

input ENUM_TIMEFRAMES TimeFrame = 0;
input ENUM_APPLIED_PRICE Price = PRICE_CLOSE; //Apply to
input int Length = 9; //Window Size
input double Sigma = 6.0; //Sigma parameter
input double Offset = 0.85; //Offset of Gaussian distribution (0...1)
input int Shift = 0; //Shift in Bars
input int ColorMode = 0; //Color Mode(0-off,1-on)

double alma[];
double trend[];
double price[];

ENUM_TIMEFRAMES tf;
int mtf_handle, Price_handle;
double W[], mtf_alma[1], mtf_trend[1];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
if(TimeFrame <= Period()) tf = Period(); else tf = TimeFrame;
//--- indicator buffers mapping
SetIndexBuffer(0, alma, INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3);
SetIndexBuffer(1,trend, INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,price,INDICATOR_CALCULATIONS);
//---
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Length+1);
//---
PlotIndexSetInteger(0,PLOT_SHIFT,Shift);
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---
string short_name = "ALMA_v2["+timeframeToString(TimeFrame)+"]("+priceToString(Price)+","+(string)Length+","+(string)Sigma+","+(string)Offset+"winking smiley";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
PlotIndexSetString(0,PLOT_LABEL,"ALMA_v2["+timeframeToString(TimeFrame)+"]"winking smiley;
//---
Price_handle = iMA(NULL,TimeFrame,1,0,0,Price);

if(TimeFrame > 0) mtf_handle = iCustom(NULL,TimeFrame,"ALMA_v2",0,Price,Length,Sigma,Offset,Shift,ColorMode);
else
{
ArrayResize(W,Length);

double m = MathFloor(Offset*(Length - 1));
double s = Length/Sigma;
double wSum = 0;
for (int i=0;i < Length;i++)
{
W = MathExp(-((i-m)*(i-m))/(2*s*s));
wSum += W;
}

for (int i=0;i < Length;i++) W = W/wSum;
}
//--- initialization done
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,
const datetime &Time[],
const double &Open[],
const double &High[],
const double &Low[],
const double &Close[],
const long &TickVolume[],
const long &Volume[],
const int &Spread[])
{
int x, y, shift, limit, mtflimit, copied = 0;
datetime mtf_time;
//--- preliminary calculations
if(prev_calculated == 0)
{
limit = 0;
mtflimit = rates_total - 1;
ArrayInitialize(alma,EMPTY_VALUE);
}
else
{
limit = rates_total - 1;
mtflimit = rates_total - prev_calculated + PeriodSeconds(tf)/PeriodSeconds(Period());
}

copied = CopyBuffer(Price_handle,0,Time[rates_total-1],Time[0],price);

if(copied < 0)
{
Print("not all prices copied. Will try on next tick Error =",GetLastError(),", copied =",copied);
return(0);
}

//--- the main loop of calculations
if(tf > Period())
{
ArraySetAsSeries(Time,true);

for(shift=0,y=0;shift<mtflimit;shift++)
{
if(Time[shift] < iTime(NULL,TimeFrame,y)) y++;
mtf_time = iTime(NULL,TimeFrame,y);

copied = CopyBuffer(mtf_handle,0,mtf_time,mtf_time,mtf_alma);
if(copied <= 0) return(0);
x = rates_total - shift - 1;
alma[x] = mtf_alma[0];

if(ColorMode > 0)
{
copied = CopyBuffer(mtf_handle,1,mtf_time,mtf_time,mtf_trend);
if(copied <= 0) return(0);
trend[x] = mtf_trend[0];
}
else trend[x] = 0;
}
}
else
{
for(shift=limit;shift<rates_total;shift++)
{
if(shift < Length) continue;
double sum = 0.0;
for(int i = 0; i < Length; i++) sum += price[shift-(Length - 1 - i)]*W;

alma[shift] = sum;

if(shift < Length + 2) continue;

if(shift > 0)
{
if(ColorMode > 0 && alma[shift-1] > 0)
{
trend[shift] = trend[shift-1];
if(alma[shift] > alma[shift-1]) trend[shift] = 1;
if(alma[shift] < alma[shift-1]) trend[shift] = 2;
}
else trend[shift] = 0;
}
}
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
string timeframeToString(ENUM_TIMEFRAMES TF)
{
switch(TF)
{
case PERIOD_CURRENT : return("Current"winking smiley;
case PERIOD_M1 : return("M1"winking smiley;
case PERIOD_M2 : return("M2"winking smiley;
case PERIOD_M3 : return("M3"winking smiley;
case PERIOD_M4 : return("M4"winking smiley;
case PERIOD_M5 : return("M5"winking smiley;
case PERIOD_M6 : return("M6"winking smiley;
case PERIOD_M10 : return("M10"winking smiley;
case PERIOD_M12 : return("M12"winking smiley;
case PERIOD_M15 : return("M15"winking smiley;
case PERIOD_M20 : return("M20"winking smiley;
case PERIOD_M30 : return("M30"winking smiley;
case PERIOD_H1 : return("H1"winking smiley;
case PERIOD_H2 : return("H2"winking smiley;
case PERIOD_H3 : return("H3"winking smiley;
case PERIOD_H4 : return("H4"winking smiley;
case PERIOD_H6 : return("H6"winking smiley;
case PERIOD_H8 : return("H8"winking smiley;
case PERIOD_H12 : return("H12"winking smiley;
case PERIOD_D1 : return("D1"winking smiley;
case PERIOD_W1 : return("W1"winking smiley;
case PERIOD_MN1 : return("MN1"winking smiley;
default : return("Current"winking smiley;
}
}

string priceToString(ENUM_APPLIED_PRICE app_price)
{
switch(app_price)
{
case PRICE_CLOSE : return("Close"winking smiley;
case PRICE_HIGH : return("High"winking smiley;
case PRICE_LOW : return("Low"winking smiley;
case PRICE_MEDIAN : return("Median"winking smiley;
case PRICE_OPEN : return("Open"winking smiley;
case PRICE_TYPICAL : return("Typical"winking smiley;
case PRICE_WEIGHTED: return("Weighted"winking smiley;
default : return(""winking smiley;
}
}

datetime iTime(string symbol,ENUM_TIMEFRAMES TF,int index)
{
if(index < 0) return(-1);
static datetime timearray[];
if(CopyTime(symbol,TF,index,1,timearray) > 0) return(timearray[0]); else return(-1);
}
Re: MetaTrader Convesion
August 13, 2018 06:38AM
Quote
chillic15
Below is a script for the ALMA and seeing if anyone can convert it from meta to TOS.

No need to convert it, a fellow coder posted the Alma some years ago



script ALMA {
 input Data = close;
 input Window = 9; 
 input Sigma = 6;
 input Offset = 0.85;

 def m = (Offset * (Window - 1));
 def s = Window/Sigma;

 def SumVectorData = fold y = 0 to Window with WS do WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
 def SumVector = fold z = 0 to Window with CW do CW + Exp(-(sqr(z-m))/(2*sqr(s)));

 plot ALMA = SumVectorData / SumVector;
}
input price=close;
input Window = 9;
input Sigma = 6;
input Offset = 0.85;

plot ALMA = ALMA (price, Window, Sigma, Offset);

ALMA.setPaintingStrategy(PaintingStrategy.LINE);
ALMA.SetDefaultColor(Color.CYAN);
ALMA.HideTitle();
ALMA.HideBubble();



Edited 2 time(s). Last edit at 08/13/2018 06:43AM by rigel.
Re: MetaTrader Convesion
August 13, 2018 07:40AM
Rigel,

Thanks I have the ALMA but this was indicating an additional ALMA with a multi-time frame as well.

I can't post the image but below is the link to the image on forex indicators.

[www.forexmt4indicators.com]

So is it possible to have an additional ALMA to be able to choose a different time frame than the current chart with 1,2,5,10 minute etc?

I should of been more clear on my first post.

Thanks again.
Kevin



Edited 1 time(s). Last edit at 08/13/2018 07:41AM by chillc15.
Re: MetaTrader Convesion
August 13, 2018 02:23PM
Quote
chillic15
I should of been more clear on my first post.

Yes....

So... what you want is ONE alma that has the capability to use the time frame of the current chart OR other HIGHER (*) time frame, right?

If yes, please be specific: you use for example 5 min and want to be able to choose 15, 20,30,60,120

(*) TOS only allows to have equal or higher time frames that the current chart.
Re: MetaTrader Convesion
August 13, 2018 03:12PM
Rigel,

Using a one minute chart and plotting one ALMA and then plot another ALMA with the ability to select a higher time frame of 2.3.5.10.15 and have them both on the one minute chart.

I have seen it done with lower studies but wasn't sure if it has been done with upper studies as well.

Thanks
Re: MetaTrader Convesion
August 14, 2018 02:02PM
chillic15

Below a one min chart with an Alma 9 period in blue(1 min time frame) and another Alma 9 period in yellow (5 min time frame)

You need to deploy two times the Alma study selecting the appropriated settings and colors



# Alma MA with multiple time frames
# in the settings "current" represents the current time frame of the chart
# by Rigel, August 2018
#
script ALMA {
    input Data = close;
    input Window = 9; 
    input Sigma = 6;
    input Offset = 0.85;

    def m = (Offset * (Window - 1));
    def s = Window / Sigma;

    def SumVectorData = fold y = 0 to Window with WS do WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(Data, (Window - 1) - y);
    def SumVector = fold z = 0 to Window with CW do CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));

    plot ALMA = SumVectorData / SumVector;
}

input Window = 9;
input Sigma = 6;
input Offset = 0.85;
input TimeFrame= {default current,"2 min","3 min","5 min","10 min","15 min"};
def agg;
switch (timeFrame) 
{
case "2 min":
  agg=aggregationPeriod.TWO_MIN;
case "3 min":
  agg=aggregationPeriod.THREE_MIN;
case "5 min":
  agg=aggregationPeriod.FIVE_MIN;
case "10 min":
  agg=aggregationPeriod.TEN_MIN;
case "15 min":
  agg=aggregationPeriod.FIFTEEN_MIN;
case current:
   agg=getAggregationPeriod();
}

plot ALMA = ALMA (close(period=agg), Window, Sigma, Offset);

ALMA.SetPaintingStrategy(PaintingStrategy.LINE);
#ALMA.SetDefaultColor(Color.CYAN);
ALMA.HideTitle();
ALMA.HideBubble();



Edited 1 time(s). Last edit at 08/14/2018 02:07PM by rigel.
Re: MetaTrader Convesion
August 14, 2018 09:28PM
Rigel,

Thank you!. You have been very kind in taking your time to assist with some of my questions and I do appreciate it.

Kevin
Re: Fun with ThinkScript
August 15, 2018 05:03AM
Rigel, I am having a hard time creating a scan from the code below you created to let me know what stocks have a Green signal and another scan for stocks with a Red signal




#
# OptionMaster_ZIGZAG_Signal
#
input price = close;
input priceH = high; # swing high
input priceL = low; # swing low
input ATRreversalfactor = 3.2;
def ATR = reference ATR(length = 5);
def reversalAmount = ATRreversalfactor * ATR;
input showlines = yes;
input displace = 1;
input showBubbleschange = yes;


def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {
minMaxPrice = price;
state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
state = state.downtrend;
minMaxPrice = priceL;
} else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
state = state.uptrend;
minMaxPrice = priceH;
} else {
state = state.undefined;
minMaxPrice = GetValue(minMaxPrice, 1);
}
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
state = state.downtrend;
minMaxPrice = priceL;
} else {
state = state.uptrend;
minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
}
} else {
if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
state = state.uptrend;
minMaxPrice = priceH;
} else {
state = state.downtrend;
minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
}
}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth = barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1
while lastPeriodBarAcc > 0
do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
then -lastPeriodBarAcc
else lastPeriodBarAcc + 1;
} else {
tmpLastPeriodBar = 0;
}
} else {
tmpLastPeriodBar = Double.NaN;
}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
currentPriceLevel =
fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice
do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI));
currentPoints =
fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN
while IsNaN(maxPointOnPeriodAcc)
do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
then maxPointOnPeriodI
else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
currentPriceLevel =
fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice
do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI));
currentPoints =
fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN
while IsNaN(minPointOnPeriodAcc)
do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
then minPointOnPeriodI
else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) {
currentPriceLevel = GetValue(currentPriceLevel, 1);
currentPoints = GetValue(currentPoints, 1) + 1;
} else {
currentPoints = 1;
currentPriceLevel = GetValue(price, currentPoints);
}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN;

rec zzSave = if !IsNaN("ZZ$" ) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1);

def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1);

def isUp = chg >= 0;

#Higher/Lower/Equal High, Higher/Lower/Equal Low
def xxhigh = if zzSave == priceH then Round(high, 2) else Round(xxhigh[1], 2);
def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2);
def xxlow = if zzSave == priceL then Round(low, 2) else Round(xxlow[1], 2);
def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2);


rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));

"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.UPTICK);
"ZZ$".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ$".DefineColor("Undefined", Color.WHITE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined" ) else if isUp then "ZZ$".Color("Up Trend" ) else "ZZ$".Color("Down Trend" ));

DefineGlobalColor("Unconfirmed", Color.WHITE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

AddVerticalLine(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, "Buy", if barCount ==
barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Down" ) else
GlobalColor("Up" ),curve.FIRM);

## END CODE
Re: On Balance Volume
August 15, 2018 05:43AM
Rigel, I wanted to know if you can add a 14 Exponential moving average to the lower study On Balance Volume indicator you created. Also can you change the coloring of the indicator? I need the OBV color to turn a different color any time when the OBV Is above the 14 Exponential Moving Average and both is above the 0 line. Also, If the OBV is above the 14 ema while both is under the 0 line then I want the OBV to be purple only if both lines is under the 0 line and the OBV is above the 14 ema. If the OBV is below the 14 while both is under the 0 line then I need the OBV to be yellow. I also need a Green BUY or Red SELL bubble at the top of the chart at all times. When the OBV is above the 14 and above the 0 line I need the bubble to be green and says BUY, if the OBV is below the 14 ema above the 0 line I need the Bubble to say SELL. If the OBV is above the 14 ema and the OBV turns purple while under the 0 line I want the the bubble to say UPTREND and for the bubble to also turn purple. If the OBV is below the 14 ema while both is under the 0 line I want the OBV to turn yellow with the bubble also turning yellow saying DOWNTREND at the top of the chart. And of course I need a scan to let me know when the OBV is above the 14 ema regardless if it is above or below the 0 line and a scan to let me know when stocks are below the 14 ema regardless if it is above or below the 0 line.

Also, when stocks appear in MarketWatch I need a three sections next to stocks that says either BUY, SELL, DN, or UP with the corresponding colors that match the rest of the indicator. One for the daily charts and one for the 2min charts, and one for 5min charts, or just one section with the ability to change the timeframes in MarketWatch

This could become one of the greatest indicators ever. The original code you created is below, I just need it to be even more perfect.


# OBV Oscillator
# @author LazyBear
#[www.tradingview.com]
#
# Adapted to TOS by Rigel, 2018

declare lower;
input length=20;
def OBV = TotalSum(Sign(close - close[1]) * volume);

plot obv_osc = (OBV - expAverage(OBV,length));
plot zero=0;
obv_osc.assignvalueColor(if obv_osc>0 then color.green else color.red);
zero.SetDefaultColor(color.cyan);



Edited 4 time(s). Last edit at 08/15/2018 06:33AM by MoneyBags.
Re: Fun with ThinkScript
August 16, 2018 11:48AM
Quote
MoneyBags
I am having a hard time creating a scan from the code below you created to let me know what stocks have a Green signal and another scan for stocks with a Red signal

Hmm.. the zigzag is a re-paint indicator, so you will need to be scanning continuously and the signal can be changing... no point.
Re: Fun with ThinkScript
August 16, 2018 04:04PM
Yeah, that's why I asked for only the green or red paint scan signals since it becomes official, the scan would require a re-written code to avoid picking up inaccurate white paints.


I do see what you mean, I am wondering if there is a way to scan for accurate paints as long as the green or red paint remains while price moves to the next 3 or 4 bars? Maybe that is the trick to get the right scans. Speculating.



Edited 1 time(s). Last edit at 08/17/2018 10:01AM by MoneyBags.
Re: On Balance Volume
August 20, 2018 04:14AM
Quote
MoneyBags
I wanted to know if you can add a 14 Exponential moving average to the lower study On Balance Volume indicator you created.

Add these lines at the end. That should keep you going for the rest of the code
plot ema14=expAverage(obv_osc,14);
ema14.SetDefaultColor(color.white);





Edited 1 time(s). Last edit at 08/20/2018 04:14AM by rigel.
Re: Fun with ThinkScript
August 20, 2018 09:04PM
Hoping someone can lend a hand...

Been trying to write a code just to plot the slope of the 20 ema. I thought it was as simple as (y2-y1)/(1) = slope

With Y being the closing price of the 20 ema.

I'm not sure though, any help would be appreciated.
Dan
Re: Fun with ThinkScript
August 21, 2018 10:07AM
I don't know what it is in Thinkscript, but the equation should be (y2-y1)/(x2-x1). That will give you the slope of a straight line between two points drawn on a two dimensional plane. The units will be price change per time unit (candle), which will depend on the time unit you are using for your chart. The number of candles between x2 and x1 will change depending on the time unit used but y2 and y1 will stay the same. The smaller the time unit on the chart, the larger the number of candles between x2 and x1 resulting in a smaller slope value because the denominator will be larger.
Re: Assign Price Color when conditions have been met.
August 26, 2018 08:55AM
I know this may be basic and probably at some point has been posted before but can't seem to figure it out. Needing help with assigning price color when certain conditions have been met.

Meaning:

Close is above MA1 and MA1 is above MA2 and MA2 is above MA3 color.GREEN and then obviously the reverse and then yellow when conditions have not been met.

Basic
#AssignPriceColor(if close and close > MA1 then Color.GREEN else if close and close < MA1 #then Color.RED else Color.YELLOW);

Any help is appreciated.

Thanks
Kevin
Re: Assign Price Color when conditions have been met.
August 27, 2018 07:55AM
Quote
chillc15
Close is above MA1 and MA1 is above MA2 and MA2 is above MA3 color.GREEN and then obviously the reverse and then yellow when conditions have not been met.

You could do that all in one go, but it helps, when learning, to do it in several steps. In this case define your conditions and at the end use them in the AssignPriceColor

For example your condition for green is:
def uptrend=close>MA1 and MA1>MA2 and MA2>MA3 ;
[your other conditions]
AssignPriceColor(if uptrend then Color.GREEN else if downtrend...... ) ;

That should keep you in the right direction...
Re: Assign Price Color when conditions have been met.
August 27, 2018 09:27PM
X



Edited 2 time(s). Last edit at 08/27/2018 09:30PM by Ralph53.
Re: Assign Price Color when conditions have been met.
August 30, 2018 07:29AM
rigel,

It does and thank you very much.

Kevin
Re: Fun with ThinkScript
August 30, 2018 01:09PM
Hello, I don't remember where this code is fromm, but it plots some of supply and demand. I would really like to make it plot extended horizontal lines
and sadly can only plot for one bar only currently. Any help/suggestion is appreciate it. Thank you

Def swinghigh = if high >= high[1] and high >= high[2] and high >= high[3] and high >= high[4] and high >= high[5] and high >= high[6] and high >= high[7] and high >= high[8] and high >= high[9] and high >= high[10] and high >= high[-1] and high >= high[-2] and high >= high[-3] and high >= high[-4] and high >= high[-5] and high >= high[-6] and high >= high[-7] and high >= high[-8] and high >= high[-9] and high >= high[-10] then 1 else 0;

Plot sh = if swinghigh then high else double.nan;
sh.setstyle(curve.points);

Def swinghighlows = if low >= low[1] and low >= low[2] and low >= low[3] and low >= low[4] and low >= low[5] and low >= low[6] and low >= low[7] and low >= low[8] and low >= low[9] and low >= low[10] and low >= low[-1] and low >= low[-2] and low >= low[-3] and low >= low[-4] and low >= low[-5] and low >= low[-6] and low >= low[-7] and low >= low[-8] and low >= low[-9] and low >= low[-10] then 1 else 0;

Plot shl = if swinghighlows then low else double.nan;
shl.setstyle(curve.points);



Def swinglow = if low <= low[1] and low <= low[2] and low <= low[3] and low <= low[4] and low <= low[5] and low <= low[6] and low <= low[7] and low <= low[8] and low <= low[9] and low <= low[10] and low <= low[-1] and low <= low[-2] and low <= low[-3] and low <= low[-4] and low <= low[-5] and low <= low[-6] and low <= low[-7] and low <= low[-8] and low <= low[-9] and low <= low[-10] then 1 else 0;

Plot sl = if swinglow then low else double.nan;
sl.setstyle(curve.points);

Def swinglowhighs = if high <= high[1] and high <= high[2] and high <= high[3] and high <= high[4] and high <= high[5] and high <= high[6] and high <= high[7] and high <= high[8] and high <= high[9] and high <= high[10] and high <= high[-1] and high <= high[-2] and high <= high[-3] and high <= high[-4] and high <= high[-5] and high <= high[-6] and high <= high[-7] and high <= high[-8] and high <= high[-9] and high <= high[-10] then 1 else 0;

Plot slh = if swinglowhighs then high else double.nan;
slh.setstyle(curve.points);
Re: Fun with ThinkScript
August 31, 2018 05:31AM
Alexquate

That indicator "look into the future" for 10 bars.. (it is a re-paint indicator), what would be the usefulness of that?
Re: Fun with ThinkScript
August 31, 2018 09:00AM
Good morning, When you say, "Re-paint indicator" you mean is delayed?
If so is there a way to get rid of the delay? but if not its meant to represent areas of supply/demand
if I go to, settings on the study, and changed value to -->numerical and change "drawn as" to lines, It'll plot a line on a bar instead of painting it.Which is the purpose of it.That's why I was wondering if there was a way to make them plot them for more than a bar. Again I'm not well educated on writing code sad smiley



Edited 2 time(s). Last edit at 08/31/2018 01:01PM by alexguate.
Re: Fun with ThinkScript
September 01, 2018 04:45AM
Alexquate

It means that the indicator is modifying the last signal constantly (the most recent).
That is, you will see the point and in the next bar could change.
In your case the last bar will be looking the past 10 bars to see if the current high is greater than the previous 10, that is fine, BUT will also look for the next 10 bars, that of course hasn't happened yet. In other words the only reliable points that you have in your chart are those that have before and after them 10 bars. Any point that has after it, less than 10 bars and it is signaled with a point, could change(move-disappear) with the next bar. That is, it is re-paint.



Edited 1 time(s). Last edit at 09/01/2018 04:45AM by rigel.
Re: Fun with ThinkScript
September 03, 2018 10:33AM
I Rigel,

I am searching for similar code to what you have written.
Could you please post again the rest of the code? I would appreciate it alot.
.

rigel Wrote:
-------------------------------------------------------
> wichitawx
>
> I don't have Robert's code but I modified some
> basic code found in Internet (no author to give
> credit for) which produces what you are looking
> for
>
> [i.imgur.com]
>
>
>
>
> # Plot the high and low of X days ago
> # Don't know the author of original code to give
> proper credit
> # Basic code modified to produce similar results
> to Robert Payne's solution
> # by Rigel April 2018
> #
>
> declare upper;
> input LastBubble = No;
> Input DaysAgo = 1;#hint DaysAgo: Excludes today
> def AdjDaysAgo = DaysAgo + 1;#Adjusted to match a
> true LastDate which includes today
> def day = GetDay();
> def lastDay = GetLastDay();
> def year = GetYear();
> def lastYear = GetLastYear();
> def yyyymmdd = GetYYYYMMDD();
> def agg=aggregationPeriod.DAY;
>
> As the author of the request seems not interested
> the rest of the code has been deleted
>
>
Re: Fun with ThinkScript
September 04, 2018 12:53AM
Thank you Rigel, for taking the time to explain and for all your help!
Re: Fun with ThinkScript
September 04, 2018 02:25PM
Ojano

Try this:
# Plot the high and low of X days ago
# Don't know the author of original code to give proper credit
# Basic code modified to produce similar results to Robert Payne's solution
# by Rigel April 2018
#

declare upper;
input LastBubble = No; 
Input DaysAgo = 1;#hint DaysAgo: Excludes today
def AdjDaysAgo = DaysAgo + 1;#Adjusted to match a true LastDate which includes today 
def day = GetDay();
def lastDay = GetLastDay();
def year = GetYear();
def lastYear = GetLastYear();
def yyyymmdd = GetYYYYMMDD();
def agg=aggregationPeriod.DAY;

def D_lastDate = HighestAll( if day == lastDay and year == lastYear then yyyymmdd else Double.NaN );
def D_currentDate = if yyyymmdd < D_lastDate then yyyymmdd else D_lastDate;
def B_previousDay = if CountTradingDays( D_currentDate, D_lastDate ) == AdjDaysAgo then yes else no;

def D_BeginRange=  if CountTradingDays( D_currentDate, D_lastDate ) == AdjDaysAgo then yyyymmdd else double.nan;
def D_cond= highestall( D_BeginRange);


def PH = HighestAll( if B_previousDay then high( period = agg ) else Double.NaN );
def PL = HighestAll( if B_previousDay then low( period = agg ) else Double.NaN );

plot previoushigh= if yyyymmdd>= D_cond then PH else double.NaN;
plot previouslow= if yyyymmdd>= D_cond then PL else double.NaN;

addlabel(yes,"last date "+D_lastDate,color.white);

#================ Look & Feel =============
PreviousHigh.SetDefaultColor( Color.green );
PreviousHigh.SetLineWeight( 2 );
PreviousHigh.HideBubble();
PreviousLow.SetDefaultColor( Color.red); 
PreviousLow.SetLineWeight( 2 ); 
PreviousLow.HideBubble();

#=========== ID Bubbles ===================
Def barnum = barnumber();
def FirstBar = if barNum == 1 then 1 else 0;

#========= Last ID bubbles ==========
Input Offset = -10;
def LastBar = !IsNaN(open) and IsNaN(open [-1] ) ;
Def BubbleLocation = LastBar[Offset];
addchartbubble(BubbleLocation && LastBubble, PreviousHigh, ("High of " + DaysAgo + " day(s) ago" ), color.white);
addchartbubble(BubbleLocation && LastBubble,PreviousLow, ("Low of " + DaysAgo + " day(s) ago" ), color.white);



Edited 1 time(s). Last edit at 09/05/2018 04:36AM by rigel.
Sorry, only registered users may post in this forum.

Click here to login