قديم 04-12-2016, 12:08 AM
  المشاركه #1

عضو هوامير المميز

تاريخ التسجيل: Mar 2011
المشاركات: 47
ثلاثيني متهور غير متواجد حالياً  

الله يجزاه الجنه من يساعد ني في تصحيحها لان كثير من المعادلات نفس المشكله

_SECTION_BEGIN("Advanced Trend Lines");
function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 1.5, 0.01, 100. ,0.01);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes");
Lines = Param("Lines?", 1, 1, BarCount-2);
DrawR = ParamList("Resistance Points", "Off|High to High|High to Low", 1);
DrawS = ParamList("Support Points", "Off|Low to Low|Low to High", 1);
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1);
AllOrDownR = ParamToggle("Resistance ection", "All|Down");
AllOrUpS = ParamToggle("Support ection", "All|Up");
ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer = Param("S/R Percentage", 3, 1);
SRBack = Param("S/R Back", 5, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}

if(ShowTDP)

if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);
x0 = GetXResistance(H, SRPer, i);
y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);

}
}
Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+", Close: "+C+StrFormat(" (%.2f %.2f\%)", C-Ref(C, -1), SelectedValue(ROC(C, 1)))+str;

_SECTION_END();


_SECTION_BEGIN("Specific parameters I");
TopShape = Param("Top Fractal typ",5,0,50,1);
Topshapecolor = ParamColor("Top Fractal color",colorRed);
ValleyShape = Param("Bottom Fractal typ",6,0,50,1);
Valleyshapecolor = ParamColor("Bottom Fractal color",colorLime);
SRplot = ParamToggle("S/R plot","Off,On",1);
_SECTION_END();
_SECTION_BEGIN("Specific parameters II");
Sswitch = ParamToggle("Swing chart","On,Off",1);
Shswitch = ParamToggle("Swing shapes","On,Off",1);
PC = Param("Sensitivity",5,0.1,30,0.1);
Swingcolor = ParamColor("Swing line color",colorLime);
Swingstyle = ParamStyle("Swing line style",styleLine|styleThick,maskDefault);
SLC = ParamColor("Swing low",colorPaleGreen);
SHC = ParamColor("Swing high",colorLightOrange);
_SECTION_END();

#pragma nocache

Hp1 = Ref(H,-1);Hp2 = Ref(H,-2);Hp3 = Ref(H,-3);Hp4 = Ref(H,-4);Hp5 = Ref(H,-5);Hp6 = Ref(H,-6);
Lp1 = Ref(L,-1);Lp2 = Ref(L,-2);Lp3 = Ref(L,-3);Lp4 = Ref(L,-4);Lp5 = Ref(L,-5);Lp6 = Ref(L,-6);
Hf1 = Ref(H,1);Hf2 = Ref(H,2);Hf3 = Ref(H,3);Hf4 = Ref(H,4);Hf5 = Ref(H,5);Hf6 = Ref(H,6);
Lf1 = Ref(L,1);Lf2 = Ref(L,2);Lf3 = Ref(L,3);Lf4 = Ref(L,4);Lf5 = Ref(L,5);Lf6 = Ref(L,6);

x = Cum(1);
divx = LastValue(x)-x;

//Tops
A = H;
Top1 = A > Hf2 & A > Hf1 & A > Hp1 & A > Hp2 & divx>2;
Top2 = A > Hf3 & A > Hf2 & A ==Hf1 & A > Hp1 & A > Hp2 & divx>3 ;
Top3 = A > Hf4 & A > Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>4;
Top4 = A > Hf5 & A > Hf4 & A ==Hf3 & A >=Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>5;
Top5 = A > Hf6 & A > Hf5 & A ==Hf4 & A >=Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A >Hp2 & divx>6;
Top = Top1 OR Top2 OR Top3 OR Top4 OR Top5;
TopHigh = ValueWhen(Top,H);
TopX = ValueWhen(Top,X);
x_lasttop = LastValue(ValueWhen(top,x,1));

//Valleys
A = L;
Valley1 = A < Lf2 & A <= Lf1 & A <= Lp1 & A < Lp2 & divx>2;
Valley2 = A < Lf3 & A < Lf2 & A == Lf1 & A < Lp1 & A < Lp2 & divx>3;
Valley3 = A < Lf4 & A < Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>4;
Valley4 = A < Lf5 & A < Lf4 & A == Lf3 & A <= Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>5;
Valley5 = A < Lf6 & A < Lf5 & A == Lf4 & A <= Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>6;
Valley = Valley1 OR Valley2 OR Valley3 OR Valley4 OR Valley4 OR Valley5;
ValleyLow = ValueWhen(Valley,L);
ValleyX = ValueWhen(Valley,X);
x_lastvalley = LastValue(ValueWhen(Valley,x,1));


Plot(IIf(SRplot & x>= x_lasttop,LastValue(ValueWhen(top,H,1)),Null),"",Topshapecolor,1);
Plot(IIf(SRplot & x>= x_lastvalley,LastValue(ValueWhen(Valley,L,1)),Null),"",Valleyshapecolor,1);

Distance = 0.5*ATR(14);
//Support line signals
Sup_break = Cross(ValleyLow,C) & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;
Sup_pricejustabove = L<ValleyLow+Distance & L>ValleyLow & LowestSince(Ref(Valley,-1),Low,1)>ValleyLow & X-ValleyX >6;
Sup_confirmed = L<=ValleyLow & C>ValleyLow & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;

//Resistance line signals
Res_break = Cross(C,TopHigh) & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-TopX >6;
Res_pricejustbelow = H>TopHigh-Distance & H<TopHigh & HighestSince(Ref(Top,-1),High)<TopHigh & X-ValleyX >6;
Res_confirmed = H>=TopHigh & C<TopHigh & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-ValleyX >6;

SupSignals = Sup_break | Sup_pricejustabove | Sup_confirmed;
ResSignals = Res_break | Res_pricejustbelow | Res_confirmed;

Filter = SupSignals OR ResSignals OR 1;
AddColumn(C,"Close");
AddTextColumn(
WriteIf(Sup_pricejustabove,"price just above",
WriteIf(Sup_confirmed,"confirmed",
WriteIf(Sup_break,"break",""))),"Support",1.2,
IIf(Sup_pricejustabove OR sup_confirmed,colorGreen,colorRed));

AddTextColumn(
WriteIf(Res_pricejustbelow,"price just below",
WriteIf(Res_confirmed,"confirmed",
WriteIf(Res_break,"break",""))),"Resistance",1.2,
IIf(Res_pricejustbelow OR Res_confirmed,colorRed,colorGreen));

ZZ = Zig(C,LastValue(PC));
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotLow), SLC,0, L, -35) ;
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotHigh),SHC,0,H, 35) ;
Plot(IIf(Sswitch,-1e10,ZZ)," ",Swingcolor,Swingstyle + styleNoTitle);
/*
Lfs = LastValue(ValueWhen(Valley,L,1));
Lfr = LastValue(ValueWhen(top,H,1));
AddColumn(((((Lfr - Lfs)/(C))*100)), "%-Break" , 2.2);
AddTextColumn(FullName(),"Full name");
*/

SetChartOptions(0,chartShowDates);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

الموضوع الأصلي : اضغط هنا    ||   المصدر : منتدى هوامير البورصة السعودية


رد مع اقتباس
 
 

قديم 04-12-2016, 12:36 AM
  المشاركه #2

عضو هوامير المميز

تاريخ التسجيل: Apr 2012
المشاركات: 223
amm1430 غير متواجد حالياً  

_SECTION_BEGIN("Advanced Trend Lines");
function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 1.5, 0.01, 100. ,0.01);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes");
Lines = Param("Lines?", 1, 1, BarCount-2);
DrawR = ParamList("Resistance Points", "Off|High to High|High to Low", 1);
DrawS = ParamList("Support Points", "Off|Low to Low|Low to High", 1);
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1);
AllOrDownR = ParamToggle("Resistance ection", "All|Down");
AllOrUpS = ParamToggle("Support ection", "All|Up");
ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer = Param("S/R Percentage", 3, 1);
SRBack = Param("S/R Back", 5, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}

if(ShowTDP)

if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);
x0 = GetXResistance(H, SRPer, i);
y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);

}
}

_SECTION_END();


_SECTION_BEGIN("Specific parameters I");
TopShape = Param("Top Fractal typ",5,0,50,1);
Topshapecolor = ParamColor("Top Fractal color",colorRed);
ValleyShape = Param("Bottom Fractal typ",6,0,50,1);
Valleyshapecolor = ParamColor("Bottom Fractal color",colorLime);
SRplot = ParamToggle("S/R plot","Off,On",1);
_SECTION_END();
_SECTION_BEGIN("Specific parameters II");
Sswitch = ParamToggle("Swing chart","On,Off",1);
Shswitch = ParamToggle("Swing shapes","On,Off",1);
PC = Param("Sensitivity",5,0.1,30,0.1);
Swingcolor = ParamColor("Swing line color",colorLime);
Swingstyle = ParamStyle("Swing line style",styleLine|styleThick,maskDefault);
SLC = ParamColor("Swing low",colorPaleGreen);
SHC = ParamColor("Swing high",colorLightOrange);
_SECTION_END();

#pragma nocache

Hp1 = Ref(H,-1);Hp2 = Ref(H,-2);Hp3 = Ref(H,-3);Hp4 = Ref(H,-4);Hp5 = Ref(H,-5);Hp6 = Ref(H,-6);
Lp1 = Ref(L,-1);Lp2 = Ref(L,-2);Lp3 = Ref(L,-3);Lp4 = Ref(L,-4);Lp5 = Ref(L,-5);Lp6 = Ref(L,-6);
Hf1 = Ref(H,1);Hf2 = Ref(H,2);Hf3 = Ref(H,3);Hf4 = Ref(H,4);Hf5 = Ref(H,5);Hf6 = Ref(H,6);
Lf1 = Ref(L,1);Lf2 = Ref(L,2);Lf3 = Ref(L,3);Lf4 = Ref(L,4);Lf5 = Ref(L,5);Lf6 = Ref(L,6);

x = Cum(1);
divx = LastValue(x)-x;

//Tops
A = H;
Top1 = A > Hf2 & A > Hf1 & A > Hp1 & A > Hp2 & divx>2;
Top2 = A > Hf3 & A > Hf2 & A ==Hf1 & A > Hp1 & A > Hp2 & divx>3 ;
Top3 = A > Hf4 & A > Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>4;
Top4 = A > Hf5 & A > Hf4 & A ==Hf3 & A >=Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>5;
Top5 = A > Hf6 & A > Hf5 & A ==Hf4 & A >=Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A >Hp2 & divx>6;
Top = Top1 OR Top2 OR Top3 OR Top4 OR Top5;
TopHigh = ValueWhen(Top,H);
TopX = ValueWhen(Top,X);
x_lasttop = LastValue(ValueWhen(top,x,1));

//Valleys
A = L;
Valley1 = A < Lf2 & A <= Lf1 & A <= Lp1 & A < Lp2 & divx>2;
Valley2 = A < Lf3 & A < Lf2 & A == Lf1 & A < Lp1 & A < Lp2 & divx>3;
Valley3 = A < Lf4 & A < Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>4;
Valley4 = A < Lf5 & A < Lf4 & A == Lf3 & A <= Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>5;
Valley5 = A < Lf6 & A < Lf5 & A == Lf4 & A <= Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>6;
Valley = Valley1 OR Valley2 OR Valley3 OR Valley4 OR Valley4 OR Valley5;
ValleyLow = ValueWhen(Valley,L);
ValleyX = ValueWhen(Valley,X);
x_lastvalley = LastValue(ValueWhen(Valley,x,1));


Plot(IIf(SRplot & x>= x_lasttop,LastValue(ValueWhen(top,H,1)),Null),"",Topshapecolor,1);
Plot(IIf(SRplot & x>= x_lastvalley,LastValue(ValueWhen(Valley,L,1)),Null),"",Valleyshapecolor,1);

Distance = 0.5*ATR(14);
//Support line signals
Sup_break = Cross(ValleyLow,C) & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;
Sup_pricejustabove = L<ValleyLow+Distance & L>ValleyLow & LowestSince(Ref(Valley,-1),Low,1)>ValleyLow & X-ValleyX >6;
Sup_confirmed = L<=ValleyLow & C>ValleyLow & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;

//Resistance line signals
Res_break = Cross(C,TopHigh) & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-TopX >6;
Res_pricejustbelow = H>TopHigh-Distance & H<TopHigh & HighestSince(Ref(Top,-1),High)<TopHigh & X-ValleyX >6;
Res_confirmed = H>=TopHigh & C<TopHigh & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-ValleyX >6;

SupSignals = Sup_break | Sup_pricejustabove | Sup_confirmed;
ResSignals = Res_break | Res_pricejustbelow | Res_confirmed;

Filter = SupSignals OR ResSignals OR 1;
AddColumn(C,"Close");
AddTextColumn(
WriteIf(Sup_pricejustabove,"price just above",
WriteIf(Sup_confirmed,"confirmed",
WriteIf(Sup_break,"break",""))),"Support",1.2,
IIf(Sup_pricejustabove OR sup_confirmed,colorGreen,colorRed));

AddTextColumn(
WriteIf(Res_pricejustbelow,"price just below",
WriteIf(Res_confirmed,"confirmed",
WriteIf(Res_break,"break",""))),"Resistance",1.2,
IIf(Res_pricejustbelow OR Res_confirmed,colorRed,colorGreen));

ZZ = Zig(C,LastValue(PC));
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotLow), SLC,0, L, -35) ;
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotHigh),SHC,0,H, 35) ;
Plot(IIf(Sswitch,-1e10,ZZ)," ",Swingcolor,Swingstyle + styleNoTitle);
/*
Lfs = LastValue(ValueWhen(Valley,L,1));
Lfr = LastValue(ValueWhen(top,H,1));
AddColumn(((((Lfr - Lfs)/(C))*100)), "%-Break" , 2.2);
AddTextColumn(FullName(),"Full name");
*/

SetChartOptions(0,chartShowDates);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();



رد مع اقتباس
قديم 04-12-2016, 01:49 AM
  المشاركه #3

عضو هوامير المميز

تاريخ التسجيل: Mar 2011
المشاركات: 47
ثلاثيني متهور غير متواجد حالياً  

اقتباس:
المشاركة الأصلية كتبت بواسطة amm1430 مشاهدة المشاركة
_section_begin("advanced trend lines");
function getxsupport(lo, percentage, back)
{
return ((barcount - 1) - lastvalue(troughbars(lo, percentage,back)));
}
function getysupport(lo, percentage, back)
{
return (lastvalue(trough(lo, percentage, back)));
}

function getxresistance(hi, percentage, back)
{
return ((barcount - 1) -lastvalue(peakbars(hi, percentage, back)));
}
function getyresistance(hi, percentage, back)
{
return (lastvalue(peak(hi, percentage, back)));
}
function td_supply(p)
{
return ( p > ref(p, 1) and p > ref(p, -1) and p > ref(c, -2));
}
function td_demand(p)
{
return ( p < ref(p, 1) and p < ref(p, -1) and p < ref(c, -2));
}
////////////////////////////////////////////////////////////////////////
//parameters
percentage = param("percentage", 1.5, 0.01, 100. ,0.01);
drawalllines = paramtoggle("draw all lines?", "no|yes");
lines = param("lines?", 1, 1, barcount-2);
drawr = paramlist("resistance points", "off|high to high|high to low", 1);
draws = paramlist("support points", "off|low to low|low to high", 1);
showtdp = paramtoggle("show td pionts", "no|yes", 1);
allordownr = paramtoggle("resistance ection", "all|down");
allorups = paramtoggle("support ection", "all|up");
showsr = paramtoggle("show vert s/r","no|yes", 1);
srper = param("s/r percentage", 3, 1);
srback = param("s/r back", 5, 1);
str = "";
res = sup = 0;
con = 1;
////////////////////////////////////////////////////////////////////////
main = c;
con = cons = conr = 1;
if(draws=="low to low")
{
support1 = l;
support2 = l;
}
else
{
support1 = l;
support2 = h;
}
if(drawr=="high to high")
{
resistance1 = h;
resistance2 = h;
}
else
{
resistance1 = h;
resistance2 = l;
}
////////////////////////////////////////////////////////////////////////
//plotting area
if(drawalllines)
for(i = 2; i<=lines+1; i++)
{
if(draws!="off")
{
x0 = getxsupport(support1, percentage, i);
x1 = getxsupport(support2, percentage, i-1);
y0 = getysupport(support1, percentage, i);
y1 = getysupport(support2, percentage, i-1);
x = linearray(x0, y0, x1, y1, 1);
if(allorups) cons = strtonum(numtostr(y0 < y1));
if(con and cons)
plot(x, "", iif(lastvalue(c) < lastvalue(x), colorblue,colorlightblue), styleline|stylethick);
}
if(drawr!="off")
{
x0 = getxresistance(resistance1, percentage, i);
x1 = getxresistance(resistance2, percentage, i-1);
y0 = getyresistance(resistance1, percentage, i);
y1 = getyresistance(resistance2, percentage, i-1);
x = linearray(x0, y0, x1, y1, 1);
if(allordownr) conr = y0 > y1;
if(con and conr)
plot(x, "", iif(lastvalue(c) < lastvalue(x), colorblue,colorlightblue), styleline|stylethick);
}
}
else
{
if(draws!="off")
{
x0 = getxsupport(support1, percentage, lines+1);
x1 = getxsupport(support2, percentage, lines);
y0 = getysupport(support1, percentage, lines+1);
y1 = getysupport(support2, percentage, lines);
x = linearray(x0, y0, x1, y1, 1 );
sup = lastvalue(linregslope(x, lines+1));
if(allorups) cons = y0 < y1;
if(con and cons)
plot(x, "", iif(lastvalue(c) < lastvalue(x), colorblue,colorlightblue), styleline|stylethick);
}
if(drawr!="off")
{
x0 = getxresistance(resistance1, percentage, lines+1);
x1 = getxresistance(resistance2, percentage, lines);
y0 = getyresistance(resistance1, percentage, lines+1);
y1 = getyresistance(resistance2, percentage, lines);
x = linearray(x0, y0, x1, y1, 1 );
res = lastvalue(linregslope(x, lines+1));
if(allordownr) conr = y0 > y1;
if(con and conr)
plot(x, "", iif(lastvalue(c) < lastvalue(x), colorblue,colorlightblue), styleline|stylethick);
}
str = "\nr slope=("+res+"), s slope=("+sup+")";
}

if(showtdp)

if(showsr)
{
for(i=1; i<=srback; i++)
{
x0 = getxsupport(l, srper, i);
x1 = barcount-1;
y0 = getysupport(l, srper, i);
x = linearray(x0, y0, x1, y0, 0);
plot(x, "", iif(lastvalue(c) > x, colordarkgreen, colordarkred), styleline|styledashed|stylethick);
x0 = getxresistance(h, srper, i);
y0 = getyresistance(h, srper, i);
x = linearray(x0, y0, x1, y0, 0);
plot(x, "", iif(lastvalue(c) > x, colordarkgreen, colordarkred), styleline|styledashed|stylethick);

}
}

_section_end();


_section_begin("specific parameters i");
topshape = param("top fractal typ",5,0,50,1);
topshapecolor = paramcolor("top fractal color",colorred);
valleyshape = param("bottom fractal typ",6,0,50,1);
valleyshapecolor = paramcolor("bottom fractal color",colorlime);
srplot = paramtoggle("s/r plot","off,on",1);
_section_end();
_section_begin("specific parameters ii");
sswitch = paramtoggle("swing chart","on,off",1);
shswitch = paramtoggle("swing shapes","on,off",1);
pc = param("sensitivity",5,0.1,30,0.1);
swingcolor = paramcolor("swing line color",colorlime);
swingstyle = paramstyle("swing line style",styleline|stylethick,maskdefault);
slc = paramcolor("swing low",colorpalegreen);
shc = paramcolor("swing high",colorlightorange);
_section_end();

#pragma nocache

hp1 = ref(h,-1);hp2 = ref(h,-2);hp3 = ref(h,-3);hp4 = ref(h,-4);hp5 = ref(h,-5);hp6 = ref(h,-6);
lp1 = ref(l,-1);lp2 = ref(l,-2);lp3 = ref(l,-3);lp4 = ref(l,-4);lp5 = ref(l,-5);lp6 = ref(l,-6);
hf1 = ref(h,1);hf2 = ref(h,2);hf3 = ref(h,3);hf4 = ref(h,4);hf5 = ref(h,5);hf6 = ref(h,6);
lf1 = ref(l,1);lf2 = ref(l,2);lf3 = ref(l,3);lf4 = ref(l,4);lf5 = ref(l,5);lf6 = ref(l,6);

x = cum(1);
divx = lastvalue(x)-x;

//tops
a = h;
top1 = a > hf2 & a > hf1 & a > hp1 & a > hp2 & divx>2;
top2 = a > hf3 & a > hf2 & a ==hf1 & a > hp1 & a > hp2 & divx>3 ;
top3 = a > hf4 & a > hf3 & a ==hf2 & a >=hf1 & a > hp1 & a > hp2 & divx>4;
top4 = a > hf5 & a > hf4 & a ==hf3 & a >=hf2 & a >=hf1 & a > hp1 & a > hp2 & divx>5;
top5 = a > hf6 & a > hf5 & a ==hf4 & a >=hf3 & a ==hf2 & a >=hf1 & a > hp1 & a >hp2 & divx>6;
top = top1 or top2 or top3 or top4 or top5;
tophigh = valuewhen(top,h);
topx = valuewhen(top,x);
x_lasttop = lastvalue(valuewhen(top,x,1));

//valleys
a = l;
valley1 = a < lf2 & a <= lf1 & a <= lp1 & a < lp2 & divx>2;
valley2 = a < lf3 & a < lf2 & a == lf1 & a < lp1 & a < lp2 & divx>3;
valley3 = a < lf4 & a < lf3 & a == lf2 & a <= lf1 & a < lp1 & a < lp2 & divx>4;
valley4 = a < lf5 & a < lf4 & a == lf3 & a <= lf2 & a <= lf1 & a < lp1 & a < lp2 & divx>5;
valley5 = a < lf6 & a < lf5 & a == lf4 & a <= lf3 & a == lf2 & a <= lf1 & a < lp1 & a < lp2 & divx>6;
valley = valley1 or valley2 or valley3 or valley4 or valley4 or valley5;
valleylow = valuewhen(valley,l);
valleyx = valuewhen(valley,x);
x_lastvalley = lastvalue(valuewhen(valley,x,1));


plot(iif(srplot & x>= x_lasttop,lastvalue(valuewhen(top,h,1)),null),"",topshapecolor,1);
plot(iif(srplot & x>= x_lastvalley,lastvalue(valuewhen(valley,l,1)),null),"",valleyshapecolor,1);

distance = 0.5*atr(14);
//support line signals
sup_break = cross(valleylow,c) & ref(lowestsince(ref(valley,-1),low)>valleylow,-1) & x-valleyx >6;
sup_pricejustabove = l<valleylow+distance & l>valleylow & lowestsince(ref(valley,-1),low,1)>valleylow & x-valleyx >6;
sup_confirmed = l<=valleylow & c>valleylow & ref(lowestsince(ref(valley,-1),low)>valleylow,-1) & x-valleyx >6;

//resistance line signals
res_break = cross(c,tophigh) & ref(highestsince(ref(top,-1),high)<tophigh,-1) & x-topx >6;
res_pricejustbelow = h>tophigh-distance & h<tophigh & highestsince(ref(top,-1),high)<tophigh & x-valleyx >6;
res_confirmed = h>=tophigh & c<tophigh & ref(highestsince(ref(top,-1),high)<tophigh,-1) & x-valleyx >6;

supsignals = sup_break | sup_pricejustabove | sup_confirmed;
ressignals = res_break | res_pricejustbelow | res_confirmed;

filter = supsignals or ressignals or 1;
addcolumn(c,"close");
addtextcolumn(
writeif(sup_pricejustabove,"price just above",
writeif(sup_confirmed,"confirmed",
writeif(sup_break,"break",""))),"support",1.2,
iif(sup_pricejustabove or sup_confirmed,colorgreen,colorred));

addtextcolumn(
writeif(res_pricejustbelow,"price just below",
writeif(res_confirmed,"confirmed",
writeif(res_break,"break",""))),"resistance",1.2,
iif(res_pricejustbelow or res_confirmed,colorred,colorgreen));

zz = zig(c,lastvalue(pc));
pivotlow = ref(iif(ref(roc(zz,1),-1) < 0 and roc(zz,1) > 0, 1, null),1);
pivothigh = ref(iif(ref(roc(zz,1),-1) > 0 and roc(zz,1) < 0, 1, null),1);
plotshapes(iif(shswitch,0,shapecircle*pivotlow), slc,0, l, -35) ;
plotshapes(iif(shswitch,0,shapecircle*pivothigh),shc,0,h, 35) ;
plot(iif(sswitch,-1e10,zz)," ",swingcolor,swingstyle + stylenotitle);
/*
lfs = lastvalue(valuewhen(valley,l,1));
lfr = lastvalue(valuewhen(top,h,1));
addcolumn(((((lfr - lfs)/(c))*100)), "%-break" , 2.2);
addtextcolumn(fullname(),"full name");
*/

setchartoptions(0,chartshowdates);

_section_begin("price");
setchartoptions(0,chartshowarrows|chartshowdates);
_n(title = strformat("{{name}} - {{interval}} {{date}} open %g, hi %g, lo %g, close %g (%.1f%%) {{values}}", o, h, l, c, selectedvalue( roc( c, 1 ) ) ));
plot( c, "close", paramcolor("color", colorblack ), stylenotitle | paramstyle("style") | getpricestyle() );
_section_end();
بيض الله وجهك ورحم الله والدينك
اذا تسمح لي اعطيك تقريبا 4 معادلات تضبطها



رد مع اقتباس
قديم 04-12-2016, 01:53 AM
  المشاركه #4

عضو هوامير المميز

تاريخ التسجيل: Mar 2011
المشاركات: 47
ثلاثيني متهور غير متواجد حالياً  

هذا رابط المعادلة الثانية فيها مشكله ايضا
http://upload.hawamer.com/d.php?hash...O6KN7S3MLEK8PE



رد مع اقتباس
قديم 04-12-2016, 10:03 PM
  المشاركه #5

عضو هوامير المميز

تاريخ التسجيل: Apr 2012
المشاركات: 223
amm1430 غير متواجد حالياً  

http://upload.hawamer.com/d.php?hash...8TBUEXWXBCYEXE


رد مع اقتباس
قديم 04-12-2016, 11:46 PM
  المشاركه #6

عضو هوامير المميز

تاريخ التسجيل: Sep 2014
المشاركات: 102
adel828 غير متواجد حالياً  

اذا ماعليك امر ياليت تعدل الخطا بالمعادلة التالية مع الشكر والتقدير

************************************************** ****
/*Ergodic Oscillator */

/*Coded by Prakash Shenoi */
SetChartBkColor(64);
x=Param(" Average 1",11,2,32);
y=Param(" Average 2",4,3,12);
erg=(EMA(EMA(C-O,x),y)/EMA(EMA(H-L,x),y))*100;
Sg=EMA(erg,5);
Plot (erg,"Ergodic Oscillator ",colorBrightGreen,styleLine,1);
Plot (Sg,"Signal",colorRed,styleLine,1);
GraphXSpace=3;

//K = 100*(C-L)/(H-L)
ergRV=(EMA(EMA(C-L,x),y)/EMA(EMA(H-L,x),y))*100;
SgRV=EMA(ergRV,5);
K = 100*(C-L)/(H-L);
//Plot(K,"K",colorBlue,styleLine);

AB = C-L; CD = H-L;




Plot( 2, /* defines the height of the ribbon in percent of pane width */"erg-sig ribbon",
IIf( erg>Sg, colorGreen, IIf( erg<Sg, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

************************************************** ******
//------------------------------------------------------------------------------
//
// Formula Name: Momentum
// Author/Uploader: ali
// E-mail: (تم حذف الإيميل لأن عرضه مخالف لشروط المنتدى)
// Date/Time Added: 2006-09-28 18:10:13
// Origin: Momentum
// Keywords: Momentum .afl
// Level: basic
// Flags: exploration
// Formula URL: http://www.amibroker.com/library/formula.php?id=723
// Details URL: AmiBroker - AFL Library
//
//------------------------------------------------------------------------------
//
// Momentum .afl
//
//------------------------------------------------------------------------------

/* Bernstein Momentum Indicator */
/* Set Scaling to Automatic, Show dates On, Percent On, Middle On */
SetChartBkColor(64);
Title = "Bernstein MOM Close - Ref(Close,-7)";
GraphXSpace = 5;
Graph0 = MA(Close - Ref(Close,-7),1);
Graph0Style = 5;
Graph0Color = 34;
Graph1 = MA(Graph0,5);
Graph1Style = 1;
Graph1Color = 32;

//add speed Calculation

// Speed calculation
Speed = abs( C - Ref( C, -1 ) );
// SpeedUp is boolean, which is true when speed increases
SpeedUp = Speed > Ref( Speed, -1 );
SpeedDown = Speed < Ref( Speed, -1 );

************************************************** ********

//Dynamic Momentum Index Tushar Chande Translated to AFL by Jayson Casavant
//Cmo5 formula
CMO5_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,5 ) ;
CMO5_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,5 );
CMO5=DEMA(100 * Nz(( CMO5_1 -CMO5_2) /( CMO5_1+CMO5_2)),3);

//Cmo10 formula
CMO10_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,10 ) ;
CMO10_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,10 );
CMO10=DEMA(100 * Nz(( CMO10_1 -CMO10_2) /( CMO10_1+CMO10_2)),3);

//Cmo20 formula
CMO20_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,20 ) ;
CMO20_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,20 );
CMO20=DEMA(100 * Nz(( CMO20_1 -CMO20_2) /( CMO20_1+CMO20_2)),3);

// dmi formula
dmi=((StDev(C,5)* CMO5)+(StDev(C,10)* CMO10)+(StDev(C,20)*
CMO20))/(StDev(C,5)+StDev(C,10)+StDev(C,20));
pds=Param("Smoothing",3,1,10,1);
pds1=Param("Trigger Line",5,1,10,1);

Plot(EMA(dmi,pds),"Dynamic Momentum Index",colorRed,1);
Plot(MA(dmi,pds1),"trigger",colorGreen,1);

Buy=Cross(EMA(dmi,pds),MA(dmi,pds1));
Sell=Cross(MA(dmi,pds1),EMA(dmi,pds));
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colo rRed);
PlotGrid(70,colorRed);
PlotGrid(30,colorBrightGreen);
************************************************** *****

