Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: Reference code?
May 23, 2018 11:08PM
rigel,

That was what I needed.
Thanks for help and for the fast reply and coding.

styx
Re: AddCloud on Tick Chart. multiple time frame analysis on tick chart
May 24, 2018 01:22PM
Quote
Paras
Where can I get that kind of script and how much that script will cost?

Please contact Robert in his site . Every coder has different rates some do it for 50 USD per hour while others charge depending of the job.

If that doesn't work, let me know and I could give a try if I find some time.
Re: Fun with Thinkscript
May 24, 2018 05:17PM
Hi,

I'm interested in converting the following PineScript to Thinkscript:
// Bill Williams Fractal Template
// Coded By: Matthew Spencer
// If you like this script or use it's code in one of yours, please donate.
// PayPal: ma.spencer@gmx.com Bitcoin: 1foxypuyuoNp5n1LNCCCCmjZ4RAXntQ8X

// Define our title and that this script will overlay the candles.
study("Williams Fractals",shorttitle="Fractals", overlay=true)

// Define "n" as the number of periods and keep a minimum value of 2 for error handling.
n = input(title="Periods", defval=2, minval=2, type=integer)

// Williams Fractals are a 5 point lagging indicator that will draw 2 candles behind.
// The purpose of the indicator is to plot points of trend reversals.
// Often these are paired with trailing stop indicators such as Parabolic SAR, Volatility Stop, and SuperTrend.

// Down pointing fractals occur over candles when:
//   High(n-2) < High(n)
//   High(n-1) < High(n)
//   High(n + 1) < High(n)
//   High(n + 2) < High(n)
dnFractal = (high[n-2] < high[n]) and (high[n-1] < high[n]) and (high[n+1] < high[n]) and (high[n+2] < high[n])

// Up pointing fractals occur under candles when:
//   Low(n-2) > Low(n)
//   Low(n-1) > Low(n)
//   Low(n + 1) > Low(n)
//   Low(n + 2) > Low(n)
upFractal = (low[n-2] > low[n]) and (low[n-1] > low[n]) and (low[n+1] > low[n]) and (low[n+2] > low[n])

// Plot the fractals as shapes on the chart.
plotshape(dnFractal, style=shape.arrowdown, location=location.abovebar, offset=-2, color=olive, transp=0) // Down Arrow above candles
plotshape(upFractal, style=shape.arrowup, location=location.belowbar, offset=-2, color=maroon, transp=0)  // Up Arrow below candles


Anyone? Thanks in advance... smiling smiley


Source: https://www.tradingview.com/script/Uyv9vQc2-Williams-Fractals-Tutorial-Template/

Pinescript Introduction: https://blog.tradingview.com/en/tradingview-s-pine-script-introduction-203/

Pinescript Tutorial: https://www.tradingview.com/wiki/Pine_Script_Tutorial

Pinescript Language Reference: https://www.tradingview.com/study-script-reference/
Re: AddCloud on Tick Chart. multiple time frame analysis on tick chart
May 24, 2018 07:07PM
Hi Rigel,

Thank you for your information. I have already sent email with my issue to Robert.


Regards,

Paras
Re: Fun with Thinkscript
May 25, 2018 03:49AM
netarchitect, here you have it


# Bill Williams Fractal Template
# Coded By: Rigel May 2018

#Define "n" as the number of periods and keep a minimum value of 2 for error handling.
input n=2;

# Williams Fractals are a 5 point lagging indicator that will draw 2 candles behind.
# The purpose of the indicator is to plot points of trend reversals.
# Often these are paired with trailing stop indicators such as Parabolic SAR, Volatility Stop, and SuperTrend.

# Down pointing fractals occur over candles when:
#   High(n-2) < High(n)
#   High(n-1) < High(n)
#   High(n + 1) < High(n)
#   High(n + 2) < High(n)
#dnFractal = (high[n-2] < high[n]) and (high[n-1] < high[n]) and (high[n+1] < high[n]) and (high[n+2] < high[n])

def isupfractal = if low < low[1] and low < low[2] and low < low[-1] and low < low[-2] then low else double.nan;
# Up pointing fractals occur under candles when:
#   Low(n-2) > Low(n)
#   Low(n-1) > Low(n)
#   Low(n + 1) > Low(n)
#   Low(n + 2) > Low(n)
#upFractal = (low[n-2] > low[n]) and (low[n-1] > low[n]) and (low[n+1] > low[n]) and (low[n+2] > low[n])
def isdownfractal = if high > high[1] and high > high[2] and high > high[-1] and high > high[-2] then high else double.nan;
# Plot the fractals as shapes on the chart.


