• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

How to calculate candle open close from chart not the timeframe

Baappi

New member
Hello I am looking to calculate Candle(bar) open / close from the CHART not the actual timeframe itself. Please help.
Its ok to get the calculations at the close of the bar itself or for the previous bar from the chart. Image posted below.

k48vMH8.jpeg


I have a CHART that has different open / close from actual 1 min open/close due to various calculation which is beyond me.

Eg: from the image posted. Actual 1 min open = 515 close = 515.75

However chart suggests open = 504 close = 508.

Note: In simple terms, script to calculate open/close from an indicator listed on the chart would work too.

Thank you.
 
Last edited:

Baappi

New member
@Baappi You're using Heikin Ashi candles. Change them back to Candle in Style(top-right). Or are you trying to use HA and have open and close plotted on the HA candles?
generic.. tq for response, i am using a study....

code below... i would like to plot below length of each bar...just to see what is absolute value of (open - close). thanks again.

Code:
# TS_HeikinAshiSmoothed



### YOU MUST HAVE THE STYLE SETTING FIT STUDIES ENABLED ###
#hint: The style setting Fit Studies must be enabled tou use these bars.

input period = 21;
input hideCandles = NO;
input candleSmoothing = {default Valcu, Vervoort};

DefineGlobalColor("RisingMA", color.uptick);
DefineGlobalColor("FallingMA", color.downtick);
#DefineGlobalColor("RisingMA", color.cyan);
#DefineGlobalColor("FallingMA", color.yellow);

input movingAverageType = {default TEMA, Exponential, Weighted, Hull, Variable, SIMPLE};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Simple:
    openMA = compoundValue(1, Average(open, period), open);
    closeMA = compoundValue(1, Average(close, period), close);
    highMA = compoundValue(1, Average(high, period), high);
    lowMA = compoundValue(1, Average(low, period), low);
case Exponential:
    openMA = compoundValue(1, ExpAverage(open, period), open);
    closeMA = compoundValue(1, ExpAverage(close, period), close);
    highMA = compoundValue(1, ExpAverage(high, period), high);
    lowMA = compoundValue(1, ExpAverage(low, period), low);
case Weighted:
    openMA = compoundValue(1, WMA(open, period), open);
    closeMA = compoundValue(1, WMA(close, period), close);
    highMA = compoundValue(1, WMA(high, period), high);
    lowMA = compoundValue(1, WMA(low, period), low);
Case Hull:
    openMA = compoundValue(1, HullMovingAvg(open, period), open);
    closeMA = compoundValue(1,  HullMovingAvg(close, period), close);
    highMA = compoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = compoundValue(1,  HullMovingAvg(low, period), low);
case variable:
    openMA = compoundValue(1, VariableMA(open, period), open);
    closeMA = compoundValue(1, VariableMA(close, period), close);
    highMA = compoundValue(1, VariableMA(high, period), high);
    lowMA = compoundValue(1, VariableMA(low, period), low);
case TEMA:
    openMA = compoundValue(1, TEMA(open, period), open);
    closeMA = compoundValue(1, TEMA(close, period), close);
    highMA = compoundValue(1, TEMA(high, period), high);
    lowMA = compoundValue(1, TEMA(low, period), low);
}


hidePricePlot(hideCandles);

def haOpen;
def haClose;

switch(candleSmoothing) {
case Valcu:

    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;
  
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((((OpenMA + HighMA + LowMA + CloseMA)/4.0) + haOpen + Max(HighMA, haOpen) + Min(LowMA, haOpen))/4.0);

}

plot o = haopen;
o.hide();

def haLow =  min(lowMA, haOpen);
def haHigh = max(highMA,haOpen);

AddChart(high = haHigh, low  = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);

def haopen1 = if haopen>haclose
              then HAopen
              else double.nan;
def HAhigh1   = if haopen>=haclose
              then hahigh
              else double.nan;
def HAlow1    = if haopen>=haclose
              then halow
              else double.nan;

AddChart(high = haHigh1, low  = haLow1, open = haopen1, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("FallingMA"), fallColor = GlobalColor("RisingMA"), neutralColor = color.gray);
 

Baappi

New member
@Baappi You're using Heikin Ashi candles. Change them back to Candle in Style(top-right). Or are you trying to use HA and have open and close plotted on the HA candles?
Hi it worked out...i just used the same code replaced ADDchart with Plots/below; and used high/open from the script. All good now, except not sure what i am trying to achieve..lol.
 

Similar threads

Top