// JJ says Ergodic is a better way to measure momentum than just using last price momentum, its more reflective of both long AND Short term momentum

//speed
// Base trading system
Buy = Cross( C, MA( C, 10 ) );
Sell = Cross( MA( C, 5 ), C );
Short = Cross( MA( C, 10 ), C );
Cover = Cross( C, MA( C, 5 ) );
// Speed calculation
Speed = abs( C - Ref( C, -1 ) );
// SpeedUp is boolean, which is true when speed increases
SpeedUp = Speed > Ref( Speed, -1 );
SpeedDown = Speed < Ref( Speed, -1 );
// these statements modify trading system rules
// to enter long/short only when speed increases
// (hypothesis 1)
Buy = Buy AND SpeedUp;
Short = Short AND SpeedUp;
//Plot(MA(C,5),"MA(C,5)",colorBlue,styleOwnScale,sty leThick);

//Plot(MA(C,10),"MA(C,10)",colorRed,styleOwnScale,st yleThick);

Plot(Speed,"Speed",colorViolet,styleDots);
//Plot(0,"ZERO",colorRed,styleDots);
//Plot(EMA(Speed,3),"emaspeed3",colorRed,styleLine);
//Plot(SpeedUp,"speedup",colorBlack,styleLine);
//Plot(SpeedDown,"speedDN",colorRed,styleLine);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

************************************************** *****



رد مع اقتباس
قديم 05-12-2016, 08:22 AM
  المشاركه #7

عضو هوامير المميز

تاريخ التسجيل: Apr 2012
المشاركات: 223
amm1430 غير متواجد حالياً  

/*Ergodic Oscillator */

/*Coded by Prakash Shenoi */
SetChartBkColor(64);
x=Param(" Average 1",11,2,32);
y=Param(" Average 2",4,3,12);
erg=(EMA(EMA(C-O,x),y)/EMA(EMA(H-L,x),y))*100;
Sg=EMA(erg,5);
Plot (erg,"Ergodic Oscillator ",colorBrightGreen,styleLine,1);
Plot (Sg,"Signal",colorRed,styleLine,1);
GraphXSpace=3;

//K = 100*(C-L)/(H-L)
ergRV=(EMA(EMA(C-L,x),y)/EMA(EMA(H-L,x),y))*100;
SgRV=EMA(ergRV,5);
K = 100*(C-L)/(H-L);
//Plot(K,"K",colorBlue,styleLine);

AB = C-L; CD = H-L;




Plot( 2, /* defines the height of the ribbon in percent of pane width */"erg-sig ribbon",
IIf( erg>Sg, colorGreen, IIf( erg<Sg, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

//------------------------------------------------------------------------------
//
// Formula Name: Momentum
// Author/Uploader: ali
// E-mail: (E? ??? C?????? ??? ???? ?IC?? ?O??? C???EI?)
// Date/Time Added: 2006-09-28 18:10:13
// Origin: Momentum
// Keywords: Momentum .afl
// Level: basic
// Flags: exploration
// Formula URL: http://www.amibroker.com/library/formula.php?id=723
// Details URL: AmiBroker - AFL Library
//
//------------------------------------------------------------------------------
//
// Momentum .afl
//
//------------------------------------------------------------------------------

/* Bernstein Momentum Indicator */
/* Set Scaling to Automatic, Show dates On, Percent On, Middle On */
SetChartBkColor(64);
Title = "Bernstein MOM Close - Ref(Close,-7)";
GraphXSpace = 5;
Graph0 = MA(Close - Ref(Close,-7),1);
Graph0Style = 5;
Graph0Color = 34;
Graph1 = MA(Graph0,5);
Graph1Style = 1;
Graph1Color = 32;

//add speed Calculation

// Speed calculation
Speed = abs( C - Ref( C, -1 ) );
// SpeedUp is boolean, which is true when speed increases
SpeedUp = Speed > Ref( Speed, -1 );
SpeedDown = Speed < Ref( Speed, -1 );


//Dynamic Momentum Index Tushar Chande Translated to AFL by Jayson Casavant
//Cmo5 formula
CMO5_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,5 ) ;
CMO5_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,5 );
CMO5=DEMA(100 * Nz(( CMO5_1 -CMO5_2) /( CMO5_1+CMO5_2)),3);

//Cmo10 formula
CMO10_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,10 ) ;
CMO10_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,10 );
CMO10=DEMA(100 * Nz(( CMO10_1 -CMO10_2) /( CMO10_1+CMO10_2)),3);

//Cmo20 formula
CMO20_1=Sum( IIf( C > Ref( C, -1 ) , ( C - Ref( C ,-1 ) ) ,0 ) ,20 ) ;
CMO20_2=Sum( IIf( C < Ref( C ,-1 ) , ( Ref( C ,-1 ) - C ) ,0 ) ,20 );
CMO20=DEMA(100 * Nz(( CMO20_1 -CMO20_2) /( CMO20_1+CMO20_2)),3);

// dmi formula
dmi=((StDev(C,5)* CMO5)+(StDev(C,10)* CMO10)+(StDev(C,20)*
CMO20))/(StDev(C,5)+StDev(C,10)+StDev(C,20));
pds=Param("Smoothing",3,1,10,1);
pds1=Param("Trigger Line",5,1,10,1);

Plot(EMA(dmi,pds),"Dynamic Momentum Index",colorRed,1);
Plot(MA(dmi,pds1),"trigger",colorGreen,1);

Buy=Cross(EMA(dmi,pds),MA(dmi,pds1));
Sell=Cross(MA(dmi,pds1),EMA(dmi,pds));
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorGreen);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
PlotGrid(70,colorRed);
PlotGrid(30,colorBrightGreen);

// JJ says Ergodic is a better way to measure momentum than just using last price momentum, its more reflective of both long AND Short term momentum

//speed
// Base trading system
Buy = Cross( C, MA( C, 10 ) );
Sell = Cross( MA( C, 5 ), C );
Short = Cross( MA( C, 10 ), C );
Cover = Cross( C, MA( C, 5 ) );
// Speed calculation
Speed = abs( C - Ref( C, -1 ) );
// SpeedUp is boolean, which is true when speed increases
SpeedUp = Speed > Ref( Speed, -1 );
SpeedDown = Speed < Ref( Speed, -1 );
// these statements modify trading system rules
// to enter long/short only when speed increases
// (hypothesis 1)
Buy = Buy AND SpeedUp;
Short = Short AND SpeedUp;
//Plot(MA(C,5),"MA(C,5)",colorBlue,styleOwnScale,sty leThick);

//Plot(MA(C,10),"MA(C,10)",colorRed,styleOwnScale,st yleThick);

Plot(Speed,"Speed",colorViolet,styleDots);
//Plot(0,"ZERO",colorRed,styleDots);
//Plot(EMA(Speed,3),"emaspeed3",colorRed,styleLine);
//Plot(SpeedUp,"speedup",colorBlack,styleLine);
//Plot(SpeedDown,"speedDN",colorRed,styleLine);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();



رد مع اقتباس
قديم 05-12-2016, 07:27 PM
  المشاركه #8

عضو هوامير المميز

تاريخ التسجيل: Dec 2011
المشاركات: 310
haat غير متواجد حالياً  

جزاكم الله خيرا


رد مع اقتباس
قديم 05-12-2016, 09:55 PM
  المشاركه #9

عضو هوامير المميز

تاريخ التسجيل: Sep 2014
المشاركات: 102
adel828 غير متواجد حالياً  

اقتباس:
المشاركة الأصلية كتبت بواسطة amm1430 مشاهدة المشاركة
/*ergodic oscillator */

