Plotting Value$ on Price Chart creating a Moving Average

grapetux

Member
Hi there, I've successfully plotted the upper and lower boundaries that I have defined on the upper price chart as pictured.
As you can see in the below code, the input values have been set so the upper boundary is plotting at the price level of 369 and the
lower at 366, as red and green dotted lines.

Instead of defining the input values as a number, you can put a word such a High,Low,Open,Close, Vwap etc.. to have the line plotted on the price chart mimicking a moving average. When you define the input with those recognized words, you get a drop down list when you select 'edit properties' from the 'edit studies' menu containing other options, (H+L)/2, Tick Count, Volume, Open Interest etc etc..

My question is, is there a way to define the input value to have these boundaries plot above the high and low of current price + 1 standard deviation? or some other set value? Rather than have these defined boundaries stuck at a fixed price throughout the trading day, my goal would be to have these input values plot a line above current price to appear as a moving average containing all price action. Below is the code for these plots. Hope my explanation makes sense, thanks for any help. Cheers
-N

input UpperBoundary = 369;
plot Upperlevel= if hi>0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);

input LowerBoundary = 366;
plot Lowerlevel = if lo<0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);


MZc5Va5.jpg


@SleepyZ hey my friend.. Any idea on this one? Appreciate the help
 
Last edited by a moderator:
Hi there, I've successfully plotted the upper and lower boundaries that I have defined on the upper price chart as pictured.
As you can see in the below code, the input values have been set so the upper boundary is plotting at the price level of 369 and the
lower at 366, as red and green dotted lines.

Instead of defining the input values as a number, you can put a word such a High,Low,Open,Close, Vwap etc.. to have the line plotted on the price chart mimicking a moving average. When you define the input with those recognized words, you get a drop down list when you select 'edit properties' from the 'edit studies' menu containing other options, (H+L)/2, Tick Count, Volume, Open Interest etc etc..

My question is, is there a way to define the input value to have these boundaries plot above the high and low of current price + 1 standard deviation? or some other set value? Rather than have these defined boundaries stuck at a fixed price throughout the trading day, my goal would be to have these input values plot a line above current price to appear as a moving average containing all price action. Below is the code for these plots. Hope my explanation makes sense, thanks for any help. Cheers
-N

input UpperBoundary = 369;
plot Upperlevel= if hi>0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);

input LowerBoundary = 366;
plot Lowerlevel = if lo<0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);


MZc5Va5.jpg


@SleepyZ hey my friend.. Any idea on this one? Appreciate the help
Hi there,
That is a nice set up you have there. Do you mind to share the chart? I might be able to help you with the code.

I am not very good at coding but I think this is what you need. The code works good, I checked it out. But you try it as well and let me know if does what you want

declare upper;

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;

def DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
def DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);


input UpperBoundaryDevUp = 1.0;

def UpperBoundary = DailyHigh + UpperBoundaryDevUp * standardDeviation (DailyHigh);

plot Upperlevel = if DailyHigh >0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);


input LowerBoundaryDevDn = -1.0;

def LowerBoundary = DailyLow + LowerBoundaryDevDn * standardDeviation (DailyLow);

plot Lowerlevel = if DailyLow>0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);
 
Hi there, I've successfully plotted the upper and lower boundaries that I have defined on the upper price chart as pictured.
As you can see in the below code, the input values have been set so the upper boundary is plotting at the price level of 369 and the
lower at 366, as red and green dotted lines.

Instead of defining the input values as a number, you can put a word such a High,Low,Open,Close, Vwap etc.. to have the line plotted on the price chart mimicking a moving average. When you define the input with those recognized words, you get a drop down list when you select 'edit properties' from the 'edit studies' menu containing other options, (H+L)/2, Tick Count, Volume, Open Interest etc etc..

My question is, is there a way to define the input value to have these boundaries plot above the high and low of current price + 1 standard deviation? or some other set value? Rather than have these defined boundaries stuck at a fixed price throughout the trading day, my goal would be to have these input values plot a line above current price to appear as a moving average containing all price action. Below is the code for these plots. Hope my explanation makes sense, thanks for any help. Cheers
-N

input UpperBoundary = 369;
plot Upperlevel= if hi>0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);

input LowerBoundary = 366;
plot Lowerlevel = if lo<0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);


MZc5Va5.jpg


@SleepyZ hey my friend.. Any idea on this one? Appreciate the help
@grapetux
Hi there,
Did you try this code that I shared? Not sure if you saw my reply below. Just checking to see if it worked or not.

Also, if you don't mind can you please share the candle coloring and tick study you have on your part?

Thanks,


Hi there,
That is a nice set up you have there. Do you mind to share the chart? I might be able to help you with the code.

I am not very good at coding but I think this is what you need. The code works good, I checked it out. But you try it as well and let me know if does what you want

declare upper;

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;

def DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
def DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);


input UpperBoundaryDevUp = 1.0;

def UpperBoundary = DailyHigh + UpperBoundaryDevUp * standardDeviation (DailyHigh);

plot Upperlevel = if DailyHigh >0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);


