Magic Fib chart indicator into a scan


Category:
0
0

Hello Pete,

I have a chart indicator that is called a magic fib…I tried making a scan from the editor and never comes back with results.  I was hoping you can help with the scan..I would like results for any cross above or below….

 

declare upper;
declare hide_on_daily;
declare once_per_bar;

def vClose = close;
def nan = Double.NaN;

def showPrevClose = 0;
def showOpen = 0;

# logic
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBarOfDay = if
(afterEnd[-1] == 1 and afterEnd == 0) or
(isRollOver[-1] and firstBarOfDay[-1])
then 1
else 0;

def dayOpen = if firstBarOfDay then vClose else dayOpen[1];
def prevDayClose = if lastBarOfDay then vClose else prevDayClose[1];

# fibs
def delta = if firstBarOfDay then dayOpen – prevDayClose else delta[1];
def fib1272 = if firstBarOfDay then prevDayClose + delta * 1.272 else fib1272[1];

# colors, see https://usethinkscript.com/threads/rainbow-indicators-%E2%80%93-bb-and-moving-average.294/
#
# plots
# Plot nan on the bar before a new plot starts on firstBarOfDay.
# This causes the plot to draw without an annoying connecting line from
# one day to the next.
#
plot fib = if firstBarOfDay[-1] then nan else fib1272;
fib.SetDefaultColor(CreateColor(0,0,255));

plot pOpen = if showOpen and !firstBarOfDay[-1] then dayOpen else nan;
plot pPrevClose = if showPrevClose and !lastBarOfDay[-1] then prevDayClose else nan;
pOpen.SetDefaultColor(CreateColor(0,255,0));
pPrevClose.SetDefaultColor(CreateColor(255,0,0));

 

Thanks

Marked as spam
Posted by (Questions: 49, Answers: 42)
Asked on August 27, 2019 7:58 am
355 views
0
Private answer

You didn't include your own attempt at the scan. So I cannot comment on that to help you learn. Here is my first attempt. I have not tested this but seems to me it should work.

def vClose = close;
def nan = Double.NaN;
def showPrevClose = 0;
def showOpen = 0;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0;
def lastBarOfDay = if (afterEnd[-1] == 1 and afterEnd == 0) or (isRollOver[-1] and firstBarOfDay[-1]) then 1 else 0;
def dayOpen = if firstBarOfDay then vClose else dayOpen[1];
def prevDayClose = if lastBarOfDay then vClose else prevDayClose[1];
def delta = if firstBarOfDay then dayOpen – prevDayClose else delta[1];
def fib1272 = if firstBarOfDay then prevDayClose + delta * 1.272 else fib1272[1];
plot scan = (close[1] < fib1272[1] and close > fib1272) or (close[1] > fib1272[1] and close < fib1272);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 27, 2019 9:40 am