/*coded by prakash shenoi */
setchartbkcolor(64);
x=param(" average 1",11,2,32);
y=param(" average 2",4,3,12);
erg=(ema(ema(c-o,x),y)/ema(ema(h-l,x),y))*100;
sg=ema(erg,5);
plot (erg,"ergodic oscillator ",colorbrightgreen,styleline,1);
plot (sg,"signal",colorred,styleline,1);
graphxspace=3;

//k = 100*(c-l)/(h-l)
ergrv=(ema(ema(c-l,x),y)/ema(ema(h-l,x),y))*100;
sgrv=ema(ergrv,5);
k = 100*(c-l)/(h-l);
//plot(k,"k",colorblue,styleline);

ab = c-l; cd = h-l;




plot( 2, /* defines the height of the ribbon in percent of pane width */"erg-sig ribbon",
iif( erg>sg, colorgreen, iif( erg<sg, colorred, 0 )), /* choose color */
styleownscale|stylearea|stylenolabel, -0.5, 100 );

//------------------------------------------------------------------------------
//
// formula name: Momentum
// author/uploader: Ali
// e-mail: (e? ??? C?????? ??? ???? ?ic?? ?o??? C???ei?)
// date/time added: 2006-09-28 18:10:13
// origin: Momentum
// keywords: Momentum .afl
// level: Basic
// flags: Exploration
// formula url: http://www.amibroker.com/library/formula.php?id=723
// details url: Amibroker - afl library
//
//------------------------------------------------------------------------------
//
// momentum .afl
//
//------------------------------------------------------------------------------

/* bernstein momentum indicator */
/* set scaling to automatic, show dates on, percent on, middle on */
setchartbkcolor(64);
title = "bernstein mom close - ref(close,-7)";
graphxspace = 5;
graph0 = ma(close - ref(close,-7),1);
graph0style = 5;
graph0color = 34;
graph1 = ma(graph0,5);
graph1style = 1;
graph1color = 32;

//add speed calculation

// speed calculation
speed = abs( c - ref( c, -1 ) );
// speedup is boolean, which is true when speed increases
speedup = speed > ref( speed, -1 );
speeddown = speed < ref( speed, -1 );


//dynamic momentum index tushar chande translated to afl by jayson casavant
//cmo5 formula
cmo5_1=sum( iif( c > ref( c, -1 ) , ( c - ref( c ,-1 ) ) ,0 ) ,5 ) ;
cmo5_2=sum( iif( c < ref( c ,-1 ) , ( ref( c ,-1 ) - c ) ,0 ) ,5 );
cmo5=dema(100 * nz(( cmo5_1 -cmo5_2) /( cmo5_1+cmo5_2)),3);

//cmo10 formula
cmo10_1=sum( iif( c > ref( c, -1 ) , ( c - ref( c ,-1 ) ) ,0 ) ,10 ) ;
cmo10_2=sum( iif( c < ref( c ,-1 ) , ( ref( c ,-1 ) - c ) ,0 ) ,10 );
cmo10=dema(100 * nz(( cmo10_1 -cmo10_2) /( cmo10_1+cmo10_2)),3);

//cmo20 formula
cmo20_1=sum( iif( c > ref( c, -1 ) , ( c - ref( c ,-1 ) ) ,0 ) ,20 ) ;
cmo20_2=sum( iif( c < ref( c ,-1 ) , ( ref( c ,-1 ) - c ) ,0 ) ,20 );
cmo20=dema(100 * nz(( cmo20_1 -cmo20_2) /( cmo20_1+cmo20_2)),3);

// dmi formula
dmi=((stdev(c,5)* cmo5)+(stdev(c,10)* cmo10)+(stdev(c,20)*
cmo20))/(stdev(c,5)+stdev(c,10)+stdev(c,20));
pds=param("smoothing",3,1,10,1);
pds1=param("trigger line",5,1,10,1);

plot(ema(dmi,pds),"dynamic momentum index",colorred,1);
plot(ma(dmi,pds1),"trigger",colorgreen,1);

buy=cross(ema(dmi,pds),ma(dmi,pds1));
sell=cross(ma(dmi,pds1),ema(dmi,pds));
plotshapes(iif(buy,shapeuparrow,shapenone) ,colorgreen);
plotshapes(iif(sell,shapedownarrow,shapenone),colorred);
plotgrid(70,colorred);
plotgrid(30,colorbrightgreen);

// jj says ergodic is a better way to measure momentum than just using last price momentum, its more reflective of both long and short term momentum

//speed
// base trading system
buy = cross( c, ma( c, 10 ) );
sell = cross( ma( c, 5 ), c );
short = cross( ma( c, 10 ), c );
cover = cross( c, ma( c, 5 ) );
// speed calculation
speed = abs( c - ref( c, -1 ) );
// speedup is boolean, which is true when speed increases
speedup = speed > ref( speed, -1 );
speeddown = speed < ref( speed, -1 );
// these statements modify trading system rules
// to enter long/short only when speed increases
// (hypothesis 1)
buy = buy and speedup;
short = short and speedup;
//plot(ma(c,5),"ma(c,5)",colorblue,styleownscale,sty lethick);

//plot(ma(c,10),"ma(c,10)",colorred,styleownscale,st ylethick);

plot(speed,"speed",colorviolet,styledots);
//plot(0,"zero",colorred,styledots);
//plot(ema(speed,3),"emaspeed3",colorred,styleline);
//plot(speedup,"speedup",colorblack,styleline);
//plot(speeddown,"speeddn",colorred,styleline);

_section_begin("price");
setchartoptions(0,chartshowarrows|chartshowdates);
_n(title = strformat("{{name}} - {{interval}} {{date}} open %g, hi %g, lo %g, close %g (%.1f%%) {{values}}", o, h, l, c, selectedvalue( roc( c, 1 ) ) ));
plot( c, "close", paramcolor("color", colorblack ), stylenotitle | paramstyle("style") | getpricestyle() );
_section_end();

الله يعطيك العافية



رد مع اقتباس
قديم 10-12-2016, 01:20 AM
  المشاركه #10

ابو محمد

تاريخ التسجيل: Dec 2005
المشاركات: 14,976
تراحــــــيب غير متواجد حالياً  

اقتباس:
المشاركة الأصلية كتبت بواسطة ثلاثيني متهور مشاهدة المشاركة
الله يجزاه الجنه من يساعد ني في تصحيحها لان كثير من المعادلات نفس المشكله

_SECTION_BEGIN("Advanced Trend Lines");
function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 1.5, 0.01, 100. ,0.01);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes");
Lines = Param("Lines?", 1, 1, BarCount-2);
DrawR = ParamList("Resistance Points", "Off|High to High|High to Low", 1);
DrawS = ParamList("Support Points", "Off|Low to Low|Low to High", 1);
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1);
AllOrDownR = ParamToggle("Resistance ection", "All|Down");
AllOrUpS = ParamToggle("Support ection", "All|Up");
ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer = Param("S/R Percentage", 3, 1);
SRBack = Param("S/R Back", 5, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}

if(ShowTDP)

if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);
x0 = GetXResistance(H, SRPer, i);
y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);

}
}
Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+", Close: "+C+StrFormat(" (%.2f %.2f\%)", C-Ref(C, -1), SelectedValue(ROC(C, 1)))+str;

_SECTION_END();


_SECTION_BEGIN("Specific parameters I");
TopShape = Param("Top Fractal typ",5,0,50,1);
Topshapecolor = ParamColor("Top Fractal color",colorRed);
ValleyShape = Param("Bottom Fractal typ",6,0,50,1);
Valleyshapecolor = ParamColor("Bottom Fractal color",colorLime);
SRplot = ParamToggle("S/R plot","Off,On",1);
_SECTION_END();
_SECTION_BEGIN("Specific parameters II");
Sswitch = ParamToggle("Swing chart","On,Off",1);
Shswitch = ParamToggle("Swing shapes","On,Off",1);
PC = Param("Sensitivity",5,0.1,30,0.1);
Swingcolor = ParamColor("Swing line color",colorLime);
Swingstyle = ParamStyle("Swing line style",styleLine|styleThick,maskDefault);
SLC = ParamColor("Swing low",colorPaleGreen);
SHC = ParamColor("Swing high",colorLightOrange);
_SECTION_END();

