Hi, I have the following code:
That is running on a 1min 30 day chart. I want the plot to return one candle per trading day. And if possible though I don't think it is, return the time of the one candle that is plotted.
Here is a better example of what I mean. It is much more complicated but It is better to do it right I suppose.
Code:
def yesterdaysClose = if close(period = "DAY")[1] < open(period = "DAY")[1] then close(period = "DAY")[1] else double.nan;
plot yc = yesterdaysClose;
Here is a better example of what I mean. It is much more complicated but It is better to do it right I suppose.
Code:
#- TS_GapFill
#- http://www.thinkscripter.com
#- [email protected]
#- Last Update 28 Jan 2010
# Time related
input marketOpenTime = 0930;
input marketCloseTime = 1615;
def secondsFromOpen = secondsFromTime(marketOpenTime);
def secondsTillClose = secondsTillTime(marketCloseTime);
def marketOpen = if secondsFromOpen >= 0 and secondsTillClose >= 0 then 1 else 0;
def newDay = if getDay() != getDay()[1] then 1 else 0;
# Price
def yesterdaysClose = close(period = "DAY")[1];
# First Open
rec regularHoursOpen = if (secondsFromOpen >= 0 and secondsFromOpen[1] < 0) or
(getDay() != getDay()[1]) then open else regularHoursOpen[1];
# First High
rec regularHoursHigh = if (secondsFromOpen >= 0 and secondsFromOpen[1] < 0) or
(getDay() != getDay()[1]) then high else regularHoursHigh[1];
# First Low
rec regularHoursLow = if (secondsFromOpen >= 0 and secondsFromOpen[1] < 0) or
(getDay() != getDay()[1]) then low else regularHoursLow[1];
rec regHoursHigh = if newDay then high else if marketOpen then
if high > regHoursHigh[1] then high else regHoursHigh[1] else high;
# Low
rec regHoursLow = if newDay then low else if marketOpen then
if low < regHoursLow[1] then low else regHoursLow[1] else low;
# First Market Open Candle
def yc = if marketOpen then yesterdaysClose else double.nan;
def o = if marketOpen then regularHoursOpen else double.nan;
# Gap up or down
def gapUp = if yc < o then 1 else 0;
def gapDown = if yc > o then 1 else 0;
# Half of gap
def hg = o + (yc - o) / 2;
def gapRemaining = if gapUp then
Max(regHoursLow - yc, 0) else
if gapDown then Max(yc - regHoursHigh, 0) else 0;
def percentRemaining = 100 * gapRemaining / AbsValue(yc - o);
def gapFilled = if percentRemaining == 0 then 1 else 0;
def halfGapFilled = if percentRemaining <= 50 then 1 else 0;
plot gH = if (gapUp and !gapFilled and marketOpen and !newDay[-1])
then regHoursLow else if (gapDown and !gapFilled and marketOpen and !newDay[-1])
then yc else double.nan;
plot gL = if (gapUp and !gapFilled and marketOpen and !newDay[-1])
then yc else if (gapDown and !gapFilled and marketOpen and !newDay[-1])
then regHoursHigh else double.nan;
plot hGF = if !gapFilled and marketOpen and !newDay[-1]
then hg else double.nan;
# Candles below half plot hGF are plotted, return 1 for gapup, return 2 for gapdown
def return1 = gL - (gL*0.001);
def return2 = gH + (gH*0.001);
# regHoursLow and regHoursHigh describes the lowest and highest candle after RTH open and before RTH close for equities
plot greaterlessGF = if regHoursLow <= hGF and GapUp then return1[1] else if regHoursHigh >= hGF and GapDown then return2[1] else double.nan;
# Coloring
gH.SetPaintingStrategy(paintingStrategy.DaSHES);
gH.AssignValueColor(if gapDown then color.darK_red else color.dark_green);
gL.SetPaintingStrategy(paintingStrategy.DASHES);
gL.AssignValueColor(if gapDown then color.darK_red else color.dark_green);
hGF.setStyle(curve.LONG_DASH);
hGF.SetDefaultColor(color.dark_gray);
AddCloud(gH, gL, color.gray, color.gray);
Last edited by a moderator: