# Trying to rewrite 1 minute OHLC data without opening gaps

I am trying to create new OHLC data that fixes opening gaps. As an example, I would create a new series that assumes that the morning opening price is the previous closing price and I would use the ln(c/o) to create the new closing price at the open. How should I go about doing this? Should I use addtocomposite() or create arrays using loops? Thanks for any feedback.

You don't need to create such data series if you just want to see such chart.
A simple:

``````Open = Ref( Close, -1 ); // remove opening gap
High = Max( High, Open ); // fix high if previous close > high
Low = Min( Low, Open ); // fix low if previous close < low

Plot(Close, "Price", colorDefault, styleCandle );
``````

would do this on-the-fly without need to create any data

Thanks for the reply. I forgot to mention that I'm using 1 minute data and I'm trying to preserve the percentages related to the candle. So the ratios of the high to the open, low to the open and close to the open would remain the same. The only difference would be removing the morning gap between the previous close and the open.

Just store the original ratios before changing OHL arrays.

``````ratio1 = H/O;
ratio2 = L/O;
ratio3 = C/O;

Open = Ref( Close, -1 ); // remove opening gap
High = Max( High, Open ); // fix high if previous close > high
Low = Min( Low, Open ); // fix low if previous close < low

Plot(Close, "Price", colorDefault, styleCandle );
``````

This was my solution:

``````oc=ln(C/o);
dco=ln(O/Ref(C,-1));
ol=ln(L/O);
oh=ln(H/O);

tim=Hour()*100+Minute();

C_new=ln(C);
o_new=ln(o);
l_new=ln(l);
h_new=ln(h);

for( i=1; i<BarCount; i++ )
{ if ( tim[i]==930 )
{	o_new[i]=C_new[i-1];
}
else
{	O_new[i]=C_new[i-1]+dco[i];
}

C_new[i]=O_new[i]+oc[i];
h_new[i]=O_new[i]+oh[i];
L_new[i]=o_new[i]+ol[i];
}

Plot(exp(C_new),"c", colorGreen, styleLine);
Plot(exp(o_new),"o", colorgreen, styleLine);
Plot(exp(l_new),"l", colorred, styleLine);
Plot(exp(h_new),"h", colorblue, styleLine);
``````

Not sure how efficient this code is, but it seems to work.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.