#pragma nocache

Hp1 = Ref(H,-1);Hp2 = Ref(H,-2);Hp3 = Ref(H,-3);Hp4 = Ref(H,-4);Hp5 = Ref(H,-5);Hp6 = Ref(H,-6);
Lp1 = Ref(L,-1);Lp2 = Ref(L,-2);Lp3 = Ref(L,-3);Lp4 = Ref(L,-4);Lp5 = Ref(L,-5);Lp6 = Ref(L,-6);
Hf1 = Ref(H,1);Hf2 = Ref(H,2);Hf3 = Ref(H,3);Hf4 = Ref(H,4);Hf5 = Ref(H,5);Hf6 = Ref(H,6);
Lf1 = Ref(L,1);Lf2 = Ref(L,2);Lf3 = Ref(L,3);Lf4 = Ref(L,4);Lf5 = Ref(L,5);Lf6 = Ref(L,6);

x = Cum(1);
divx = LastValue(x)-x;

//Tops
A = H;
Top1 = A > Hf2 & A > Hf1 & A > Hp1 & A > Hp2 & divx>2;
Top2 = A > Hf3 & A > Hf2 & A ==Hf1 & A > Hp1 & A > Hp2 & divx>3 ;
Top3 = A > Hf4 & A > Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>4;
Top4 = A > Hf5 & A > Hf4 & A ==Hf3 & A >=Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>5;
Top5 = A > Hf6 & A > Hf5 & A ==Hf4 & A >=Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A >Hp2 & divx>6;
Top = Top1 OR Top2 OR Top3 OR Top4 OR Top5;
TopHigh = ValueWhen(Top,H);
TopX = ValueWhen(Top,X);
x_lasttop = LastValue(ValueWhen(top,x,1));

//Valleys
A = L;
Valley1 = A < Lf2 & A <= Lf1 & A <= Lp1 & A < Lp2 & divx>2;
Valley2 = A < Lf3 & A < Lf2 & A == Lf1 & A < Lp1 & A < Lp2 & divx>3;
Valley3 = A < Lf4 & A < Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>4;
Valley4 = A < Lf5 & A < Lf4 & A == Lf3 & A <= Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>5;
Valley5 = A < Lf6 & A < Lf5 & A == Lf4 & A <= Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>6;
Valley = Valley1 OR Valley2 OR Valley3 OR Valley4 OR Valley4 OR Valley5;
ValleyLow = ValueWhen(Valley,L);
ValleyX = ValueWhen(Valley,X);
x_lastvalley = LastValue(ValueWhen(Valley,x,1));


Plot(IIf(SRplot & x>= x_lasttop,LastValue(ValueWhen(top,H,1)),Null),"",Topshapecolor,1);
Plot(IIf(SRplot & x>= x_lastvalley,LastValue(ValueWhen(Valley,L,1)),Null),"",Valleyshapecolor,1);

Distance = 0.5*ATR(14);
//Support line signals
Sup_break = Cross(ValleyLow,C) & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;
Sup_pricejustabove = L<ValleyLow+Distance & L>ValleyLow & LowestSince(Ref(Valley,-1),Low,1)>ValleyLow & X-ValleyX >6;
Sup_confirmed = L<=ValleyLow & C>ValleyLow & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;

//Resistance line signals
Res_break = Cross(C,TopHigh) & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-TopX >6;
Res_pricejustbelow = H>TopHigh-Distance & H<TopHigh & HighestSince(Ref(Top,-1),High)<TopHigh & X-ValleyX >6;
Res_confirmed = H>=TopHigh & C<TopHigh & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-ValleyX >6;

SupSignals = Sup_break | Sup_pricejustabove | Sup_confirmed;
ResSignals = Res_break | Res_pricejustbelow | Res_confirmed;

Filter = SupSignals OR ResSignals OR 1;
AddColumn(C,"Close");
AddTextColumn(
WriteIf(Sup_pricejustabove,"price just above",
WriteIf(Sup_confirmed,"confirmed",
WriteIf(Sup_break,"break",""))),"Support",1.2,
IIf(Sup_pricejustabove OR sup_confirmed,colorGreen,colorRed));

AddTextColumn(
WriteIf(Res_pricejustbelow,"price just below",
WriteIf(Res_confirmed,"confirmed",
WriteIf(Res_break,"break",""))),"Resistance",1.2,
IIf(Res_pricejustbelow OR Res_confirmed,colorRed,colorGreen));

ZZ = Zig(C,LastValue(PC));
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotLow), SLC,0, L, -35) ;
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotHigh),SHC,0,H, 35) ;
Plot(IIf(Sswitch,-1e10,ZZ)," ",Swingcolor,Swingstyle + styleNoTitle);
/*
Lfs = LastValue(ValueWhen(Valley,L,1));
Lfr = LastValue(ValueWhen(top,H,1));
AddColumn(((((Lfr - Lfs)/(C))*100)), "%-Break" , 2.2);
AddTextColumn(FullName(),"Full name");
*/

