Creating a custom index

crscrs85

New member
I want to create a Moving Average for the average closing price of 10 specific stocks. Is it possible to do this? And if so, can it be made so you can switch the stocks used in and out with other ones?
 
Solution
I want to create a Moving Average for the average closing price of 10 specific stocks. Is it possible to do this? And if so, can it be made so you can switch the stocks used in and out with other ones?

take a look at this
https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

can assign a variable to a stock symbol.
input s1 = "SPY";

then use that variable as an input parameter to close() , to read price from that stock.
p1 = close(s1);

repeat this 10x, then add them up and divide by 10.
def p_avg = ( p1+p2+p3+... +p10 )/10;
plot z = p_avg;
.

halcyonguy

Well-known member
VIP
Lifetime
I want to create a Moving Average for the average closing price of 10 specific stocks. Is it possible to do this? And if so, can it be made so you can switch the stocks used in and out with other ones?

take a look at this
https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

can assign a variable to a stock symbol.
input s1 = "SPY";

then use that variable as an input parameter to close() , to read price from that stock.
p1 = close(s1);

repeat this 10x, then add them up and divide by 10.
def p_avg = ( p1+p2+p3+... +p10 )/10;
plot z = p_avg;
.
 
Solution

crscrs85

New member
take a look at this
https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

can assign a variable to a stock symbol.
input s1 = "SPY";

then use that variable as an input parameter to close() , to read price from that stock.
p1 = close(s1);

repeat this 10x, then add them up and divide by 10.
def p_avg = ( p1+p2+p3+... +p10 )/10;
plot z = p_avg;
.
I tried a few different things, lines 27- 44 ended up working for a MA but after experimenting with different types of MA's and lengths within the code and using the gear icon it gave me the same line that had a starting point. Can you see what i did wrong? And Is there any way to have it plot as candles or a histogram?


#input symbol = "SPY";
#def price = close(symbol);
#input length = 20;
#input displace = 0;
#def hma = HullMovingAvg(price, length, displace);

#plot z = hma;
#z.SetDefaultColor(Color.YELLOW);
#z.SetLineWeight(1);
#z.HideBubble();
###spy HULLMovingAvg halcyonguy usethinkscript.com

#can assign a variable to a stock symbol.
#input s1 = "SPY";

#then use that variable as an input parameter to close() , #to read price from that stock.
#input p1 = close(s1);

#repeat this 10x, then add them up and divide by 10.
#def p_avg = ( p1+p2+p3+... +p10 )/10;
#plot z = p_avg;


###
###
###LIDAR INDEX
input length = 50;

#input AggregationPeriod = AggregationPeriod.DAY;
#input price = FundamentalType.CLOSE;
#input displace = 0;
#input showBreakoutSignals = no;
#plot AvgExp = ExpAverage(Fundamental(price, period = #AggregationPeriod)[-displace], length);

input s1 = "LAZR";
input s2 = "VLDR";
input s3 = "MVIS";
input s4 = "INDI";
input s5 = "AEVA";
input s6 = "QNGY";
input s7 = "CPTN";
input s8 = "INVZ";
input s9 = "LIDR";
plot AvgExp = (close(s1) + close(s2) + close(s3) + close(s4) + close(s5) + close(s6) + close(s7) + close(s8) + close(s9)) / (9);


#input p1 = close(s1)
#input p2 = close(s2)
#input p3 = close(s3)
#input p4 = close(s4)
#input p5 = close(s5)
#input p6 = close(s6)
#input p7 = close(s7)
#input p8 = close(s8)
#input p9 = close(s9)

#def p1 = close(s1)
#input p1 = close(s1)







#input symbol = "LAZR";
#Luminar Technologies, FLorida, mktcap 1 as 9-22-22
#input symbol = "VLDR";
#Velodyne Lidar, California, mktcap 7
#input symbol = "MVIS";
#Microvision, Washington, mktcap 4
#input symbol = "INDI";
#Indie Semiconductor, California, mktcap 2
#input symbol = "AEVA";
#Aeva Technologies, California, mktcap 5
#input symbol = "QNGY";
#Quanergy Systems, California, mktcap 9
#input symbol = "CPTN";
#Cepton, California, maktcap 6
#input symbol = "INVZ";
#Innoviz, Arizonia, mktcap 3
#input symbol = "LIDR";
#AEye, California, mktcap 8
#def price = (close(LAZR) + close(VLDR) + close(MVIS) + #close(INDI) + close(AEVA) + close(QNGY) + close(CPTN) #+ close(INVZ) + close(LIDR)) / (9);
#plot price;
 

halcyonguy

Well-known member
VIP
Lifetime
I tried a few different things, lines 27- 44 ended up working for a MA but after experimenting with different types of MA's and lengths within the code and using the gear icon it gave me the same line that had a starting point. Can you see what i did wrong? And Is there any way to have it plot as candles or a histogram?


i don't know what you mean by this,
..it gave me the same line that had a starting point.

the study isn't reading data from a chart. it is reading the same 9 stock prices on whatever chart you look at, so the line will always be the same, no matter what stock is loaded in the main chart.

i should have mentioned to make it a lower study
it is possible to make this an upper study and turn off the main price candles. but for me, the chart was still scaling as if the main plot was drawing. the code below will turn off main candles.
if you use this, it can only be used in 1 study that is loaded on a chart. and if it is in a lower study, it will still affect the candles in the main chart.

# turn off price bars
input HidePrice = YES;
HidePricePlot(HidePrice);

-------------------

i created 2 new versions, a line chart and a histogram.

each of them,
..read prices from 9 stocks. changeable in settings , from an input
..can pick to use chart time or use a second aggregation time.
....default time is chart time. default agg is day.

..the line version can also plot dashed lines for the 9 stocks

..the histogram has 3 colors of bars, depending on 2 price levels
default is,
input lvl1 = 3.5
input lvl2 = 4.0

------------------

line study

Ruby:
# multiple_symbols1_01_line

# https://usethinkscript.com/threads/creating-a-custom-index.12756/
# create a Moving Average for the average closing price of 10 specific stocks.

# ref
#https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

# LIDAR INDEX

declare lower;

def na = double.nan;
def bn = barnumber();

input price_data = { default chart_time , second_agg };
input Agg = AggregationPeriod.DAY;

input s1 = "LAZR";
input s2 = "VLDR";
input s3 = "MVIS";
input s4 = "INDI";
input s5 = "AEVA";
input s6 = "QNGY";
input s7 = "CPTN";
input s8 = "INVZ";
input s9 = "LIDR";

def p1;
def p2;
def p3;
def p4;
def p5;
def p6;
def p7;
def p8;
def p9;
switch (price_data) {
case chart_time:
 p1 = if isnan(close(s1)) then close(s1)[1] else close(s1);
 p2 = if isnan(close(s2)) then close(s1)[1] else close(s2);
 p3 = if isnan(close(s3)) then close(s1)[1] else close(s3);
 p4 = if isnan(close(s4)) then close(s1)[1] else close(s4);
 p5 = if isnan(close(s5)) then close(s1)[1] else close(s5);
 p6 = if isnan(close(s6)) then close(s1)[1] else close(s6);
 p7 = if isnan(close(s7)) then close(s1)[1] else close(s7);
 p8 = if isnan(close(s8)) then close(s1)[1] else close(s8);
 p9 = if isnan(close(s9)) then close(s1)[1] else close(s9);
case second_agg:
 p1 = if isnan(close(s1, agg)) then close(s1, agg)[1] else close(s1, agg);
 p2 = if isnan(close(s2, agg)) then close(s1, agg)[1] else close(s2, agg);
 p3 = if isnan(close(s3, agg)) then close(s1, agg)[1] else close(s3, agg);
 p4 = if isnan(close(s4, agg)) then close(s1, agg)[1] else close(s4, agg);
 p5 = if isnan(close(s5, agg)) then close(s1, agg)[1] else close(s5, agg);
 p6 = if isnan(close(s6, agg)) then close(s1, agg)[1] else close(s6, agg);
 p7 = if isnan(close(s7, agg)) then close(s1, agg)[1] else close(s7, agg);
 p8 = if isnan(close(s8, agg)) then close(s1, agg)[1] else close(s8, agg);
 p9 = if isnan(close(s9, agg)) then close(s1, agg)[1] else close(s9, agg);
}

input qty = 9;
def x = if !isnan(close(s1)) then 1 else 0;
plot Avg = if !x then na else (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9)/qty;
avg.setdefaultcolor(color.yellow);

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

input show_price_lines = no;

plot z1 = if (show_price_lines and x) then p1 else na;
z1.setdefaultcolor(getcolor(0));
z1.SetStyle(Curve.MEDIUM_DASH);
plot z2 = if (show_price_lines and x) then p2 else na;
z2.setdefaultcolor(getcolor(1));
z2.SetStyle(Curve.MEDIUM_DASH);
plot z3 = if (show_price_lines and x) then p3 else na;
z3.setdefaultcolor(getcolor(2));
z3.SetStyle(Curve.MEDIUM_DASH);
plot z4 = if (show_price_lines and x) then p4 else na;
z4.setdefaultcolor(getcolor(3));
z4.SetStyle(Curve.MEDIUM_DASH);
plot z5 = if (show_price_lines and x) then p5 else na;
z5.setdefaultcolor(getcolor(4));
z5.SetStyle(Curve.MEDIUM_DASH);
plot z6 = if (show_price_lines and x) then p5 else na;
z6.setdefaultcolor(getcolor(5));
z6.SetStyle(Curve.MEDIUM_DASH);
plot z7 = if (show_price_lines and x) then p7 else na;
z7.setdefaultcolor(getcolor(6));
z7.SetStyle(Curve.MEDIUM_DASH);
plot z8 = if (show_price_lines and x) then p8 else na;
z8.setdefaultcolor(getcolor(7));
z8.SetStyle(Curve.MEDIUM_DASH);
plot z9 = if (show_price_lines and x) then p9 else na;
z9.setdefaultcolor(getcolor(8));
z9.SetStyle(Curve.MEDIUM_DASH);
#


------------------

histogram study

Ruby:
# multiple_symbols1_02_histo

# https://usethinkscript.com/threads/creating-a-custom-index.12756/
# create a Moving Average for the average closing price of 10 specific stocks.

# ref
#https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

# LIDAR INDEX

declare lower;

def na = double.nan;
def bn = barnumber();

input price_data = { default chart_time , second_agg };
input Agg = AggregationPeriod.DAY;

input s1 = "LAZR";
input s2 = "VLDR";
input s3 = "MVIS";
input s4 = "INDI";
input s5 = "AEVA";
input s6 = "QNGY";
input s7 = "CPTN";
input s8 = "INVZ";
input s9 = "LIDR";

def p1;
def p2;
def p3;
def p4;
def p5;
def p6;
def p7;
def p8;
def p9;
switch (price_data) {
case chart_time:
 p1 = if isnan(close(s1)) then close(s1)[1] else close(s1);
 p2 = if isnan(close(s2)) then close(s1)[1] else close(s2);
 p3 = if isnan(close(s3)) then close(s1)[1] else close(s3);
 p4 = if isnan(close(s4)) then close(s1)[1] else close(s4);
 p5 = if isnan(close(s5)) then close(s1)[1] else close(s5);
 p6 = if isnan(close(s6)) then close(s1)[1] else close(s6);
 p7 = if isnan(close(s7)) then close(s1)[1] else close(s7);
 p8 = if isnan(close(s8)) then close(s1)[1] else close(s8);
 p9 = if isnan(close(s9)) then close(s1)[1] else close(s9);
case second_agg:
 p1 = if isnan(close(s1, agg)) then close(s1, agg)[1] else close(s1, agg);
 p2 = if isnan(close(s2, agg)) then close(s1, agg)[1] else close(s2, agg);
 p3 = if isnan(close(s3, agg)) then close(s1, agg)[1] else close(s3, agg);
 p4 = if isnan(close(s4, agg)) then close(s1, agg)[1] else close(s4, agg);
 p5 = if isnan(close(s5, agg)) then close(s1, agg)[1] else close(s5, agg);
 p6 = if isnan(close(s6, agg)) then close(s1, agg)[1] else close(s6, agg);
 p7 = if isnan(close(s7, agg)) then close(s1, agg)[1] else close(s7, agg);
 p8 = if isnan(close(s8, agg)) then close(s1, agg)[1] else close(s8, agg);
 p9 = if isnan(close(s9, agg)) then close(s1, agg)[1] else close(s9, agg);
}

input qty = 9;
input lvl1 = 3.5;
input lvl2 = 4.0;

def x = if !isnan(close(s1)) then 1 else 0;
plot Avg = if !x then na else (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9)/qty;
#avg.setdefaultcolor(color.yellow);
avg.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
avg.AssignValueColor(if avg >= lvl2 then color.green else if avg >= lvl1 then color.cyan else color.blue);
#
#

RLPQM6s.jpg
 

crscrs85

New member
This is what I mean by giving me a starting point and the same line (The link). It wouldnt let me post the picture for some reason but regardless of the length input of the MA the line remained the same (Seems to be fixed now). My end goal is to have the chart candlesticks turned off and have the study register as candlesticks instead of a line and to run it side by side with the stock im trading so essentially it would look like just another stock to anyone looking at it.