input LowerBoundaryDevDn = -1.0;

def LowerBoundary = DailyLow + LowerBoundaryDevDn * standardDeviation (DailyLow);

plot Lowerlevel = if DailyLow>0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);
 
@grapetux
Hi there,
Did you try this code that I shared? Not sure if you saw my reply below. Just checking to see if it worked or not.

Also, if you don't mind can you please share the candle coloring and tick study you have on your part?

Thanks,


Hi there,
That is a nice set up you have there. Do you mind to share the chart? I might be able to help you with the code.

I am not very good at coding but I think this is what you need. The code works good, I checked it out. But you try it as well and let me know if does what you want

declare upper;

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;

def DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
def DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);


input UpperBoundaryDevUp = 1.0;

def UpperBoundary = DailyHigh + UpperBoundaryDevUp * standardDeviation (DailyHigh);

plot Upperlevel = if DailyHigh >0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);


input LowerBoundaryDevDn = -1.0;

def LowerBoundary = DailyLow + LowerBoundaryDevDn * standardDeviation (DailyLow);

plot Lowerlevel = if DailyLow>0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);
Hey brotha, sorry for the delay. I dont have the code for the repainted chart any longer but I have a lot of similar and better things if you're looking for repaint study. As for the tick study.. below is the latest version I'm using, coupled with some cool crossover studies and signals..

Let me know if you have any questions or if I can help with more studies, cheers
-N

declare lower;
def Data = close("$tick/q");


plot data1 = WildersSmoothing(Data, 8);
data1.AssignValueColor(if data1 > data1[1] then Color.GREEN else CreateColor(255, 55, 55));


def hi = high("$TICK");
def lo = low("$TICK");
def tick = close("$TICK");

plot highmid = ExpAverage(hi, 2);

def mid = (hi + lo + close) / 3;
plot uh = ExpAverage(mid, 10);
def off = lo<-750 and hi>750;



plot Ask = hi;
Ask.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Ask.AssignValueColor( if hi>0 and lo<0 then CreateColor(75, 75, 75 ) else if off then color.black else if uh < 0 and lo > 0 and hi > 0 then Color.magenta else if hi > 900 then Color.green else if hi > 0 and lo > 0 then CreateColor(35, 135, 35) else CreateColor(65, 65, 65 ) );


#CreateColor(240, 180, 80 )

plot Bid = lo;
Bid.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Bid.AssignValueColor( if hi>0 and lo<0 then CreateColor(75, 75, 75 ) else if off then color.black else if uh > 0 and lo < 0 and hi < 0 then Color.magenta else if lo < -1100 then color.red else if lo < 0 and hi < 0 then CreateColor(135, 55, 55) else CreateColor(65, 65, 65 ) );

############
def pone = (hi + lo + tick) / 3;
def ptwo = (hi[1] + lo[1] + tick[1]) / 3;
def pthree = (hi[2] + lo[2] + tick[2]) / 3;
############

plot Tpiv1 = (pone + ptwo + pthree) / 3;


plot midd = 0;
#tpiv1.assignValueColor(if tpiv1>tpiv1[1] then createcolor(30,225,30) else createcolor(190,5,5));


##ZERO LINE CROSS STUDY
input ZXup = 0;
plot zerocrossUP = if Tpiv1 crosses above 0 then ZXup else Double.NaN;
input ZXdn = 0;
plot zerocrossDN = if Tpiv1 crosses below 0 then ZXdn else Double.NaN;


input up = 1500;
input dn= 1500;
plot up1 = if tpiv1>0 then up else Double.NaN;
plot dn1 = if tpiv1<0 then dn else Double.NaN;


def VWMA = Sum(volume * close) / Sum(volume);
input length1 = 9;
input price = close;
input displace = 0;

def piv1 = (pone + ptwo + pthree) / 3;
def simp2 = WildersSmoothing(piv1, 2);




plot v1 = Average(VWMA[-displace], length1);

input Incline = 1200;
plot Istring = if volume > volume[1] and volume[1] > volume[2] and volume [2] > volume [3] and volume [3] > volume [4]
then Incline else Double.NaN;
#Istring.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#istring.assignValueColor(if istring then color.light_green else color.current);

input Decline = 1200;
plot Dstring = if volume < volume[1] and volume[1] < volume[2] and volume [2] < volume [3] and volume [3] < volume [4] then Decline else Double.NaN;
#Dstring.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#assignpriceColor(if dstring then color.light_red else color.current);

def UVOLQ = close(“$UVOL/q”);
def DVOLQ = close(“$DVOL/q”);
#Nasdaq Breadth ratio
def NASDratio = if (UVOLQ >= DVOLQ) then (UVOLQ / DVOLQ) else -(DVOLQ / UVOLQ);



input NasDnVoUplDivy = 1000;
plot priceup = if price>price[1] and price[1]>price[2] and price[2]>price[3] and nasDratio<nasDratio[1] and nasDratio[1]<nasDratio[2] and nasDratio[2]<nasDratio[3] then NasDnVoUplDivy else Double.NaN;
priceup.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

