Auto fib based on specific time frame


Category:
0
0

So im trying to create auto fibonacci for a specific time frame. I’ll share the code below that I have pieced together which plots the exact time frames I’m look at (Open price at 730, then high and low of the rest of the premarket time ie 7;30–>9.30). This code just plots horizontal lines at open price of 7:30 and high/low 7:30–>9:30. What I’m hoping to get is auto fib of this time frame with 7:30mopen price at 100% and high/low at 0%. make sense? Also, not sure why, but my 730 line plots throughout the day (which I like), but not my high/low lines.

Thanks

 

input targetTime = 0730;

def targetBar = SecondsFromTime(targetTime) == 0;

rec targetopen = if targetBar then open else targetopen[1];

plot data = targetopen;

 

 

input marketOpen = 730;

input  marketClose = 929;

def startCounter = SecondsFromTime(marketOpen);

def endCounter = SecondsTillTime(marketClose);

def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

rec targetPeriodHigh = if targetHours and !targetHours[1] then high else if targetHours and high > targetPeriodHigh[1] then high else if targetHours then targetPeriodHigh[1] else Double.NaN;

rec targetPeriodLow = if targethours and !targetHours[1] and low > 0 then low else if targetHours and low < targetPeriodLow[1] then low else if targetHours then targetPeriodLow[1] else Double.NaN;

plot pmHigh = targetPeriodHigh;

plot pmLow = targetPeriodLow;

Marked as spam
Posted by (Questions: 6, Answers: 18)
Asked on August 14, 2019 8:47 pm
402 views
0
Private answer

This should do the trick. I have included a single Fib level. I'll leave it to you to add more as you require. Screenshot below shows the result.

input targetTime = 0730;
input fibOne = 50.0;
def targetBar = SecondsFromTime(targetTime) == 0;
rec targetopen = if targetBar then open else targetopen[1];
plot data = targetopen;
input marketOpen = 730;
input marketClose = 929;
def startCounter = SecondsFromTime(marketOpen);
def endCounter = SecondsTillTime(marketClose);
def targetHours = if startCounter >= 0 and endCounter >= 0 then 1 else 0;
rec targetPeriodHigh = if targetHours and !targetHours[1] then high else if targetHours and high > targetPeriodHigh[1] then high else targetPeriodHigh[1];
rec targetPeriodLow = if targethours and !targetHours[1] and low > 0 then low else if
targetHours and low < targetPeriodLow[1] then low else targetPeriodLow[1];
plot pmHigh = targetPeriodHigh;
plot pmLow = targetPeriodLow;
def range = if !targetHours then pmHigh - pmLow else Double.NaN;
plot fibLevelOne = if range > 0 then (range * (fibOne * 0.01)) + pmLow else Double.NaN;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on August 15, 2019 8:00 am
0
Thanks so much, ill mess with it and add some fibs.
( at August 15, 2019 9:20 am)
0
Just looking at it closer, is there a way to make the fib start at that 7:30 open bar and then trace to high or low instead of doing a fib from high to low? so fib 100% line would be 730 open bar, not high/low.
( at August 15, 2019 9:30 am)
0

So you want two fibonacci's. One for the range of high to open and another for the range of open to low? As the code is now, everything is wrapped up in that range variable:

def range = if !targetHours then pmHigh - pmLow else Double.NaN;

You can change "pmHigh - pmLow" to "pmHigh - targetOpen" or you can use "targetOpen - pmLow". If you wanted to you could split that range variable into rangeHigh and rangeLow. Then you could adjust each as I just described. This will give you two ranges from which to plot your fibonacci levels.

( at August 15, 2019 10:11 am)
0
Ok cool, i"ll play with these. Thanks!
( at August 15, 2019 10:31 am)
0
Hi Jeff, Appreciated if you can share the code of the study, if you have already added the fibs and 100% fib line as 730 open bar. Sam
( at August 20, 2019 1:24 am)