https://1drv.ms/u/s!Ai-lRKVY6qfrhkmEtbjImSqiwid-?e=Jq4BPV

In its current version (the Line study you posted) why is the line fixed? It doesnt adjust on the chart like a typical MA. If its changed from a line to candlesticks will it adjust?
 

crscrs85

New member
i don't know what you mean by this,
..it gave me the same line that had a starting point.

the study isn't reading data from a chart. it is reading the same 9 stock prices on whatever chart you look at, so the line will always be the same, no matter what stock is loaded in the main chart.

i should have mentioned to make it a lower study
it is possible to make this an upper study and turn off the main price candles. but for me, the chart was still scaling as if the main plot was drawing. the code below will turn off main candles.
if you use this, it can only be used in 1 study that is loaded on a chart. and if it is in a lower study, it will still affect the candles in the main chart.

# turn off price bars
input HidePrice = YES;
HidePricePlot(HidePrice);

-------------------

i created 2 new versions, a line chart and a histogram.

each of them,
..read prices from 9 stocks. changeable in settings , from an input
..can pick to use chart time or use a second aggregation time.
....default time is chart time. default agg is day.

..the line version can also plot dashed lines for the 9 stocks

..the histogram has 3 colors of bars, depending on 2 price levels
default is,
input lvl1 = 3.5
input lvl2 = 4.0

------------------

line study

Ruby:
# multiple_symbols1_01_line

# https://usethinkscript.com/threads/creating-a-custom-index.12756/
# create a Moving Average for the average closing price of 10 specific stocks.

# ref
#https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

# LIDAR INDEX

declare lower;

def na = double.nan;
def bn = barnumber();

input price_data = { default chart_time , second_agg };
input Agg = AggregationPeriod.DAY;

input s1 = "LAZR";
input s2 = "VLDR";
input s3 = "MVIS";
input s4 = "INDI";
input s5 = "AEVA";
input s6 = "QNGY";
input s7 = "CPTN";
input s8 = "INVZ";
input s9 = "LIDR";

def p1;
def p2;
def p3;
def p4;
def p5;
def p6;
def p7;
def p8;
def p9;
switch (price_data) {
case chart_time:
 p1 = if isnan(close(s1)) then close(s1)[1] else close(s1);
 p2 = if isnan(close(s2)) then close(s1)[1] else close(s2);
 p3 = if isnan(close(s3)) then close(s1)[1] else close(s3);
 p4 = if isnan(close(s4)) then close(s1)[1] else close(s4);
 p5 = if isnan(close(s5)) then close(s1)[1] else close(s5);
 p6 = if isnan(close(s6)) then close(s1)[1] else close(s6);
 p7 = if isnan(close(s7)) then close(s1)[1] else close(s7);
 p8 = if isnan(close(s8)) then close(s1)[1] else close(s8);
 p9 = if isnan(close(s9)) then close(s1)[1] else close(s9);
case second_agg:
 p1 = if isnan(close(s1, agg)) then close(s1, agg)[1] else close(s1, agg);
 p2 = if isnan(close(s2, agg)) then close(s1, agg)[1] else close(s2, agg);
 p3 = if isnan(close(s3, agg)) then close(s1, agg)[1] else close(s3, agg);
 p4 = if isnan(close(s4, agg)) then close(s1, agg)[1] else close(s4, agg);
 p5 = if isnan(close(s5, agg)) then close(s1, agg)[1] else close(s5, agg);
 p6 = if isnan(close(s6, agg)) then close(s1, agg)[1] else close(s6, agg);
 p7 = if isnan(close(s7, agg)) then close(s1, agg)[1] else close(s7, agg);
 p8 = if isnan(close(s8, agg)) then close(s1, agg)[1] else close(s8, agg);
 p9 = if isnan(close(s9, agg)) then close(s1, agg)[1] else close(s9, agg);
}

input qty = 9;
def x = if !isnan(close(s1)) then 1 else 0;
plot Avg = if !x then na else (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9)/qty;
avg.setdefaultcolor(color.yellow);

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

input show_price_lines = no;