input NasUpVolDnlDivy= 1000;
plot pricedn = if price<price[1] and price[1]<price[2] and price[2]<price[3] and nasDratio>nasDratio[1] and nasDratio[1]>nasDratio[2] and nasDratio[2]>nasDratio[3] then NasUpVolDnlDivy else Double.NaN;
pricedn.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_down);
 
Hey brotha, sorry for the delay. I dont have the code for the repainted chart any longer but I have a lot of similar and better things if you're looking for repaint study. As for the tick study.. below is the latest version I'm using, coupled with some cool crossover studies and signals..

Let me know if you have any questions or if I can help with more studies, cheers
-N

declare lower;
def Data = close("$tick/q");


plot data1 = WildersSmoothing(Data, 8);
data1.AssignValueColor(if data1 > data1[1] then Color.GREEN else CreateColor(255, 55, 55));


def hi = high("$TICK");
def lo = low("$TICK");
def tick = close("$TICK");

plot highmid = ExpAverage(hi, 2);

def mid = (hi + lo + close) / 3;
plot uh = ExpAverage(mid, 10);
def off = lo<-750 and hi>750;



plot Ask = hi;
Ask.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Ask.AssignValueColor( if hi>0 and lo<0 then CreateColor(75, 75, 75 ) else if off then color.black else if uh < 0 and lo > 0 and hi > 0 then Color.magenta else if hi > 900 then Color.green else if hi > 0 and lo > 0 then CreateColor(35, 135, 35) else CreateColor(65, 65, 65 ) );


#CreateColor(240, 180, 80 )

plot Bid = lo;
Bid.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Bid.AssignValueColor( if hi>0 and lo<0 then CreateColor(75, 75, 75 ) else if off then color.black else if uh > 0 and lo < 0 and hi < 0 then Color.magenta else if lo < -1100 then color.red else if lo < 0 and hi < 0 then CreateColor(135, 55, 55) else CreateColor(65, 65, 65 ) );

############
def pone = (hi + lo + tick) / 3;
def ptwo = (hi[1] + lo[1] + tick[1]) / 3;
def pthree = (hi[2] + lo[2] + tick[2]) / 3;
############

plot Tpiv1 = (pone + ptwo + pthree) / 3;


plot midd = 0;
#tpiv1.assignValueColor(if tpiv1>tpiv1[1] then createcolor(30,225,30) else createcolor(190,5,5));


##ZERO LINE CROSS STUDY
input ZXup = 0;
plot zerocrossUP = if Tpiv1 crosses above 0 then ZXup else Double.NaN;
input ZXdn = 0;
plot zerocrossDN = if Tpiv1 crosses below 0 then ZXdn else Double.NaN;


input up = 1500;
input dn= 1500;
plot up1 = if tpiv1>0 then up else Double.NaN;
plot dn1 = if tpiv1<0 then dn else Double.NaN;


def VWMA = Sum(volume * close) / Sum(volume);
input length1 = 9;
input price = close;
input displace = 0;

def piv1 = (pone + ptwo + pthree) / 3;
def simp2 = WildersSmoothing(piv1, 2);




plot v1 = Average(VWMA[-displace], length1);

input Incline = 1200;
plot Istring = if volume > volume[1] and volume[1] > volume[2] and volume [2] > volume [3] and volume [3] > volume [4]
then Incline else Double.NaN;
#Istring.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#istring.assignValueColor(if istring then color.light_green else color.current);

input Decline = 1200;
plot Dstring = if volume < volume[1] and volume[1] < volume[2] and volume [2] < volume [3] and volume [3] < volume [4] then Decline else Double.NaN;
#Dstring.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#assignpriceColor(if dstring then color.light_red else color.current);

def UVOLQ = close(“$UVOL/q”);
def DVOLQ = close(“$DVOL/q”);
#Nasdaq Breadth ratio
def NASDratio = if (UVOLQ >= DVOLQ) then (UVOLQ / DVOLQ) else -(DVOLQ / UVOLQ);



input NasDnVoUplDivy = 1000;
plot priceup = if price>price[1] and price[1]>price[2] and price[2]>price[3] and nasDratio<nasDratio[1] and nasDratio[1]<nasDratio[2] and nasDratio[2]<nasDratio[3] then NasDnVoUplDivy else Double.NaN;
priceup.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);

input NasUpVolDnlDivy= 1000;
plot pricedn = if price<price[1] and price[1]<price[2] and price[2]<price[3] and nasDratio>nasDratio[1] and nasDratio[1]>nasDratio[2] and nasDratio[2]>nasDratio[3] then NasUpVolDnlDivy else Double.NaN;
pricedn.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_down);
Hi There,

Thank you so much for your response. It would be nice to have a good repainting study. I recently switched to TOS from Trading View. I literally have everything for Trading View but not much for TOS. I would greatly appreciate it if you share the repainting study.

Did you try the code that I sent you? Did it work and did what you wanted? I am still in the learning process of coding on TOS and just wanna make sure it's what you were looking for.

Good Luck,
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
450 Online
Create Post

Similar threads

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.
Back
Top