#Experimental Time-Limited Fractal Energy
#plots only during set times
input begin_time = 0930;
input end_time = 1600;
def start = if SecondsFromTime(begin_time) >= 0 then 1 else 0;
def end = if SecondsTillTime(end_time) >= 0 then 1 else 0;
def nan = double.nan;
#Fractal Energy by Mobius
#hacked to only show during certain times and changed o/h/l/c values
input nFE = 8;
input AlertOn = no;
input Glength = 13;
input betaDev = 8;
def data1 = if start and end then open else 0;
def data2 = if start and end then high else 0;
def data3 = if start and end then low else 0;
def data4 = if start and end then close else 0;
def w = (2 * Double.Pi / Glength);
def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
def Go = Power(alpha, 4) * data1 +
4 * (1 – alpha) * Go[1] – 6 * Power( 1 - alpha, 2 ) * Go[2] +
4 * Power( 1 - alpha, 3 ) * Go[3] - Power( 1 - alpha, 4 ) * Go[4];
def Gh = Power(alpha, 4) * data2 +
4 * (1 – alpha) * Gh[1] – 6 * Power( 1 - alpha, 2 ) * Gh[2] +
4 * Power( 1 - alpha, 3 ) * Gh[3] - Power( 1 - alpha, 4 ) * Gh[4];
def Gl = Power(alpha, 4) * data3 +
4 * (1 – alpha) * Gl[1] – 6 * Power( 1 - alpha, 2 ) * Gl[2] +
4 * Power( 1 - alpha, 3 ) * Gl[3] - Power( 1 - alpha, 4 ) * Gl[4];
def Gc = Power(alpha, 4) * data4 +
4 * (1 – alpha) * Gc[1] – 6 * Power( 1 - alpha, 2 ) * Gc[2] +
4 * Power( 1 - alpha, 3 ) * Gc[3] - Power( 1 - alpha, 4 ) * Gc[4];
def o = (Go + Gc[1]) / 2;
def h = Max(Gh, Gc[1]);
def l = Min(Gl, Gc[1]);
def c = (o + h + l + Gc) / 4;
plot gamma = if start and end then Log(Sum((Max(Gh, Gc[1]) - Min(Gl, Gc[1])), nFE) /
(Highest(Gh, nFE) - Lowest(Gl, nFE)))
/ Log(nFE) else Double.NaN;
gamma.SetPaintingStrategy(PaintingStrategy.LINE);
gamma.SetLineWeight(2);
gamma.SetDefaultColor(Color.YELLOW);
plot M = if IsNaN(c) then Double.NaN else if start and end then 0.5 else nan;
M.SetPaintingStrategy(PaintingStrategy.LINE);
M.SetDefaultColor(Color.DARK_GRAY);
M.HideBubble();
M.HideTitle();
plot FEh = if IsNaN(c) then Double.NaN else if start and end then .618 else nan;
FEh.SetStyle(Curve.SHORT_DASH);
FEh.HideBubble();
FEh.SetDefaultColor(Color.GREEN);
FEh.HideTitle();
plot FEl = if IsNaN(c) then Double.NaN else if start and end then .382 else nan;
FEl.SetStyle(Curve.SHORT_DASH);
FEl.SetDefaultColor(Color.RED);
FEl.HideBubble();
FEl.HideTitle();
#end code