plot z1 = if (show_price_lines and x) then p1 else na;
z1.setdefaultcolor(getcolor(0));
z1.SetStyle(Curve.MEDIUM_DASH);
plot z2 = if (show_price_lines and x) then p2 else na;
z2.setdefaultcolor(getcolor(1));
z2.SetStyle(Curve.MEDIUM_DASH);
plot z3 = if (show_price_lines and x) then p3 else na;
z3.setdefaultcolor(getcolor(2));
z3.SetStyle(Curve.MEDIUM_DASH);
plot z4 = if (show_price_lines and x) then p4 else na;
z4.setdefaultcolor(getcolor(3));
z4.SetStyle(Curve.MEDIUM_DASH);
plot z5 = if (show_price_lines and x) then p5 else na;
z5.setdefaultcolor(getcolor(4));
z5.SetStyle(Curve.MEDIUM_DASH);
plot z6 = if (show_price_lines and x) then p5 else na;
z6.setdefaultcolor(getcolor(5));
z6.SetStyle(Curve.MEDIUM_DASH);
plot z7 = if (show_price_lines and x) then p7 else na;
z7.setdefaultcolor(getcolor(6));
z7.SetStyle(Curve.MEDIUM_DASH);
plot z8 = if (show_price_lines and x) then p8 else na;
z8.setdefaultcolor(getcolor(7));
z8.SetStyle(Curve.MEDIUM_DASH);
plot z9 = if (show_price_lines and x) then p9 else na;
z9.setdefaultcolor(getcolor(8));
z9.SetStyle(Curve.MEDIUM_DASH);
#


------------------

histogram study

Ruby:
# multiple_symbols1_02_histo

# https://usethinkscript.com/threads/creating-a-custom-index.12756/
# create a Moving Average for the average closing price of 10 specific stocks.

# ref
#https://usethinkscript.com/threads/getting-a-hma-value-of-a-different-symbol.12722/#post-108365

# LIDAR INDEX

declare lower;

def na = double.nan;
def bn = barnumber();

input price_data = { default chart_time , second_agg };
input Agg = AggregationPeriod.DAY;

input s1 = "LAZR";
input s2 = "VLDR";
input s3 = "MVIS";
input s4 = "INDI";
input s5 = "AEVA";
input s6 = "QNGY";
input s7 = "CPTN";
input s8 = "INVZ";
input s9 = "LIDR";

def p1;
def p2;
def p3;
def p4;
def p5;
def p6;
def p7;
def p8;
def p9;
switch (price_data) {
case chart_time:
 p1 = if isnan(close(s1)) then close(s1)[1] else close(s1);
 p2 = if isnan(close(s2)) then close(s1)[1] else close(s2);
 p3 = if isnan(close(s3)) then close(s1)[1] else close(s3);
 p4 = if isnan(close(s4)) then close(s1)[1] else close(s4);
 p5 = if isnan(close(s5)) then close(s1)[1] else close(s5);
 p6 = if isnan(close(s6)) then close(s1)[1] else close(s6);
 p7 = if isnan(close(s7)) then close(s1)[1] else close(s7);
 p8 = if isnan(close(s8)) then close(s1)[1] else close(s8);
 p9 = if isnan(close(s9)) then close(s1)[1] else close(s9);
case second_agg:
 p1 = if isnan(close(s1, agg)) then close(s1, agg)[1] else close(s1, agg);
 p2 = if isnan(close(s2, agg)) then close(s1, agg)[1] else close(s2, agg);
 p3 = if isnan(close(s3, agg)) then close(s1, agg)[1] else close(s3, agg);
 p4 = if isnan(close(s4, agg)) then close(s1, agg)[1] else close(s4, agg);
 p5 = if isnan(close(s5, agg)) then close(s1, agg)[1] else close(s5, agg);
 p6 = if isnan(close(s6, agg)) then close(s1, agg)[1] else close(s6, agg);
 p7 = if isnan(close(s7, agg)) then close(s1, agg)[1] else close(s7, agg);
 p8 = if isnan(close(s8, agg)) then close(s1, agg)[1] else close(s8, agg);
 p9 = if isnan(close(s9, agg)) then close(s1, agg)[1] else close(s9, agg);
}

input qty = 9;
input lvl1 = 3.5;
input lvl2 = 4.0;

def x = if !isnan(close(s1)) then 1 else 0;
plot Avg = if !x then na else (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9)/qty;
#avg.setdefaultcolor(color.yellow);
avg.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
avg.AssignValueColor(if avg >= lvl2 then color.green else if avg >= lvl1 then color.cyan else color.blue);
#
#

RLPQM6s.jpg
I modified the histo to change color based on increase/decrease of previous bar

def na = double.nan;
def bn = barnumber();

input price_data = { default chart_time , second_agg };
input Agg = AggregationPeriod.DAY;