plot upfractal = if( isupfractal, isupfractal+ (1 * tickSize()) , double.nan);
upfractal.SetPaintingStrategy(paintingStrategy.ARROW_UP);
plot downfractal = if( isdownfractal, isdownfractal - (1 * tickSize()), double.nan);
downfractal.SetPaintingStrategy(paintingStrategy.ARROW_DOWN);
Re: Fun with Thinkscript
May 25, 2018 08:03AM
Hi Rigel,

Thank you very much... I really appreciate it!

Best Regards,

netarchitech
Re: Fun with ThinkScript
May 26, 2018 10:28PM
Hi Robert,

I am new to TOS and I am very impressed by your technical aptitude when it comes to scripting on TOS.

I have two questions and I would appreciate very much your guidance...

Q1. Partially exit a position after a profit target is hit

I am trying to test some strategies on /ES and the rules are:

1. Go long 2 contracts when a certain condition is met.
2. Exit just ONE contract when a profit target is hit.

I tried to close just one contract (see the code snippet below) and TOS always closed the entire position i.e. 2 contracts. For the remaining one contract, I want to use a trailing stop loss of 0.25 tick to lock in the gain of the first profit target and let the profit run until stopped out.
Can you show me how to achieve the above in code?

######## Code Snippet #####################
# Go long 2 contracts when a certain condition is met

AddOrder(OrderType.BUY_TO_OPEN, LongEntrySetup, close, 2, tickColor = GetColor(1), arrowColor = GetColor(1), name="Long Entry" )

# Determine if profit target was hit

def targetHit = if high >= target1 then 1 else 0;

# Profit target exit

AddOrder(OrderType.SELL_TO_CLOSE, targetHit, open[-1], 1, tickColor = GetColor(6), arrowColor = GetColor(6), name="Profit Target Exit" )

Q2. How do you code a strategy to exit a position after 5 bars from the entry price?

For question 2, I just have no idea where to start and I would look to your help on this.

Thanks for your help in advance.

Dilan
Replacing Momentum UP and Momentum BOOLEAN ARROWS
May 27, 2018 12:08PM
Looking for help in changing the Momentum UP and Momentum DOWN BOOLEAN ARROWS with (BUY CALL LINES and BUY PUT LINES) on This Study

Thanks


input price = close;

input superfast_length = 5;

input fast_length = 11;

input slow_length = 21;

input displace = 0;



def mov_avg5 = ExpAverage(price[-displace], superfast_length);

def mov_avg11 = ExpAverage(price[-displace], fast_length);

def mov_avg21 = ExpAverage(price[-displace], slow_length);



#moving averages

Plot Superfast = mov_avg5;

plot Fast = mov_avg11;

plot Slow = mov_avg21;



def buy = mov_avg5 > mov_avg11 and mov_avg11 > mov_avg21 and low > mov_avg5;

def stopbuy = mov_avg5 <= mov_avg11;

def buynow = !buy[1] and buy;

def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1]==1 and stopbuy then 0 else buysignal[1], 0);



plot Buy_Signal = buysignal[1] == 0 and buysignal==1;

Buy_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Buy_signal.setdefaultColor(color.dark_GREEN);

Buy_signal.hidetitle();

Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);



plot Momentum_Down = buysignal[1] ==1 and buysignal==0;

Momentum_down.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Momentum_Down.setdefaultColor(color.plum);

Momentum_down.hidetitle();

Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);



def sell = mov_avg5 < mov_avg11 and mov_avg11 < mov_avg21 and high < mov_avg5;

def stopsell = mov_avg5 >= mov_avg11;

def sellnow = !sell[1] and sell;

def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1]==1 and stopsell then 0 else sellsignal[1], 0);



Plot Sell_Signal = sellsignal[1] ==0 and sellsignal;

Sell_signal.setpaintingStrategy(PaintingStrategy.Draw vertical line );

sell_signal.setDefaultColor(color.red);

Sell_signal.hidetitle();

Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);



Plot Momentum_Up = sellsignal[1]==1 and sellSignal==0;

