Previous day Midpoint drawn on chart as a line today

Epavell

New member
Looking to draw a line on todays chart that is yesterday's midpoint.

Have coding that create a label but also looking to ad the line on the chart as well. here is the code I have.

**************
input candletype = {default candle, heikinashi};
def HAclose = hlc3;
rec HAopen = CompoundValue( 1, ( HAopen[1] + HAclose[1] ) / 2, HAclose );
def HAhigh = Max( high, Max( HAopen, HAclose ) );
def HAlow = Min( low, Min( HAopen, HAclose ) );
plot Data = if candletype == candletype.heikinashi
then (HAhigh + HAlow) / 2
else hl2;
Data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Data.AssignValueColor(if Data > Data[1] then Color.GREEN else CreateColor(102, 0, 0));
Data.SetLineWeight(5);

def midpoint = data;


Plot Previousbar = data[1];
AddLabel(yes, "prev bar = " + data[1], Color.white );

Plot Currentbar = data;
AddLabel(yes, "Curr bar = " + data, Color.white );
#------------------------------------
# LABEL SECTION
#------------------------------------


#AddLabel(yes,

#if Data[1] < close then “Abv prev Midpoint” else if Data[1] > close then “Below prev Midpoint” else "WAIT", Color.white);

#AddLabel(yes, if midpoint < close then Color.LIGHT_GREEN else if midpoint > close then Color.LIGHT_RED else Color.white);

AddLabel(yes, "Previous Bar", if data[1] < close then Color.LIGHT_GREEN else if data[1] > close then Color.Light_red else Color.WHITE);

AddLabel(yes, "Current Bar", if data < close then Color.light_green else if data > close then Color.LIGHT_RED else Color.WHITE);



Thank you in advance.
 
Solution
Looking to draw a line on todays chart that is yesterday's midpoint.

Have coding that create a label but also looking to ad the line on the chart as well. here is the code I have.

**************
input candletype = {default candle, heikinashi};
def HAclose = hlc3;
rec HAopen = CompoundValue( 1, ( HAopen[1] + HAclose[1] ) / 2, HAclose );
def HAhigh = Max( high, Max( HAopen, HAclose ) );
def HAlow = Min( low, Min( HAopen, HAclose ) );
plot Data = if candletype == candletype.heikinashi
then (HAhigh + HAlow) / 2
else hl2;
Data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Data.AssignValueColor(if Data > Data[1] then Color.GREEN else CreateColor(102, 0, 0));
Data.SetLineWeight(5)...
Looking to draw a line on todays chart that is yesterday's midpoint.

Have coding that create a label but also looking to ad the line on the chart as well. here is the code I have.

**************
input candletype = {default candle, heikinashi};
def HAclose = hlc3;
rec HAopen = CompoundValue( 1, ( HAopen[1] + HAclose[1] ) / 2, HAclose );
def HAhigh = Max( high, Max( HAopen, HAclose ) );
def HAlow = Min( low, Min( HAopen, HAclose ) );
plot Data = if candletype == candletype.heikinashi
then (HAhigh + HAlow) / 2
else hl2;
Data.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Data.AssignValueColor(if Data > Data[1] then Color.GREEN else CreateColor(102, 0, 0));
Data.SetLineWeight(5);

def midpoint = data;


Plot Previousbar = data[1];
AddLabel(yes, "prev bar = " + data[1], Color.white );

Plot Currentbar = data;
AddLabel(yes, "Curr bar = " + data, Color.white );
#------------------------------------
# LABEL SECTION
#------------------------------------


#AddLabel(yes,

#if Data[1] < close then “Abv prev Midpoint” else if Data[1] > close then “Below prev Midpoint” else "WAIT", Color.white);

#AddLabel(yes, if midpoint < close then Color.LIGHT_GREEN else if midpoint > close then Color.LIGHT_RED else Color.white);

AddLabel(yes, "Previous Bar", if data[1] < close then Color.LIGHT_GREEN else if data[1] > close then Color.Light_red else Color.WHITE);

AddLabel(yes, "Current Bar", if data < close then Color.light_green else if data > close then Color.LIGHT_RED else Color.WHITE);



Thank you in advance.

See if this helps

Code:
plot midpoint = if getday() == getlastday() then hl2(period=aggregationPeriod.DAY)[1] else double.nan;
Screenshot 2023-08-08 145040.png
 
Solution

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

Hi SleepyZ. The line is added to todays chart but can it use the heikinashi formula to plot the line.

Here is the heikinashi version

Code:
input days_back = 1;
input aggregationPeriod = AggregationPeriod.DAY;
def o = open(period = aggregationPeriod)[days_back];
def h = high(period = aggregationPeriod)[days_back];
def l = low(period = aggregationPeriod)[days_back];
def c = close(period = aggregationPeriod)[days_back];

def HAclose   =  (o + h + l + c) / 4;
def HAopen    = CompoundValue( 1, ( HAopen[1] + HAclose[1] ) / 2, HAclose );
def HAhigh    = Max( h, Max( HAopen, HAclose ) );
def HAlow     = Min( l, Min( HAopen, HAclose ) );

plot heikenashi_midpoint = if GetDay() == GetLastDay() then (HAhigh + HAlow) / 2 else Double.NaN;
heikenashi_midpoint.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
heikenashi_midpoint.SetDefaultColor(Color.YELLOW);

#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
388 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