input s1 = "LAZR";
input s2 = "VLDR";
input s3 = "MVIS";
input s4 = "INDI";
input s5 = "AEVA";
input s6 = "QNGY";
input s7 = "CPTN";
input s8 = "INVZ";
input s9 = "LIDR";

def p1;
def p2;
def p3;
def p4;
def p5;
def p6;
def p7;
def p8;
def p9;
switch (price_data) {
case chart_time:
p1 = if isnan(close(s1)) then close(s1)[1] else close(s1);
p2 = if isnan(close(s2)) then close(s1)[1] else close(s2);
p3 = if isnan(close(s3)) then close(s1)[1] else close(s3);
p4 = if isnan(close(s4)) then close(s1)[1] else close(s4);
p5 = if isnan(close(s5)) then close(s1)[1] else close(s5);
p6 = if isnan(close(s6)) then close(s1)[1] else close(s6);
p7 = if isnan(close(s7)) then close(s1)[1] else close(s7);
p8 = if isnan(close(s8)) then close(s1)[1] else close(s8);
p9 = if isnan(close(s9)) then close(s1)[1] else close(s9);
case second_agg:
p1 = if isnan(close(s1, agg)) then close(s1, agg)[1] else close(s1, agg);
p2 = if isnan(close(s2, agg)) then close(s1, agg)[1] else close(s2, agg);
p3 = if isnan(close(s3, agg)) then close(s1, agg)[1] else close(s3, agg);
p4 = if isnan(close(s4, agg)) then close(s1, agg)[1] else close(s4, agg);
p5 = if isnan(close(s5, agg)) then close(s1, agg)[1] else close(s5, agg);
p6 = if isnan(close(s6, agg)) then close(s1, agg)[1] else close(s6, agg);
p7 = if isnan(close(s7, agg)) then close(s1, agg)[1] else close(s7, agg);
p8 = if isnan(close(s8, agg)) then close(s1, agg)[1] else close(s8, agg);
p9 = if isnan(close(s9, agg)) then close(s1, agg)[1] else close(s9, agg);
}

input qty = 9;
input lvl1 = 3.5;
input lvl2 = 4.0;

def x = if !isnan(close(s1)) then 1 else 0;
plot Avg = if !x then na else (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9)/qty;
#avg.setdefaultcolor(color.yellow);
avg.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
avg.AssignValueColor(if avg > avg from 1 bar ago then color.green else if avg < avg from 1 bar ago then color.red else color.yellow);
#
#
 
Last edited by a moderator:

halcyonguy

Well-known member
VIP
Lifetime
This is what I mean by giving me a starting point and the same line (The link). It wouldnt let me post the picture for some reason but regardless of the length input of the MA the line remained the same (Seems to be fixed now). My end goal is to have the chart candlesticks turned off and have the study register as candlesticks instead of a line and to run it side by side with the stock im trading so essentially it would look like just another stock to anyone looking at it.

https://1drv.ms/u/s!Ai-lRKVY6qfrhkmEtbjImSqiwid-?e=Jq4BPV

In its current version (the Line study you posted) why is the line fixed? It doesnt adjust on the chart like a typical MA. If its changed from a line to candlesticks will it adjust?

what do you mean by 'fixed' ?

if you are wondering why the line looks the same when you load a different symbol on the chart,
reread my previous post,

the study isn't reading data from a chart. it is reading the same 9 stock prices on whatever chart you look at, so the line will always be the same, no matter what stock is loaded in the main chart.


you can't post images on this forum. need to copy a link to an image , and paste that. the answer is explained in a link, in sentences #3 , at the top of the questions group.
https://usethinkscript.com/forums/questions.6/
 

crscrs85

New member
what do you mean by 'fixed' ?

if you are wondering why the line looks the same when you load a different symbol on the chart,
reread my previous post,

the study isn't reading data from a chart. it is reading the same 9 stock prices on whatever chart you look at, so the line will always be the same, no matter what stock is loaded in the main chart.


you can't post images on this forum. need to copy a link to an image , and paste that. the answer is explained in a link, in sentences #3 , at the top of the questions group.
https://usethinkscript.com/forums/questions.6/
I understand it is calculating from the 9 stocks. The blue line in the pic has a starting point and an end point, and wouldnt change when i adjusted the aggregation period. Image link below, hopfully it works correctly, l followed the instructions from the link. Like I said, its working fine now, it was an error from my attempt not yours.

SVHV0uH.png
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top