Momentum_up.setpaintingStrategy(PaintingStrategy.Draw vertical line );

Momentum_up.setDefaultColor(color.plum);

Momentum_up.hidetitle();

Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);



plot Colorbars = if buysignal ==1 then 1 else if sellsignal ==1 then 2 else if buysignal ==0 or sellsignal==0 then 3 else 0;

colorbars.hide();

Colorbars.definecolor("Buy_Signal_Bars", color.dark_green);

Colorbars.definecolor("Sell_Signal_Bars", color.red);

Colorbars.definecolor("Neutral", color.plum);



AssignPriceColor(if Colorbars ==1 then colorbars.color("buy_signal_bars"winking smiley else if colorbars ==2 then colorbars.color("Sell_Signal_bars"winking smiley else colorbars.color("neutral"winking smiley);

#end
Re: Fun with ThinkScript
May 30, 2018 03:05AM
Hi Rigel,

I am wondering if you could help me with my questions posted earlier. The questions are posted below for your reference and I would appreciate your guidance on this.

Q1. Partially exit a position after a profit target is hit

I am trying to test some strategies on /ES and the rules are:

1. Go long 2 contracts when a certain condition is met.
2. Exit just ONE contract when a profit target is hit.

I tried to close just one contract (see the code snippet below) and TOS always closed the entire position i.e. 2 contracts. For the remaining one contract, I want to use a trailing stop loss of 0.25 tick to lock in the gain of the first profit target and let the profit run until stopped out.
Can you show me how to achieve the above in code?

######## Code Snippet #####################
# Go long 2 contracts when a certain condition is met

AddOrder(OrderType.BUY_TO_OPEN, LongEntrySetup, close, 2, tickColor = GetColor(1), arrowColor = GetColor(1), name="Long Entry" )

# Determine if profit target was hit

def targetHit = if high >= target1 then 1 else 0;

# Profit target exit

AddOrder(OrderType.SELL_TO_CLOSE, targetHit, open[-1], 1, tickColor = GetColor(6), arrowColor = GetColor(6), name="Profit Target Exit" )

Q2. How do you code a strategy to exit a position after 5 bars from the entry price?

For question 2, I just have no idea where to start and I would look to your help on this.

Thanks for your help in advance.

Dilan
Re: Fun with ThinkScript
June 01, 2018 04:14AM
Dilan

Your code is according to syntax
AddOrder(OrderType.SELL_TO_CLOSE, targetHit, open[-1], 1, tickColor = GetColor(6), arrowColor = GetColor(6), name="Profit Target Exit" )

So it seems that "sell to close" ignores the contract size and simply closes any open position. As you are not posting the whole code that is my best guess.

For your second question it would be necessary to have a counter of elapsed bars (not difficult to do) but would require to have the addOrder statement in a conditional situation. Again that is my best guess as you are not posting the whole code.
Re: Fun with ThinkScript
June 01, 2018 04:21AM
Paras

Did you find the solution ? if not you can PM me.

Rigel
Re: Fun with ThinkScript
June 01, 2018 02:11PM
Hi,

Is it possible to create a script for an email SMS alert instead of the "Message Center and Play Sound" or the Setup / Application /Settings /Notifications option.


Thank you



Edited 1 time(s). Last edit at 06/01/2018 02:55PM by Nassavah.
Re: Fun with ThinkScript
June 02, 2018 04:09AM
Nassavah

I assume you want an script alert based on a study that you have created and not a fixed value you have to setup again and again... if that is right, it is actually possible, you need to work in the market watch - alerts - study alerts section

Google study alerts

Cheers
Re: Fun with ThinkScript
June 04, 2018 08:41AM
Good Day Rigel,
Thank you for the quick response.
I am using the follow script for a Watch list indicator, As a way to shorten my search and a way to alert when I am not at my desk.
I am looking to set a SMS Alert manually when ever I get a price change /when the MACD crosses the zeroline.
Thank you for the help!!!

Nassavah



Edited 1 time(s). Last edit at 08/31/2018 07:49AM by Nassavah.
Need help on a RS type ThinkScript
June 05, 2018 10:07PM
I found the below RS type code on the internet and it seem to basicly work fine. As a non-coder, I would like someone to add a few things
to it and maybe explain a few things so a non-coder (me) can understand them.
The code is below:
And also below is what I would like done to the code and added to the code if possible.

1.
I would like to able to smooth the two input periods with a mov. avg. So as the code is wrote. I want to be able to smooth the SPX
63 period and the stocks 63 period with a mov. avg. Just wanting to make the indicator line smoother and not as jagged as they look now?

2.
Have it where the stock line above the SPX line is blue and below orange. And maybe also having a cloud color above and below the SPX line.

3.
Also for my info: What in the code is making the SPX line a straight line across the indicator? In other words, how is that done.

4.
I just thought of this as I was writing and looking at the indicator, so I thought I would ask about it.
As you can see, if you chart the indicator in ThinkorSwim as you go back in time the indicator moves up and down alot.
So what I was wondering is if the SPX line be like a centerline that many other indicators have and since the big spikes up and down in the
stock line doesn't matter much, if maybe the stock part can be like a bound indicator and just go flat above and below a certain point.
So the whole indicator can be like other bound indicators with the SPX line like a center-zero line and the stock line to be bound above and below a certain point? Just an idea. I don't know if it can be done or not.
The main things are 1 - 2 - 3 above.

Also as far as number 4. To kind of see what I am talking about as far as a bound indicator and the SPX like a center line etc.
You can look at some of the Chaikin Analytics charts and look at the Relative Strength indicator. It is a bound indicator that is from
0.00 to 1.00 with .50 as the center.

Also if need anyone can email me about this.


declare lower;

input Comparison_Security = "SPX";
input period1 = 63;
input period2 = 63;
input price = FundamentalType.CLOSE;

def comparisonPrice = fundamental( price, Comparison_Security );
def comparisonRtOfChg = comparisonPrice / comparisonPrice[ period1 ];

def currentStkPrice = fundamental( price );
def currentStkRtOfChg = currentStkPrice / currentStkPrice[ period2 ];

plot RS = if IsNaN( comparisonRtOfChg ) then Double.NaN else ( currentStkRtOfChg / comparisonRtOfChg ) * 100;
RS.setDefaultColor(GetColor(6));
RS.HideBubble();

plot BaseLine = 100;
BaseLine.SetDefaultColor( Color.BLACK );
BaseLine.HideBubble();
BaseLine.HideTitle();


Thanks,
% Change from Open (0930)
June 06, 2018 12:56PM
I currently have a Thinkscript for % change since close of previous day on a chart label. Is there a way to modify it so it shows % change since the open at 0930 ?? I can't figure it out. Here is my Thinkscript for % change since previous close:

input length = 1;
def price = close(period = AggregationPeriod.DAY);

assert(length > 0, "'length' must be positive: " + length);
def PercentChg = 100 * (price / price[length]-1);

AddLabel(yes, Concat("%change = ", Round(percentchg, 2)), if percentchg <0 then Color.RED else if percentchg >0 then color.GREEN else color.GRAY);

Thanks !!
Re: Fun with ThinkScript
June 06, 2018 01:15PM
Hey Robert, can you create a study for me that just shows the Divergence of the Stochastics10,3,3 and Price with trendlines from the highs and lows on price relative to the highs and lows of the Stochastics within TOS pleaseee...im a noob graduating college and just getting into trading....
Re: Fun with ThinkScript
June 06, 2018 01:17PM
Hi all,
Before I get to my question I must say that I've been a long time voyeur of the forum and really enjoyed everyone's contributions. Thank you to all, truly. On to the q:
I've been trying to apply an ATR or super-trend style trailing stop using a hull moving average as the reference point instead of the low or high and only when other conditions are met. I have been able to get most everything to plot, but my trail does not 'hold position' as the ATR trailing stop does and instead experiences some excursions. Any help that the forum can provide is most appreciated.

declare upper;

input DisplayAverageType = AverageType.HULL;
input DisplayMA = 80;
input timeframe2 = AggregationPeriod.FIFTEEN_MIN;
input normalmalong = 50;
input normalmamed = 20;
input normalmashort = 9;
input averagetypenormalma = AverageType.EXPONENTIAL;
input drawtype = PaintingStrategy.LINE_VS_POINTS;
input drawwidth = 1;

def normallongavg2 = MovingAverage(averagetypenormalma, close(period = timeframe2), normalmalong);
def normalmedavg2 = MovingAverage(averagetypenormalma, close(period = timeframe2), normalmamed);
def normalshortavg2 = MovingAverage(averagetypenormalma, close(period = timeframe2), normalmashort);
def normaluptrend2 = normalshortavg2 > normalmedavg2 and normalmedavg2 > normallongavg2;
def normaldowntrend2 = normallongavg2 > normalmedavg2 and normalmedavg2 > normalshortavg2;
def HMA = MovingAverage(DisplayAverageType, close, DisplayMA);

plot ave = HMA;
ave.AssignValueColor(if ave>ave[1] and normaluptrend2 then Color.CYAN
else if ave<ave[1] and normaldowntrend2 then Color.LIGHT_RED
else Color.GRAY);
ave.SetPaintingStrategy(drawtype);
ave.SetLineWeight(drawwidth);


#
# TrailStop:
# Modified from SuperTrend by Mobius
#
# V03.10.2015
# Added Bubbles to mark entry and exit prices. Doesn't give much time to follow into trade, but better than guessing.
# Alteed default settings for values that made more sense on Intraday Futures. Added Color and ColorBars.
#Hintconfused smileyupertrend Indicator: shows trend direction and gives buy or sell signals according to that. It is based on a combination of the average price rate in the current period along with a volatility indicator. The ATR indicator is most commonly used as volatility indicator. The values are calculated as follows:
# When the change of trend occurs, the indicator flips

input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;

def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def state;
state = if HMA>HMA[1] and normaluptrend2 is true then 1 else
if HMA<HMA[1] and normaldowntrend2 is true then -1 else
double.NaN;
def UP = HMA - (AtrMult * ATR);
def DN = HMA - (AtrMult * ATR);
def ST = if state==1 then Max(UP[1],Up) else
if state==-1 then Min(DN[1],Dn) else
double.NaN;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if state==-1 then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and state==1
then Color.RED
else if PaintBars and state==-1
then Color.GREEN
else Color.CURRENT);
AddChartBubble(close crosses below ST, low[1], low[1], color.Dark_Gray);
AddChartBubble(close crosses above ST, high[1], high[1], color.Dark_Gray, no);
# End Code
Re: % Change from Open (0930)
June 07, 2018 06:15AM
captain597

Try this
# % Price change vs Day's Opening
# by Rigel 2018

def agg=aggregationPeriod.DAY;
def price = close;
def opening= Open(period=agg);
def PercentChg = 100 * (price / opening-1);

AddLabel(yes, Concat("%change = ", Round(percentchg, 2)), if percentchg <0 then Color.RED else if percentchg >0 then color.GREEN else color.white);





Edited 1 time(s). Last edit at 06/07/2018 06:24AM by rigel.
Re: Need help on a RS type ThinkScript
June 07, 2018 06:41AM
Quote
styx
1
I would like to able to smooth the two input periods with a mov. avg. So as the code is wrote. I want to be able to smooth the SPX
63 period and the stocks 63 period with a mov. avg. Just wanting to make the indicator line smoother and not as jagged as they look now?

If you replace your Plot Rs with this line, it will smooth the RS with a 15 period simple average :
plot RS = if IsNaN( comparisonRtOfChg ) then Double.NaN else average(( currentStkRtOfChg / comparisonRtOfChg ) * 100,15);

2. I don't understand

Quote
styx
3.
Also for my info: What in the code is making the SPX line a straight line across the indicator? In other words, how is that done.

plot BaseLine = 100;

4. Sorry that does not make sense in your indicator as it is comparing RS of two securities.
Re: On Balance Volume
June 07, 2018 12:27PM
Learning about OBV and would like to enhance the OBV that TOS provides.

Came across this script in Tradingview in which Lazybear created an oscillator for the OBV. Looking to re-create that for TOS and add a MA which can be changed to sma, ema etc.

Here is the script which was created in pine script.
[www.tradingview.com]

//
// @author LazyBear
//
// Appreciate a note if you use this code anywhere.
//
study(title="On Balance Volume Oscillator [LazyBear]", shorttitle="OBVOSC_LB" )
src = close
length=input(20)
obv(src) => cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume)
os=obv(src)
obv_osc = (os - ema(os,length))
obc_color=obv_osc > 0 ? green : red
plot(obv_osc, color=obc_color, style=line,title="OBV-Points", linewidth=2)
plot(obv_osc, color=silver, transp=70, title="OBV", style=area)
hline(0)

Any help is appreciated.

Thanks
Kevin



Edited 1 time(s). Last edit at 06/07/2018 12:36PM by chillc15.
Re: On Balance Volume
June 07, 2018 02:42PM
Kevin, try this



# 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);
Re: Need help on a RS type ThinkScript
June 07, 2018 09:42PM
Rigel,

1. The smoothing avg. worked just fine.

2. As far as my number 2. (Have it where the stock line above the SPX line is blue and below orange. And maybe also having a cloud color above and below the SPX line.)
The way I understand the indicator is that the 100 horizontal Baseline is the SPX avg.? In the code the line is black and hard to see. For my
use I changed the color to white in the edit section so I can see it.
So what I was talking about is having the stock line blue above the 100 baseline and orange below the 100 baseline. And maybe also
using addcloud or something to color above and below the 100 baseline? So basicly showing when a stock is stroner or weaker than
the SPX by using colors when above or below the 100 baseline.

4. As far as my number 4.
I just happen to think about Chaikins RS and the way it looked. You can see a few charts of Chaikins at the URL below:
Also of course Chaikin has his own websites.
But you can see that his RS shows the SPY as a steady horizontal line at .50. (where the code I found has it as the 100 line)
And his is green above the SPY and red below the SPY using something like addcloud?

www.thestreet.com/jim-cramer/chaikins-technical-tools-craners-off-the-charts-14600037

Thanks for your help on this. You do a great service for the users of this forum.
Re: Need help on a RS type ThinkScript
June 08, 2018 01:46AM
Styx

Thanks for your kind words.

2 an4
I see what you mean. You can see how to change the color of the line in my previous post to Kevin. Use assignvalueColor, that would change the color of the indicator line. Then use addcloud between the line and BaseLine.
Experiment with it until you master it.
Re: Fun with ThinkScript
June 09, 2018 01:03PM
Hello all,

I wondered if anyone had a code similar to this. it's a reversal trade. "A" is a pull back in a trend. "B" is a newer high or low. "C" pulls back and violates "A" . I would like to setup a scan in TOS to help me locate possible setups.

Futuresnoob


Re: % Change from Open (0930)
June 09, 2018 03:23PM
Figured it out ... here is the thinkscript:

input period_Type = AggregationPeriod.DAY;

def begin = open(period = period_Type);
def end = close(period = period_Type);
def NetChg = end - begin;
def PctChg = (end / begin) - 1;

AddLabel(yes, "%Chg Open: " + AsDollars(NetChg) + " " + AsPercent(PctChg), if NetChg > 0 then Color.GREEN else if NetChg < 0 then color.RED else color.LIGHT_GRAY);
Re: Need help on a RS type ThinkScript
June 10, 2018 09:59PM
rigel,

I figured out how to use the assignvalueColor, to color the RS indicator line.
But I just can't figure out how to use the addcloud in the code to color from the indicator line to baseline, when line is
above and below the baseline.
Can you or someone else here show how to do that in my code?

Thanks,
Re: Need help on a RS type ThinkScript
June 11, 2018 06:10AM
Quote
styx
But I just can't figure out how to use the addcloud in the code to color from the indicator line to baseline, when line is
above and below the baseline.

Styx the help in your TOS is your best friend:

AddCloud
AddCloud ( IDataHolder data1, IDataHolder data2, CustomColor color1, CustomColor color2);
Default values:
color1: Color.YELLOW color2: Color.RED
Plots a translucent cloud bounded above and below by values data1 and data2. Areas where data1 is greater than data2 are assigned color1, others are filled with color2. By default, the cloud border is invisble: to make it visible, set the showBorder parameter value to yes.

So:
IDataHolder data1= RS
IDataHolder data2= BaseLine

Then you only need to add at the end:

AddCloud (RS,BaseLine);



Edited 1 time(s). Last edit at 06/11/2018 06:11AM by rigel.
Re: Need help on a RS type ThinkScript
June 11, 2018 09:18PM
rigel,

Thanks, That helped a lot. I finally figured it out.
Wish I understood coding better.
Re: On Balance Volume
June 13, 2018 06:04AM
Rigel,

Thank you very much.

I really appreciate it!

Kevin
Sorry, only registered users may post in this forum.

Click here to login