SetChartOptions(0,chartShowDates);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("Advanced Trend Lines");
function GetXSupport(Lo, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
return (LastValue(Peak(Hi, Percentage, Back)));
}
function TD_Supply(P)
{
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
}
function TD_Demand(P)
{
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 1.5, 0.01, 100. ,0.01);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes");
Lines = Param("Lines?", 1, 1, BarCount-2);
DrawR = ParamList("Resistance Points", "Off|High to High|High to Low", 1);
DrawS = ParamList("Support Points", "Off|Low to Low|Low to High", 1);
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1);
AllOrDownR = ParamToggle("Resistance ection", "All|Down");
AllOrUpS = ParamToggle("Support ection", "All|Up");
ShowSR = ParamToggle("Show Vert S/R","No|Yes", 1);
SRPer = Param("S/R Percentage", 3, 1);
SRBack = Param("S/R Back", 5, 1);
str = "";
Res = Sup = 0;
Con = 1;
////////////////////////////////////////////////////////////////////////
Main = C;
Con = ConS = ConR = 1;
if(DrawS=="Low to Low")
{
Support1 = L;
Support2 = L;
}
else
{
Support1 = L;
Support2 = H;
}
if(DrawR=="High to High")
{
Resistance1 = H;
Resistance2 = H;
}
else
{
Resistance1 = H;
Resistance2 = L;
}
////////////////////////////////////////////////////////////////////////
//Plotting Area
if(DrawAllLines)
for(i = 2; i<=Lines+1; i++)
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, i);
x1 = GetXSupport(Support2, Percentage, i-1);
y0 = GetYSupport(Support1, Percentage, i);
y1 = GetYSupport(Support2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrUpS) ConS = StrToNum(NumToStr(y0 < y1));
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, i);
x1 = GetXResistance(Resistance2, Percentage, i-1);
y0 = GetYResistance(Resistance1, Percentage, i);
y1 = GetYResistance(Resistance2, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, 1);
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
}
else
{
if(DrawS!="Off")
{
x0 = GetXSupport(Support1, Percentage, Lines+1);
x1 = GetXSupport(Support2, Percentage, Lines);
y0 = GetYSupport(Support1, Percentage, Lines+1);
y1 = GetYSupport(Support2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Sup = LastValue(LinRegSlope(x, Lines+1));
if(AllOrUpS) ConS = y0 < y1;
if(Con AND ConS)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
if(DrawR!="Off")
{
x0 = GetXResistance(Resistance1, Percentage, Lines+1);
x1 = GetXResistance(Resistance2, Percentage, Lines);
y0 = GetYResistance(Resistance1, Percentage, Lines+1);
y1 = GetYResistance(Resistance2, Percentage, Lines);
x = LineArray(x0, y0, x1, y1, 1 );
Res = LastValue(LinRegSlope(x, Lines+1));
if(AllOrDownR) ConR = y0 > y1;
if(Con AND ConR)
Plot(x, "", IIf(LastValue(C) < LastValue(x), colorBlue,colorLightBlue), styleLine|styleThick);
}
str = "\nR Slope=("+Res+"), S Slope=("+Sup+")";
}

if(ShowTDP)

if(ShowSR)
{
for(i=1; i<=SRBack; i++)
{
x0 = GetXSupport(L, SRPer, i);
x1 = BarCount-1;
y0 = GetYSupport(L, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);
x0 = GetXResistance(H, SRPer, i);
y0 = GetYResistance(H, SRPer, i);
x = LineArray(x0, y0, x1, y0, 0);
Plot(x, "", IIf(LastValue(C) > x, colorDarkGreen, colorDarkRed), styleLine|styleDashed|styleThick);

}
}
Title =FullName()+"({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+", Close: "+C+StrFormat(" (%.2f %.2f%)", C-Ref(C,-1), SelectedValue(ROC(C, 1)))+str;

_SECTION_END();


_SECTION_BEGIN("Specific parameters I");
TopShape = Param("Top Fractal typ",5,0,50,1);
Topshapecolor = ParamColor("Top Fractal color",colorRed);
ValleyShape = Param("Bottom Fractal typ",6,0,50,1);
Valleyshapecolor = ParamColor("Bottom Fractal color",colorLime);
SRplot = ParamToggle("S/R plot","Off,On",1);
_SECTION_END();
_SECTION_BEGIN("Specific parameters II");
Sswitch = ParamToggle("Swing chart","On,Off",1);
Shswitch = ParamToggle("Swing shapes","On,Off",1);
PC = Param("Sensitivity",5,0.1,30,0.1);
Swingcolor = ParamColor("Swing line color",colorLime);
Swingstyle = ParamStyle("Swing line style",styleLine|styleThick,maskDefault);
SLC = ParamColor("Swing low",colorPaleGreen);
SHC = ParamColor("Swing high",colorLightOrange);
_SECTION_END();

#pragma nocache

Hp1 = Ref(H,-1);Hp2 = Ref(H,-2);Hp3 = Ref(H,-3);Hp4 = Ref(H,-4);Hp5 = Ref(H,-5);Hp6 = Ref(H,-6);
Lp1 = Ref(L,-1);Lp2 = Ref(L,-2);Lp3 = Ref(L,-3);Lp4 = Ref(L,-4);Lp5 = Ref(L,-5);Lp6 = Ref(L,-6);
Hf1 = Ref(H,1);Hf2 = Ref(H,2);Hf3 = Ref(H,3);Hf4 = Ref(H,4);Hf5 = Ref(H,5);Hf6 = Ref(H,6);
Lf1 = Ref(L,1);Lf2 = Ref(L,2);Lf3 = Ref(L,3);Lf4 = Ref(L,4);Lf5 = Ref(L,5);Lf6 = Ref(L,6);

x = Cum(1);
divx = LastValue(x)-x;

//Tops
A = H;
Top1 = A > Hf2 & A > Hf1 & A > Hp1 & A > Hp2 & divx>2;
Top2 = A > Hf3 & A > Hf2 & A ==Hf1 & A > Hp1 & A > Hp2 & divx>3 ;
Top3 = A > Hf4 & A > Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>4;
Top4 = A > Hf5 & A > Hf4 & A ==Hf3 & A >=Hf2 & A >=Hf1 & A > Hp1 & A > Hp2 & divx>5;
Top5 = A > Hf6 & A > Hf5 & A ==Hf4 & A >=Hf3 & A ==Hf2 & A >=Hf1 & A > Hp1 & A >Hp2 & divx>6;
Top = Top1 OR Top2 OR Top3 OR Top4 OR Top5;
TopHigh = ValueWhen(Top,H);
TopX = ValueWhen(Top,X);
x_lasttop = LastValue(ValueWhen(top,x,1));

//Valleys
A = L;
Valley1 = A < Lf2 & A <= Lf1 & A <= Lp1 & A < Lp2 & divx>2;
Valley2 = A < Lf3 & A < Lf2 & A == Lf1 & A < Lp1 & A < Lp2 & divx>3;
Valley3 = A < Lf4 & A < Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>4;
Valley4 = A < Lf5 & A < Lf4 & A == Lf3 & A <= Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>5;
Valley5 = A < Lf6 & A < Lf5 & A == Lf4 & A <= Lf3 & A == Lf2 & A <= Lf1 & A < Lp1 & A < Lp2 & divx>6;
Valley = Valley1 OR Valley2 OR Valley3 OR Valley4 OR Valley4 OR Valley5;
ValleyLow = ValueWhen(Valley,L);
ValleyX = ValueWhen(Valley,X);
x_lastvalley = LastValue(ValueWhen(Valley,x,1));


Plot(IIf(SRplot & x>= x_lasttop,LastValue(ValueWhen(top,H,1)),Null),"",Topshapecolor,1);
Plot(IIf(SRplot & x>= x_lastvalley,LastValue(ValueWhen(Valley,L,1)),Null),"",Valleyshapecolor,1);

Distance = 0.5*ATR(14);
//Support line signals
Sup_break = Cross(ValleyLow,C) & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;
Sup_pricejustabove = L<ValleyLow+Distance & L>ValleyLow & LowestSince(Ref(Valley,-1),Low,1)>ValleyLow & X-ValleyX >6;
Sup_confirmed = L<=ValleyLow & C>ValleyLow & Ref(LowestSince(Ref(Valley,-1),Low)>ValleyLow,-1) & X-ValleyX >6;

//Resistance line signals
Res_break = Cross(C,TopHigh) & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-TopX >6;
Res_pricejustbelow = H>TopHigh-Distance & H<TopHigh & HighestSince(Ref(Top,-1),High)<TopHigh & X-ValleyX >6;
Res_confirmed = H>=TopHigh & C<TopHigh & Ref(HighestSince(Ref(Top,-1),High)<TopHigh,-1) & X-ValleyX >6;

SupSignals = Sup_break | Sup_pricejustabove | Sup_confirmed;
ResSignals = Res_break | Res_pricejustbelow | Res_confirmed;

Filter = SupSignals OR ResSignals OR 1;
AddColumn(C,"Close");
AddTextColumn(
WriteIf(Sup_pricejustabove,"price just above",
WriteIf(Sup_confirmed,"confirmed",
WriteIf(Sup_break,"break",""))),"Support",1.2,
IIf(Sup_pricejustabove OR sup_confirmed,colorGreen,colorRed));

AddTextColumn(
WriteIf(Res_pricejustbelow,"price just below",
WriteIf(Res_confirmed,"confirmed",
WriteIf(Res_break,"break",""))),"Resistance",1.2,
IIf(Res_pricejustbelow OR Res_confirmed,colorRed,colorGreen));

ZZ = Zig(C,LastValue(PC));
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotLow), SLC,0, L, -35) ;
PlotShapes(IIf(Shswitch,0,shapeCircle*PivotHigh),SHC,0,H, 35) ;
Plot(IIf(Sswitch,-1e10,ZZ)," ",Swingcolor,Swingstyle + styleNoTitle);
/*
Lfs = LastValue(ValueWhen(Valley,L,1));
Lfr = LastValue(ValueWhen(top,H,1));
AddColumn(((((Lfr - Lfs)/(C))*100)), "%-Break" , 2.2);
AddTextColumn(FullName(),"Full name");
*/

SetChartOptions(0,chartShowDates);

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();



رد مع اقتباس
إضافة رد


أدوات الموضوع

تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة

الانتقال السريع



07:58 PM