madeinnyc
Member
Is anyone here familiar with the process of back-testing this study on the /ES 5 Min Chart, where results are only reflective of cash market trading hours? Any guidance is appreciated!
Here's the code:
Here's the code:
Code:
# User Inputs
input agg = aggregationPeriod.Four_Min;
input Length = 5; #hint Length: Length for calculations.
input Value = .618;
input MeanValue = HL2; #hint MeanValue: Point of origen.
input PointWeight = 3;
input PointColor = 4;
script g {
input length = 10;
input betaDev = 20;
input data = close;
def w = (2 * Double.Pi / length);
def beta = (1 - Cos(w)) / (Power(1.414, 2.0 / betaDev) - 1 );
def alpha = (-beta + Sqrt(beta * beta + 2 * beta));
def G = Power(alpha, 4) * data +
4 * (1 – alpha) * G[1] – 6 * Power( 1 - alpha, 2 ) * G[2] +
4 * Power( 1 - alpha, 3 ) * G[3] - Power( 1 - alpha, 4 ) * G[4];
plot Line = G;
}
def o = g(data = open(period = agg));
def h = g(data = high(period = agg));
def l = g(data = low(period = agg));
def c = g(data = close(period = agg));
def bar = barNumber();
def TR = Max(h, c[1]) - Min(l, c[1]);
def R = Highest(h, Length) - Lowest(l, Length);
def F = Log(Sum(TR, Length) / R) / Log(Length);
def M = if F crosses above Value
then MeanValue
else if F > Value and F > F[1]
then M[1]
else M[1];
def S = F > Value and F > F[1];
def StartBar = if F crosses above Value
then bar
else double.nan;
def Flag_High;
def Flag_Low;
if F crosses above Value
{
Flag_High = h;
Flag_Low = l;
}
else if S and h > Flag_High[1]
{
Flag_High = h;
Flag_Low = Flag_Low[1];
}
else if S and l < Flag_Low[1]
{
Flag_High = Flag_High[1];
Flag_Low = l;
}
else
{
Flag_High = Flag_High[1];
Flag_Low = Flag_Low[1];
}
# Plots
plot mean = if F crosses above Value
then m
else if F > Value
then m
else double.nan;
mean.SetStyle(Curve.Points);
mean.SetDefaultColor(GetColor(PointColor));
mean.SetLineWeight(PointWeight);
plot Flag_Mean = if bar >= HighestAll(StartBar)
then HighestAll(if isNaN(close[-1])
then M
else double.nan)
else double.nan;
Flag_Mean.SetDefaultColor(Color.CYAN);
plot Flag_High_Line = if bar >= HighestAll(StartBar)
then HighestAll(if isNaN(close[-1])
then Round(Flag_High/TickSize(), 0)*TickSize()
else double.nan)
else double.nan;
Flag_High_Line.SetDefaultColor(Color.Green);
plot Flag_Low_Line = if bar >= HighestAll(StartBar)
then HighestAll(if isNaN(close[-1])
then Round(Flag_Low/TickSize(), 0)*TickSize()
else double.nan)
else double.nan;
Flag_Low_Line.SetDefaultColor(Color.Red);
AddCloud(Flag_Mean, Flag_High_Line, CreateColor(50, 150, 75), CreateColor(50, 150, 70));
AddCloud(Flag_Low_Line, Flag_Mean, CreateColor(175, 0, 50), CreateColor(175, 0, 50));
def FHL = if !isNaN(Flag_High_Line)
then Flag_High
else FHL[1];
def FLL = if !isNaN(Flag_Low_Line)
then Flag_Low
else FLL[1];
def ColorSwitch;
if h > Flag_High
{
ColorSwitch = 1;
}
else if l < Flag_Low
{
ColorSwitch = -1;
}
else
{
ColorSwitch = 0;
}
AssignPriceColor(if ColorSwitch == 1
then color.green
else if ColorSwitch == -1
then color.red
else color.yellow);
def ChartAgg = getAggregationPeriod();
Addlabel(1, "Flag Study at: " + (agg /1000/60) + "min agg" +
" Chart Agg: " + (ChartAgg/1000/60) +
" Energy Level = " + AsPercent(F),
if ColorSwitch == 1
then color.green
else if ColorSwitch == -1
then color.red
else color.yellow);
#End Code ECI or Flags
Last edited by a moderator: