i tried adding the following code to return the bar number but its not working.
Code:
def crossing_bar = if close and extension crosses extension2 then BarNumber() else crossing_bar[1];
AddLabel (yes, "crossing bar" + (crossing_bar) );
If i can get the bar number i can get the price its at but i must first get the bar number and the code isnt working. Im not really to familiar with extending to the right where there is are no bars to retrieve data. Perhaps @SleepyZ can chime in and help.
i tried adding the following code to return the bar number but its not working.
Code:
def crossing_bar = if close and extension crosses extension2 then BarNumber() else crossing_bar[1];
AddLabel (yes, "crossing bar" + (crossing_bar) );
If i can get the bar number i can get the price its at but i must first get the bar number and the code isnt working. Im not really to familiar with extending to the right where there is are no bars to retrieve data. Perhaps @SleepyZ can chime in and help.
def cross = if extension crosses extension2 then barnumber() else double.nan;
plot x = if barnumber()==highestall(cross) then extension else double.nan;
x.setpaintingStrategy(PaintingStrategy.ARROW_UP);
addchartbubble(barnumber()==highestall(cross), highestall(x), round(highestall(x)),color.white);
nice work SleepyZ, i battled that for like 30 mins going crazy trying to figure it out, i used double.nan too but was strange the label wouldnt record the number.
even with your code Cross wont return the bar number on a label as the example above. thats strange, thats what had me stumped, i still dont understand why it doesnt. but i guess if the code is properly coded and finished like you did it then the final code works. thats strange. im baffled as to why cross doesnt return barnumber value in
AddLabel (yes, "TEST " + (cross) );
yet it still works correctly for final code.
all my previous codings for getting barnumber always returns a value in the label when testing if i have it coded right....this is coded right but the bar number value doesnt show, super strange.
nice work SleepyZ, i battled that for like 30 mins going crazy trying to figure it out, i used double.nan too but was strange the label wouldnt record the number.
even with your code Cross wont return the bar number on a label as the example above. thats strange, thats what had me stumped, i still dont understand why it doesnt. but i guess if the code is properly coded and finished like you did it then the final code works. thats strange. im baffled as to why cross doesnt return barnumber value in
AddLabel (yes, "TEST " + (cross) );
yet it still works correctly for final code.
all my previous codings for getting barnumber always returns a value in the label when testing if i have it coded right....this is coded right but the bar number value doesnt show, super strange.
Sometimes the extensions do not cross within the extended chart area, causing no values for the labels. When a cross is present, this should produce values for your labels.
Huge thank you to everyone who contributed their time and effort on this! XeoNox and SleepyZ especially. I will be using this through the week. Definitely excited to see how this works.
the extension value doesnt refresh itself. i had to change the timeframe of the chart and come back then it shows the value. otherwise it is stuck. Any idea what could be done? TIA
the extension value doesnt refresh itself. i had to change the timeframe of the chart and come back then it shows the value. otherwise it is stuck. Any idea what could be done? TIA
I’m not really sure. I haven’t used the SMA extension indicator really. I do use the version with the STARC band extensions all the time though. I haven’t had trouble with that version. I’m sorry I can’t be of more help.
I’m not really sure. I haven’t used the SMA extension indicator really. I do use the version with the STARC band extensions all the time though. I haven’t had trouble with that version. I’m sorry I can’t be of more help.
nice work SleepyZ, i battled that for like 30 mins going crazy trying to figure it out, i used double.nan too but was strange the label wouldnt record the number.
even with your code Cross wont return the bar number on a label as the example above. thats strange, thats what had me stumped, i still dont understand why it doesnt. but i guess if the code is properly coded and finished like you did it then the final code works. thats strange. im baffled as to why cross doesnt return barnumber value in
AddLabel (yes, "TEST " + (cross) );
yet it still works correctly for final code.
all my previous codings for getting barnumber always returns a value in the label when testing if i have it coded right....this is coded right but the bar number value doesnt show, super strange.
I’m not really sure. I haven’t used the SMA extension indicator really. I do use the version with the STARC band extensions all the time though. I haven’t had trouble with that version. I’m sorry I can’t be of more help.
Hi chinks1980!
When I see a consistent zone where the extensions are crossing, it can indicate support/resistance zones as well as directionality of future price movements. More than anything, I look for the extensions to agree on direction and not be crossed. When this happens price will be moving the indicated direction. When the extensions cross, especially when their direction is contradictory (one up and one down), price movement will start to stagnate and potentially shift into a reversal.
# Plotting MA slope into extension area (Modded v2021.1)
# Mobius
# Chat Room Request
#Modded by XeoNoX for more recent data and incorporation of inertia in v2021.1
#draws extended line to the right of the chart based off recent linear regression curve of the Moving Average
#Mod by Sleepyz to limit length of extension
input MAlength = 20;
input AvgType = AverageType.SIMPLE;
input price = close;
plot moveavg = MovingAverage(AvgType, price, MAlength);
moveavg.SetDefaultColor(CreateColor(0, 255, 0));
moveavg.SetLineWeight(1);
def inertline = inertiaall(moveavg,2);
def EXT_MA = if !IsNaN(close()) then inertline else EXT_MA[1] + ((EXT_MA[1] - EXT_MA[2]) / (2 - 1));
input extension_length_limited_to = 20;
def lastbar = if isnan(close[-1]) and !isnan(close) then barnumber() else double.nan;
plot extension = if barnumber()<=highestall(lastbar)+ extension_length_limited_to then EXT_MA else double.nan;
extension.SetDefaultColor(CreateColor(0, 255, 255));
extension.SetLineWeight(1);
I added on to Mobius's code, all credits to him, i incorporated inertia plus made it so it uses the more recent data.
Plotting MA slope into extension area (Modded) .. All original credits to MOBIUS
Modded by XeoNoX for more recent data and incorporation of inertia in v2021.1
Draws extended line to the right of the chart based off recent linear regression curve of the Moving Average
(Most likely used for attempting future moving average prediction)
Code:
# Plotting MA slope into extension area (Modded v2021.1)
# Mobius
# Chat Room Request
#Modded by XeoNoX for more recent data and incorporation of inertia in v2021.1
#draws extended line to the right of the chart based off recent linear regression curve of the Moving Average
input MAlength = 20;
input AvgType = AverageType.SIMPLE;
input price = close;
plot moveavg = MovingAverage(AvgType, price, MAlength);
moveavg.SetDefaultColor(CreateColor(0, 255, 0));
moveavg.SetLineWeight(1);
def inertline = inertiaall(moveavg,2);
def EXT_MA = if !IsNaN(close()) then inertline else EXT_MA[1] + ((EXT_MA[1] - EXT_MA[2]) / (2 - 1));
plot extension = EXT_MA;
extension.SetDefaultColor(CreateColor(0, 255, 255));
extension.SetLineWeight(1);
Is it possible to have the extension color dynamically base on the slope of the current average? AssignValueColor will only work on the current bar (won't color into the future), and setdefaultcolor will color into the future, but it doesn't allow for dynamic coloring based on slope. Have any thoughts on how to do this?
Is it possible to have the extension color dynamically base on the slope of the current average? AssignValueColor will only work on the current bar (won't color into the future), and setdefaultcolor will color into the future, but it doesn't allow for dynamic coloring based on slope. Have any thoughts on how to do this?
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.
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.