Try Below code. If you still need help then I am here to help to any extent. But try to read the code even if the code make no sense to you and also try to play with the various parameters available in parametrs window.
RequestTimedRefresh( 1 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Global Parameters." );
GraphXSpace = Param( "GraphXSpace", 5, 0, 100, 1 );
GraphLabelDecimals = Param( "Graph-Label's Decimals", 3, 0, 100, 1 );
Decimals = ( Param( "Decimals", 3, 0, 7, 1 ) / 10 ) + 1;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Bi = BarIndex();
BC = BarCount - 1;
xCum = Cum( 1 );
FvB = FirstVisibleValue( Bi );
LvB = LastVisibleValue( Bi );
StartBar = BeginValue( Bi );
EndBar = EndValue( Bi );
SelectedBar = SelectedValue( Bi );
LastBar = LastValue( Bi );
LastBar_Price = EndValue( Close );
SetBarsRequired( ( LvB - FvB ) * 4 );
// SetBarsRequired( -2, -2 );
Font_Name = ParamList( "Font", "Tahoma|Helvetica|Arial Black|Verdana|Courier New|Times New Roman|Open Sans|Compact|Segoe UI|DejaVu Sans", 1 );
Text_Size = Param( "Text-Size", 8, 5, 20, 1 );
Text_Color = ParamColor( "Gfx Background-Color", colorWhite );
Text_Background_Color = ParamColor( "Text Background-Color", colorBlack );
Separation_of_Letters = Param( "Separation of Letters", 3, 1, 10, 1 );
Dashed_Line_Number = Param( "Dashed Line Number", 2, 1, 4, 1 );
Gfx_Background_Color = ParamColor( "Gfx Background Default-Color", colorBlack );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Price-Mode" );
PriceArrayMode_Switch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
// PaH is 'Price Array High'
// PaL is 'Price Array Low'
if( PriceArrayMode_Switch == 1 )
{
PaH = High;
PaL = Low;
}
else
if( PriceArrayMode_Switch == 0 )
{
PaH = C;
PaL = C;
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "ZigZag Prameters" );
nZigZag_DisplaySwitch = ParamToggle( "Display Base-ZigZag ", "No|Yes", 1 );
nZZ_PeakTrough_Shapes_DisplaySwitch = ParamToggle( "Display nZZ's PeakTrough-Shapes", "No|Yes", 0 );
nPivot_Labels_DisplaySwitch = ParamToggle( "Display nPivot-Labels", "No|Yes", 0 );
pZigZag_DisplaySwitch = ParamToggle( "Display Prime-ZigZag ", "No|Yes", 1 );
pZZ_PeakTrough_Shapes_DisplaySwitch = ParamToggle( "Display pZZ's PeakTrough-Shapes", "No|Yes", 0 );
pPivot_Labels_DisplaySwitch = ParamToggle( "Display pPivot-Labels", "No|Yes", 0 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Define nNeo-Fractals" );
nRightside_NeoFractal_Strength = Param( "Base-Zigzag's Neo-Fractal Strength", 1, 1, 50, 1 );
nLeftside_NeoFractal_Strength = nRightside_NeoFractal_Strength; // Param( "nLeftside Neo-Fractal-Strength", 1, 0, 50, 1 );
nNeoFractal_Strength_Factor = Param( "Base-Zigzag Neo-Fractal Strength-Factor", 1, 1, 20, 1 );
nRsNFS = nRightside_NeoFractal_Strength;
nLsNFs = nLeftside_NeoFractal_Strength;
nNFSF = nNeoFractal_Strength_Factor;
Neo_HighsideInBar = PaH == Ref( PaH, -1 ) AND PaL >= Ref( PaL, -1 );
Neo_LowersideInBar = PaL == Ref( PaL, -1 ) AND PaH <= Ref( PaH, -1 );
Neo_InBar = Neo_HighsideInBar OR Neo_LowersideInBar;
nscPaH = Nz( SparseCompress( !Neo_InBar, PaH ) );
nscPaL = Nz( SparseCompress( !Neo_InBar, PaL ) );
nscIdx = Nz( SparseCompress( !Neo_InBar, Bi ) );
iLsNFS = iRsNFS = iNFSF = iPaH = iPaL = iUp_NeoFractal = iDown_NeoFractal = 0;
function Calculate_Main_Pivots( iLsNFS, iRsNFS, iNFSF, iPaH, iPaL )
{
iUp_NeoFractal = iPaH > Ref( HHV( iPaH, iLsNFS * iNFSF ), -1 ) AND iPaH >= Ref( HHV( iPaH, iRsNFS * iNFSF ), iRsNFS * iNFSF );
iDown_NeoFractal = iPaL < Ref( LLV( iPaL, iLsNFS * iNFSF ), -1 ) AND iPaL <= Ref( LLV( iPaL, iRsNFS * iNFSF ), iRsNFS * iNFSF );
}
Calculate_Main_Pivots( nLsNFs, nRsNFS, nNFSF, nscPaH, nscPaL );
nscUp_NeoFractal = iUp_NeoFractal;
nscDown_NeoFractal = iDown_NeoFractal;
nUp_NeoFractal = Nz( SparseExpand( !Neo_InBar, nscUp_NeoFractal ) );
nDown_NeoFractal = Nz( SparseExpand( !Neo_InBar, nscDown_NeoFractal ) );
nPeak = nUp_NeoFractal;
nTrough = nDown_NeoFractal;
nResistance = ValueWhen( nUp_NeoFractal, PaH );
nSupport = ValueWhen( nDown_NeoFractal, PaL );
nCrossUp = PaH > Ref( nResistance, -1 );
nCrossDown = PaL < Ref( nSupport, -1 );
nCrossUp = ExRem( nCrossUp, nCrossDown );
nCrossDown = ExRem( nCrossDown, nCrossUp );
nTrendUp = Flip( nCrossUp, nCrossDown );
nTrendDown = Flip( nCrossDown, nCrossUp );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Clean nPeak-Trough" );
// 'clean' the pivots function
// meaning make the pivots alternate like Peak-Trough-Peak-Trough-Peak-Trough-etc..
xnPeak = xnTrough = 0;
function Alternate_PeakTrough( xnPeak, xnTrough )
{
global xnPeak_g;
global xnTrough_g;
// alternate pivots
xnPeak_g = xnPeak;
xnTrough_g = xnTrough;
xnPeakHigh = 0;
xnPeakHighIndex = 0;
xnTroughLow = 1e10;
xnTroughLowIndex = 0;
for( i = 0; i < BarCount - 1; i++ )
{
// consecutive lower trough found
if( xnTrough[i] AND PaL[i] <= xnTroughLow )
{
// disable the previous higher trough
xnTrough_g[xnTroughLowIndex] = 0;
// update trough variables
xnTroughLow = PaL[i];
xnTroughLowIndex = i;
// reset peak variables
xnPeakHigh = 0;
xnPeakHighIndex = 0;
}
else
// consecutive higher trough found
if( xnTrough[i] AND PaL[i] > xnTroughLow )
{
// disable this trough
xnTrough_g[i] = 0;
// reset peak variables
xnPeakHigh = 0;
xnPeakHighIndex = 0;
}
else
// consecutive higher peak found
if( xnPeak[i] AND PaH[i] >= xnPeakHigh )
{
// disable the previous lower peak
xnPeak_g[xnPeakHighIndex] = 0;
// update new peak variables
xnPeakHigh = PaH[i];
xnPeakHighIndex = i;
// reset trough variables
xnTroughLow = 1e10;
xnTroughLowIndex = 0;
}
else
// consecutive lower peak found
if( xnPeak[i] AND PaH[i] < xnPeakHigh )
{
// disable this peak
xnPeak_g[i] = 0;
// reset trough variables
xnTroughLow = 1e10;
xnTroughLowIndex = 0;
}
}
}
// run clean pivots
Alternate_PeakTrough( nPeak, nTrough );
nPeak = xnPeak_g;
nTrough = xnTrough_g;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Find Missed nPeak-nTrough" );
// Find Missed Peak
nTrough_Bars = BarsSince( nTrough );
nHH_Bars = HHVBars( PaH, nTrough_Bars ); // Bars back to higher high since nTrough (if > 0, it is bars back to missed Peak)
nHH_Bars_Peak = IIf( nPeak, nHH_Bars, 0 ); // Restrict to current Peak bar
nHH_Bars_Peak_Reverse = Reverse( nHH_Bars_Peak ); // Can't change past so reverse time
nHH_Bars_Peak_Bars_Reverse = ValueWhen( nHH_Bars_Peak_Reverse, nHH_Bars_Peak_Reverse ); // Hold 'bars back to new Peak' forward in reversed time
nPeak_Bar_New_Reverse = Ref( nHH_Bars_Peak_Reverse, -nHH_Bars_Peak_Bars_Reverse ) == nHH_Bars_Peak_Bars_Reverse; // Find new Peak bar in reversed time
nPeak_Bar_New = Reverse( nPeak_Bar_New_Reverse ); // Restore time direction
nPeak = ( nPeak OR nPeak_Bar_New ) AND NOT nHH_Bars_Peak; // Add new Peak signal and remove old
// Find Missed Trough
nPeak_Bars = BarsSince( nPeak );
nLL_Bars = LLVBars( PaL, nPeak_Bars ); // Bars back to lower PaL since nPeak (if > 0, it is bars back to missed Trough)
nLL_Bars_Trough = IIf( nTrough, nLL_Bars, 0 ); // Restrict to current Trough bar
nLL_Bars_Trough_Reverse = Reverse( nLL_Bars_Trough ); // Can't change past so reverse time
nLL_Bars_Trough_Bars_Reverse = ValueWhen( nLL_Bars_Trough_Reverse, nLL_Bars_Trough_Reverse ); // Hold 'bars back to new Trough' forward in reversed time
nTrough_Bar_New_Reverse = Ref( nLL_Bars_Trough_Reverse, -nLL_Bars_Trough_Bars_Reverse ) == nLL_Bars_Trough_Bars_Reverse; // Find new Trough bar in reversed time
nTrough_Bar_New = Reverse( nTrough_Bar_New_Reverse ); // Restore time direction
nTrough = ( nTrough OR nTrough_Bar_New ) AND NOT nLL_Bars_Trough; // Add new Trough signal and remove old
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( " Again Clean nPeak-nTrough" );
// run clean pivots
Alternate_PeakTrough( nPeak, nTrough );
nPeak = xnPeak_g;
nTrough = xnTrough_g;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "nPivots-Camparision" );
for( i = 0; i < 3; i++ )
{
VarSet( "nPeak_x" + i, ValueWhen( nPeak, Bi, i ) );
VarSet( "nTrough_x" + i, ValueWhen( nTrough, Bi, i ) );
VarSet( "nPeakHigh_" + i, ValueWhen( nPeak, PaH, i ) );
VarSet( "nTroughLow_" + i, ValueWhen( nTrough, PaL, i ) );
}
nLowerLow = nTrough AND nTroughLow_1 < nTroughLow_2; // LL = LowerLow
nHigherLow = nTrough AND nTroughLow_1 > nTroughLow_2; // HL = HigherLow
nHigherHigh = nPeak AND nPeakHigh_1 > nPeakHigh_2; // HH = HigherHigh
nLowerHigh = nPeak AND nPeakHigh_1 < nPeakHigh_2; // LH = LowerHigh
nDoubleTop = nPeak AND nPeakHigh_1 == nPeakHigh_2; // DT = DoubleTop
nDoubleBottom = nTrough AND nTroughLow_1 == nTroughLow_2; // DB = DoubleBottom
nPeakBar_01 = ValueWhen( nPeak, Bi, 1 );
nPeakBar_02 = ValueWhen( nPeak, Bi, 2 );
nPeakBar_03 = ValueWhen( nPeak, Bi, 3 );
nTroughBar_01 = ValueWhen( nTrough, Bi, 1 );
nTroughBar_02 = ValueWhen( nTrough, Bi, 2 );
nTroughBar_03 = ValueWhen( nTrough, Bi, 3 );
nPeakBarHigh_01 = ValueWhen( nPeak, PaH, 1 );
nPeakBarHigh_02 = ValueWhen( nPeak, PaH, 2 );
nPeakBarHigh_03 = ValueWhen( nPeak, PaH, 3 );
nTroughBarLow_01 = ValueWhen( nTrough, PaL, 1 );
nTroughBarLow_02 = ValueWhen( nTrough, PaL, 2 );
nTroughBarLow_03 = ValueWhen( nTrough, PaL, 3 );
nLast_Pivot_Peak = nPeakBar_01 > nTroughBar_01;
nLast_Pivot_Trough = nTroughBar_01 > nPeakBar_01;
nRecent_Pivot_Peak = nPeakBar_02 > nTroughBar_02 AND nTroughBar_01 > nPeakBar_02;
nRecent_Pivot_Trough = nTroughBar_02 > nPeakBar_02 AND nPeakBar_01 > nTroughBar_02;
nPrevious_Pivot_Peak = nPeakBar_02 < nTroughBar_02 AND nTroughBar_02 < nPeakBar_01 AND nPeakBar_01 < nTroughBar_01;
nPrevious_Pivot_Trough = nTroughBar_02 < nPeakBar_02 AND nPeakBar_02 < nTroughBar_01 AND nTroughBar_01 < nPeakBar_01;
nPeakTrough_SameBar_01 = nPeakBar_01 == nTroughBar_01;
nPeakTrough_SameBar_02 = nPeakBar_02 == nTroughBar_02;
nPeakTrough_SameBar_03 = nPeakBar_02 == nTroughBar_01 AND nPeakBar_03 > nTroughBar_02;
nPeakTrough_SameBar_04 = nTroughBar_02 == nPeakBar_01 AND nTroughBar_03 > nPeakBar_02;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "nZigZag Pivot's Lables" );
//nPivot_Labels_DisplaySwitch = ParamToggle( "Display nPivot-Labels", "No|Yes", 1 );
nPivot_Labels_Zorder = Param( "nPivot-Label's Zorder", 5, -5, 5, 1 );
nPivot_Label_Background_Color = ParamColor( "nLabel's Background-Color", colorBlack );
nPivot_Upper_Label_Color = ParamColor( "nUpper-Label Color", colorYellow );
nPivot_Lower_Label_Color = ParamColor( "nLower-Lable Color", colorCustom11 );
nPivot_Upper_Label_vPosition = Param( "nUpper-Label's Vertical-Position", 30, 0, 100, 1 );
nPivot_Lower_Label_vPosition = Param( "nLower-Label's Vertical-Position", -30, 0, -100, 1 );
if( nPivot_Labels_DisplaySwitch == 1 )
{
GfxSetZOrder( nPivot_Labels_Zorder );
for( i = 0; i < BarCount - 1; i++ )
{
if( nLowerLow[i] )
{
nString = "LL";
PlotTextSetFont( nString, Font_Name, Text_Size, i, PaL[i], nPivot_Lower_Label_Color, nPivot_Label_Background_Color, nPivot_Lower_Label_vPosition );
}
if( nHigherLow [i] )
{
nString = "HL";
PlotTextSetFont( nString, Font_Name, Text_Size, i, PaL[i], nPivot_Lower_Label_Color, nPivot_Label_Background_Color, nPivot_Lower_Label_vPosition );
}
if( nHigherHigh[i] )
{
nString = "HH";
PlotTextSetFont( nString, Font_Name, Text_Size, i, PaH[i], nPivot_Upper_Label_Color, nPivot_Label_Background_Color, nPivot_Upper_Label_vPosition );
}
if( nLowerHigh[i] )
{
nString = "LH";
PlotTextSetFont( nString, Font_Name, Text_Size, i, PaH[i], nPivot_Upper_Label_Color, nPivot_Label_Background_Color, nPivot_Upper_Label_vPosition );
}
if( nDoubleTop[i] )
{
nString = "DT";
PlotTextSetFont( nString, Font_Name, Text_Size, i, PaH[i], nPivot_Upper_Label_Color, nPivot_Label_Background_Color, nPivot_Upper_Label_vPosition );
}
if( nDoubleBottom[i] )
{
nString = "DB";
PlotTextSetFont( nString, Font_Name, Text_Size, i, PaL[i], nPivot_Lower_Label_Color, nPivot_Label_Background_Color, nPivot_Lower_Label_vPosition );
}
}
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Base-ZigZag" );
// nZigZag_DisplaySwitch = ParamToggle( "Display nZigZag ", "No|Yes", 1 );
// nZZ_PeakTrough_Shapes_DisplaySwitch = ParamToggle( "Display ZZ's PeakTrough-Shapes ", "No|Yes", 0 );
nZZ_Line_Zorder = Param( "nZZ Line-Zorder", 4, -5, 5, 1 );
nZZ_Line_Width = Param( "nZZ Line-Width", 2, 1, 5, 1 );
nZZ_Line_Style = ParamStyle( "nZZ Line-Style", styleLine | styleNoRescale | styleNoLabel );
nGFX_Line_Style = Param( "nGFX Line-Style", 0, 0, 5, 1 ); // Solid=0, Dash=1, Dot=2, Null=5 (Invisible-Pen).
nZZ_UpLine_Color = ParamColor( "nZZ's UpLine-Color", colorTurquoise );
nZZ_DownLine_Color = ParamColor( "nZZ DownLine-Color", colorTurquoise );
nZZ_Line1_Color = ParamColor( "nZZ's Line1-Color", colorYellow );
nZZ_Line2_Color = ParamColor( "nZZ Line2-Color", colorYellow );
nZZ_Peak_Shape_Color = ParamColor( "nZZ Peak Shape-Color", colorCustom12 );
nZZ_Trough_Shape_Color = ParamColor( "nZZ Trough Shape-Color", colorYellow );
nZZ_Peak_Shape_Type = Param( "nZZ Peak Shape-Type", 13, 0, 50, 1 );
nZZ_Trough_Shape_Type = Param( "nZZ Trough Shape-Type", 13, 0, 50, 1 );
nZZ_Peak_Shape_vPosition = Param( "nZZ Peak-Shape's Vertical-Position", 10, 0, 100, 1 );
nZZ_Trough_Shape_vPosition = Param( "nZZ Trough-Shape's Vertical-Position", -10, 0, -100, 1 );
iaPeak = iaTrough = 0;
iaZigZag = Null;
iaLine1 = Null;
function Calculate_ZigZag( iaPeak, iaTrough )
{
// create ZigZag array Line
ZZ_Up = Flip( iaTrough, iaPeak );
ZZ_UpLow = ValueWhen( iaTrough, PaL, 1 );
ZZ_UpHigh = ValueWhen( iaPeak, PaH, 0 );
ZZ_UpLowIdx = ValueWhen( iaTrough, Bi, 1 );
ZZ_UpHighIdx = ValueWhen( iaPeak, Bi, 0 );
ZZ_SlopeUp = IIf( ZZ_Up, ( ZZ_UpHigh - ZZ_UpLow ) / ( ZZ_UpHighIdx - ZZ_UpLowIdx ) , Null );
ZZ_UpLine = IIf( ZZ_Up, ZZ_UpLow + ZZ_SlopeUp * BarsSince( iaTrough ), Null );
ZZ_Down = Flip( iaPeak, iaTrough );
ZZ_DownLow = ValueWhen( iaTrough, PaL, 0 );
ZZ_DownHigh = ValueWhen( iaPeak, PaH, 1 );
ZZ_DownLowIdx = ValueWhen( iaTrough, Bi, 0 );
ZZ_DownHighIdx = ValueWhen( iaPeak, Bi, 1 );
ZZ_SlopeDown = IIf( ZZ_Down, ( ZZ_DownLow - ZZ_DownHigh ) / ( ZZ_DownLowIdx - ZZ_DownHighIdx ) , Null );
ZZ_DownLine = IIf( ZZ_Down, ZZ_DownHigh + ZZ_SlopeDown * BarsSince( iaPeak ), Null );
ZigZag = IIf( ZZ_Up, ZZ_UpLine, IIf( ZZ_Down, ZZ_DownLine, Null ) );
ZigZag = IIf( Bi > Max( LastValue( ValueWhen( iaTrough, Bi ) ), LastValue( ValueWhen( iaPeak, Bi ) ) ), Null, ZigZag );
return ZigZag;
}
function Calculate_LastSegment( iaPeak, iaTrough, iaZigZag )
{
iaLine1 = Null;
Last_PeakIdx = LastValue( ValueWhen( iaPeak, Bi ) );
Last_TroughIdx = LastValue( ValueWhen( iaTrough, Bi ) );
Last_PeakValue = LastValue( ValueWhen( iaPeak, PaH ) );
Last_TroughValue = LastValue( ValueWhen( iaTrough, PaL ) );
PeakValue = LastValue( HighestSince( Ref( iaTrough, -1 ), PaH , 1 ) );
PeakIdx = LastValue( ValueWhen( PaH == PeakValue, Bi ) );
TroughValue = LastValue( LowestSince( Ref( iaPeak, -1 ), PaL, 1 ) );
TroughIdx = LastValue( ValueWhen( PaL == TroughValue, Bi ) );
iaLine = iaLine2 = Null;
// Last leg
if( Last_PeakIdx > Last_TroughIdx )
{
x0 = Last_PeakIdx;
y0 = Last_PeakValue;
x1 = TroughIdx;
y1 = TroughValue;
iaLine1 = LineDown = LineArray( x0, y0, x1, y1 );
iaTrough[TroughIdx] = 1;
}
if( Last_PeakIdx < Last_TroughIdx )
{
x0 = Last_TroughIdx;
y0 = Last_TroughValue;
x1 = PeakIdx;
y1 = PeakValue;
iaLine1 = LineUp = LineArray( x0, y0, x1, y1 );
iaPeak[PeakIdx] = 1;
}
iaZigZag = IIf( !IsEmpty( iaLine1 ), iaLine1, iaZigZag );
}
function Draw_UpLine( nGfxCoordsMode, nLine_Zorder, nUpLine_Color, nLine_Width, nLine_Style, nTroughBar_01, nTroughBarLow_01, nPeakBar_01, nPeakBarHigh_01 )
{
GfxSetCoordsMode( nGfxCoordsMode );
GfxSetZOrder( nLine_Zorder );
GfxSelectPen( nUpLine_Color, nLine_Width, nLine_Style );
GfxMoveTo( nTroughBar_01, nTroughBarLow_01 );
GfxLineTo( nPeakBar_01, nPeakBarHigh_01 );
}
function Draw_DownLine( nGfxCoordsMode, nDownLine_Color, nLine_Zorder, nLine_Width, nLine_Style, nPeakBar_01, nPeakBarHigh_01, nTroughBar_01, nTroughBarLow_01 )
{
GfxSetCoordsMode( nGfxCoordsMode );
GfxSetZOrder( nLine_Zorder );
GfxSelectPen( nDownLine_Color, nLine_Width, nLine_Style );
GfxMoveTo( nPeakBar_01, nPeakBarHigh_01 );
GfxLineTo( nTroughBar_01, nTroughBarLow_01 );
}
function Draw_UpLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02, nTroughBarLow_02, nPeakBar_01, nPeakBarHigh_01 )
{
GfxSetCoordsMode( nGfxCoordsMode );
GfxSetZOrder( nLine_Zorder );
GfxSelectPen( nLine_Color, nLine_Width, nLine_Style );
GfxMoveTo( nTroughBar_02, nTroughBarLow_02 );
GfxLineTo( nPeakBar_01, nPeakBarHigh_01 );
}
function Draw_DownLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nPeakBar_02, nPeakBarHigh_02, nTroughBar_01, nTroughBarLow_01 )
{
GfxSetCoordsMode( nGfxCoordsMode );
GfxSetZOrder( nLine_Zorder );
GfxSelectPen( nLine_Color, nLine_Width, nLine_Style );
GfxMoveTo( nPeakBar_02, nPeakBarHigh_02 );
GfxLineTo( nTroughBar_01, nTroughBarLow_01 );
}
function Draw_Line_PT_SameBar_to_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02, nTroughBarLow_02, nPeakBar_01, nPeakBarHigh_01 )
{
GfxSetCoordsMode( nGfxCoordsMode );
GfxSetZOrder( nLine_Zorder );
GfxSelectPen( nLine_Color, nLine_Width, nLine_Style );
GfxMoveTo( nTroughBar_02, nTroughBarLow_02 );
GfxLineTo( nPeakBar_01, nPeakBarHigh_01 );
}
if( nZigZag_DisplaySwitch == 1 )
{
nGfxCoordsMode = 1;
nLine_Zorder = nZZ_Line_Zorder;
nLine_Color = nZZ_UpLine_Color;
nUpLine_Color = nZZ_UpLine_Color;
nDownLine_Color = nZZ_DownLine_Color;
nLine_Width = nZZ_Line_Width;
nLine_Style = nGFX_Line_Style;
for( i = 0; i < BarCount - 1; i++ )
{
if( nPeakTrough_SameBar_01[i] )
{
Draw_UpLine( nGfxCoordsMode, nLine_Zorder, nUpLine_Color, nLine_Width, nLine_Style, nTroughBar_01[i], nTroughBarLow_01[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
}
if( nPeakTrough_SameBar_03[i] )
{
Draw_UpLine( nGfxCoordsMode, nLine_Zorder, nUpLine_Color, nLine_Width, nLine_Style, nTroughBar_01[i], nTroughBarLow_01[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
}
if( nPeakTrough_SameBar_04[i] )
{
Draw_DownLine( nGfxCoordsMode, nDownLine_Color, nLine_Zorder, nLine_Width, nLine_Style, nPeakBar_01[i], nPeakBarHigh_01[i], nTroughBar_01[i], nTroughBarLow_01[i] );
}
if( nPeakTrough_SameBar_01[i] AND nRecent_Pivot_Trough[i] )
{
Draw_UpLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02[i], nTroughBarLow_02[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
}
if( nPeakTrough_SameBar_01[i] AND nRecent_Pivot_Peak[i] )
{
Draw_DownLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nPeakBar_02[i], nPeakBarHigh_02[i], nTroughBar_01[i], nTroughBarLow_01[i] );
}
if( nPeakTrough_SameBar_01[i] AND nPeakTrough_SameBar_02[i] )
{
Draw_Line_PT_SameBar_to_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02[i], nTroughBarLow_02[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
}
}
}
nZigZag = Calculate_ZigZag( nPeak, nTrough );
Calculate_LastSegment( nPeak, nTrough, nZigZag );
if( nZigZag_DisplaySwitch == 1 )
{
nZZ_Line_Color = IIf( nZigZag, nZZ_UpLine_Color, IIf( nZigZag, nZZ_DownLine_Color, Null ) );
Plot( nZigZag, "", nZZ_Line_Color, nZZ_Line_Style, Null, Null, 0, nZZ_Line_Zorder, nZZ_Line_Width );
}
if( nZZ_PeakTrough_Shapes_DisplaySwitch )
{
PlotShapes( nZZ_Peak_Shape_Type * nPeak, nZZ_Peak_Shape_Color, 0, PaH, nZZ_Peak_Shape_vPosition );
PlotShapes( nZZ_Trough_Shape_Type * nTrough, nZZ_Trough_Shape_Color, 0, PaL, nZZ_Trough_Shape_vPosition );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Define pNeo-Fractals" );
pRightside_NeoFractal_Strength = Param( "Base-Zigzag's Neo-Fractal Strength", 1, 1, 50, 1 );
pLeftside_NeoFractal_Strength = pRightside_NeoFractal_Strength; // Param( "pLeftside Neo-Fractal-Strength", 1, 0, 50, 1 );
pNeoFractal_Strength_Factor = Param( "Base-Zigzag Neo-Fractal Strength-Factor", 1, 1, 20, 1 );
pRsNFS = pRightside_NeoFractal_Strength;
pLsNFs = pLeftside_NeoFractal_Strength;
pNFSF = pNeoFractal_Strength_Factor;
nPeak_High = ValueWhen( nPeak, PaH );
nTrough_Low = ValueWhen( nTrough, PaL );
Calculate_Main_Pivots( pLsNFs, pRsNFS, pNFSF, nPeak_High, nTrough_Low );
pUp_NeoFractal = iUp_NeoFractal;
pDown_NeoFractal = iDown_NeoFractal;
pPeak = pUp_NeoFractal;
pTrough = pDown_NeoFractal;
pResistance = ValueWhen( pUp_NeoFractal, PaH );
pSupport = ValueWhen( pDown_NeoFractal, PaL );
pCrossUp = PaH > Ref( pResistance, -1 );
pCrossDown = PaL < Ref( pSupport, -1 );
pCrossUp = ExRem( pCrossUp, pCrossDown );
pCrossDown = ExRem( pCrossDown, pCrossUp );
pTrendUp = Flip( pCrossUp, pCrossDown );
pTrendDown = Flip( pCrossDown, pCrossUp );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Find Missed pPeak-pTrough" );
// Find Missed Peak
pTrough_Bars = BarsSince( pTrough );
pHH_Bars = HHVBars( PaH, pTrough_Bars ); // Bars back to higher PaH since nTrough (if > 0, it is bars back to missed Peak)
pHH_Bars_Peak = IIf( pPeak, pHH_Bars, 0 ); // Restrict to current Peak bar
pHH_Bars_Peak_Reverse = Reverse( pHH_Bars_Peak ); // Can't change past so reverse time
pHH_Bars_Peak_Bars_Reverse = ValueWhen( pHH_Bars_Peak_Reverse, pHH_Bars_Peak_Reverse ); // Hold 'bars back to new Peak' forward in reversed time
pPeak_Bar_New_Reverse = Ref( pHH_Bars_Peak_Reverse, -pHH_Bars_Peak_Bars_Reverse ) == pHH_Bars_Peak_Bars_Reverse; // Find new Peak bar in reversed time
pPeak_Bar_New = Reverse( pPeak_Bar_New_Reverse ); // Restore time direction
pPeak = ( pPeak OR pPeak_Bar_New ) AND NOT pHH_Bars_Peak; // Add new Peak signal and remove old
// Find Missed Trough
pPeak_Bars = BarsSince( pPeak );
pLL_Bars = LLVBars( PaL, pPeak_Bars ); // Bars back to lower PaL since nPeak (if > 0, it is bars back to missed Trough)
pLL_Bars_Trough = IIf( pTrough, pLL_Bars, 0 ); // Restrict to current Trough bar
pLL_Bars_Trough_Reverse = Reverse( pLL_Bars_Trough ); // Can't change past so reverse time
pLL_Bars_Trough_Bars_Reverse = ValueWhen( pLL_Bars_Trough_Reverse, pLL_Bars_Trough_Reverse ); // Hold 'bars back to new Trough' forward in reversed time
pTrough_Bar_New_Reverse = Ref( pLL_Bars_Trough_Reverse, -pLL_Bars_Trough_Bars_Reverse ) == pLL_Bars_Trough_Bars_Reverse; // Find new Trough bar in reversed time
pTrough_Bar_New = Reverse( pTrough_Bar_New_Reverse ); // Restore time direction
pTrough = ( pTrough OR pTrough_Bar_New ) AND NOT pLL_Bars_Trough; // Add new Trough signal and remove old
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Clean pPeak-pTrough" );
xpPeak = xpTrough = 0;
// run clean pivots
Alternate_PeakTrough( pPeak, pTrough );
pPeak = xnPeak_g;
pTrough = xnTrough_g;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "pPivots-Camparision" );
for( i = 0; i < 3; i++ )
{
VarSet( "pPeak_x" + i, ValueWhen( pPeak, Bi, i ) );
VarSet( "pTrough_x" + i, ValueWhen( pTrough, Bi, i ) );
VarSet( "pPeakHigh_" + i, ValueWhen( pPeak, PaH, i ) );
VarSet( "pTroughLow_" + i, ValueWhen( pTrough, PaL, i ) );
}
pLowerLow = pTrough AND pTroughLow_1 < pTroughLow_2; // LL = LowerLow
pHigherLow = pTrough AND pTroughLow_1 > pTroughLow_2; // HL = HigherLow
pHigherHigh = pPeak AND pPeakHigh_1 > pPeakHigh_2; // HH = HigherHigh
pLowerHigh = pPeak AND pPeakHigh_1 < pPeakHigh_2; // LH = LowerHigh
pDoubleTop = pPeak AND pPeakHigh_1 == pPeakHigh_2; // DT = DoubleTop
pDoubleBottom = pTrough AND pTroughLow_1 == pTroughLow_2; // DB = DoubleBottom
pPeakBar_01 = ValueWhen( pPeak, Bi, 1 );
pPeakBar_02 = ValueWhen( pPeak, Bi, 2 );
pPeakBar_03 = ValueWhen( pPeak, Bi, 3 );
pTroughBar_01 = ValueWhen( pTrough, Bi, 1 );
pTroughBar_02 = ValueWhen( pTrough, Bi, 2 );
pTroughBar_03 = ValueWhen( pTrough, Bi, 3 );
pPeakBarHigh_01 = ValueWhen( pPeak, PaH, 1 );
pPeakBarHigh_02 = ValueWhen( pPeak, PaH, 2 );
pPeakBarHigh_03 = ValueWhen( pPeak, PaH, 3 );
pTroughBarLow_01 = ValueWhen( pTrough, PaL, 1 );
pTroughBarLow_02 = ValueWhen( pTrough, PaL, 2 );
pTroughBarLow_03 = ValueWhen( pTrough, PaL, 3 );
pLast_Pivot_Peak = pPeakBar_01 > pTroughBar_01;
pLast_Pivot_Trough = pTroughBar_01 > pPeakBar_01;
pRecent_Pivot_Peak = pPeakBar_02 > pTroughBar_02 AND pTroughBar_01 > pPeakBar_02;
pRecent_Pivot_Trough = pTroughBar_02 > pPeakBar_02 AND pPeakBar_01 > pTroughBar_02;
pPrevious_Pivot_Peak = pPeakBar_02 < pTroughBar_02 AND pTroughBar_02 < pPeakBar_01 AND pPeakBar_01 < pTroughBar_01;
pPrevious_Pivot_Trough = pTroughBar_02 < pPeakBar_02 AND pPeakBar_02 < pTroughBar_01 AND pTroughBar_01 < pPeakBar_01;
pPeakTrough_SameBar_01 = pPeakBar_01 == pTroughBar_01;
pPeakTrough_SameBar_02 = pPeakBar_02 == pTroughBar_02;
pPeakTrough_SameBar_03 = pPeakBar_02 == pTroughBar_01 AND pPeakBar_03 > pTroughBar_02;
pPeakTrough_SameBar_04 = pTroughBar_02 == pPeakBar_01 AND pTroughBar_03 > pPeakBar_02;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "pPivots-Comparison Lables" );
//pPivot_Labels_DisplaySwitch = ParamToggle( "Display pPivot-Labels", "No|Yes", 1 );
pPivot_Labels_Zorder = Param( "pPivot-Label's Zorder", 5, -5, 5, 1 );
pPivot_Label_Background_Color = ParamColor( "pLabel's Background-Color", colorBlack );
pPivot_Upper_Label_Color = ParamColor( "pUpper-Label Color", colorYellow );
pPivot_Lower_Label_Color = ParamColor( "pLower-Lable Color", colorCustom11 );
pPivot_Upper_Label_vPosition = Param( "pUpper-Label's Vertical-Position", 30, 0, 100, 1 );
pPivot_Lower_Label_vPosition = Param( "pLower-Label's Vertical-Position", -30, 0, -100, 1 );
if( pPivot_Labels_DisplaySwitch == 1 )
{
GfxSetZOrder( pPivot_Labels_Zorder );
for( i = 0; i < BarCount - 1; i++ )
{
if( pLowerLow[i] )
{
pString = "LL";
PlotTextSetFont( pString, Font_Name, Text_Size, i, PaL[i], pPivot_Lower_Label_Color, pPivot_Label_Background_Color, pPivot_Lower_Label_vPosition );
}
if( pHigherLow [i] )
{
pString = "HL";
PlotTextSetFont( pString, Font_Name, Text_Size, i, PaL[i], pPivot_Lower_Label_Color, pPivot_Label_Background_Color, pPivot_Lower_Label_vPosition );
}
if( pHigherHigh[i] )
{
pString = "HH";
PlotTextSetFont( pString, Font_Name, Text_Size, i, PaH[i], pPivot_Upper_Label_Color, pPivot_Label_Background_Color, pPivot_Upper_Label_vPosition );
}
if( pLowerHigh[i] )
{
pString = "LH";
PlotTextSetFont( pString, Font_Name, Text_Size, i, PaH[i], pPivot_Upper_Label_Color, pPivot_Label_Background_Color, pPivot_Upper_Label_vPosition );
}
if( pDoubleTop[i] )
{
pString = "DT";
PlotTextSetFont( pString, Font_Name, Text_Size, i, PaH[i], pPivot_Upper_Label_Color, pPivot_Label_Background_Color, pPivot_Upper_Label_vPosition );
}
if( pDoubleBottom[i] )
{
pString = "DB";
PlotTextSetFont( pString, Font_Name, Text_Size, i, PaL[i], pPivot_Lower_Label_Color, pPivot_Label_Background_Color, pPivot_Lower_Label_vPosition );
}
}
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Prime-ZigZag" );
// pZigZag_DisplaySwitch = ParamToggle( "Display pZigZag ", "No|Yes", 1 );
// pZZ_PeakTrough_Shapes_DisplaySwitch = ParamToggle( "Display pZZ's PeakTrough-Shapes ", "No|Yes", 0 );
pZZ_Line_Zorder = Param( "pZZ Line-Zorder", 5, -5, 5, 1 );
pZZ_Line_Width = Param( "pZZ Line-Width", 3, 1, 5, 1 );
pZZ_Line_Style = ParamStyle( "pZZ Line-Style", styleLine | styleNoRescale | styleNoLabel );
pGFX_Line_Style = Param( "pGFX Line-Style", 0, 0, 5, 1 ); // Solid=0, Dash=1, Dot=2, Null=5 (Invisible-Pen).
pZZ_UpLine_Color = ParamColor( "pZZ's UpLine-Color", colorWhite );
pZZ_DownLine_Color = ParamColor( "pZZ DownLine-Color", colorWhite );
pZZ_Peak_Shape_Color = ParamColor( "pZZ Peak Shape-Color", colorCustom12 );
pZZ_Trough_Shape_Color = ParamColor( "pZZ Trough Shape-Color", colorYellow );
pZZ_Peak_Shape_Type = Param( "pZZ Peak Shape-Type", 13, 0, 50, 1 );
pZZ_Trough_Shape_Type = Param( "pZZ Trough Shape-Type", 13, 0, 50, 1 );
pZZ_Peak_Shape_vPosition = Param( "pZZ Peak-Shape's Vertical-Position", 10, 0, 100, 1 );
pZZ_Trough_Shape_vPosition = Param( "pZZ Trough-Shape's Vertical-Position", -10, 0, -100, 1 );
if( pZigZag_DisplaySwitch == 1 )
{
pGfxCoordsMode = 1;
pLine_Zorder = pZZ_Line_Zorder;
pLine_Color = pZZ_UpLine_Color;
pUpLine_Color = pZZ_UpLine_Color;
pDownLine_Color = pZZ_DownLine_Color;
pLine_Width = pZZ_Line_Width;
pLine_Style = pGFX_Line_Style;
for( i = 0; i < BarCount - 1; i++ )
{
if( pPeakTrough_SameBar_01[i] )
{
Draw_UpLine( pGfxCoordsMode, pLine_Zorder, pUpLine_Color, pLine_Width, pLine_Style, pTroughBar_01[i], pTroughBarLow_01[i], pPeakBar_01[i], pPeakBarHigh_01[i] );
}
if( pPeakTrough_SameBar_03[i] )
{
Draw_UpLine( pGfxCoordsMode, pLine_Zorder, pUpLine_Color, pLine_Width, pLine_Style, pTroughBar_01[i], pTroughBarLow_01[i], pPeakBar_01[i], pPeakBarHigh_01[i] );
}
if( pPeakTrough_SameBar_04[i] )
{
Draw_DownLine( pGfxCoordsMode, pDownLine_Color, pLine_Zorder, pLine_Width, pLine_Style, pPeakBar_01[i], pPeakBarHigh_01[i], pTroughBar_01[i], pTroughBarLow_01[i] );
}
if( pPeakTrough_SameBar_01[i] AND pRecent_Pivot_Trough[i] )
{
Draw_UpLine_PT_SameBar( pGfxCoordsMode, pLine_Zorder, pLine_Color, pLine_Width, pLine_Style, pTroughBar_02[i], pTroughBarLow_02[i], pPeakBar_01[i], pPeakBarHigh_01[i] );
}
if( pPeakTrough_SameBar_01[i] AND pRecent_Pivot_Peak[i] )
{
Draw_DownLine_PT_SameBar( pGfxCoordsMode, pLine_Zorder, pLine_Color, pLine_Width, pLine_Style, pPeakBar_02[i], pPeakBarHigh_02[i], pTroughBar_01[i], pTroughBarLow_01[i] );
}
if( pPeakTrough_SameBar_01[i] AND pPeakTrough_SameBar_02[i] )
{
Draw_Line_PT_SameBar_to_PT_SameBar( pGfxCoordsMode, pLine_Zorder, pLine_Color, pLine_Width, pLine_Style, pTroughBar_02[i], pTroughBarLow_02[i], pPeakBar_01[i], pPeakBarHigh_01[i] );
}
}
}
pZigZag = Calculate_ZigZag( pPeak, pTrough );
Calculate_LastSegment( pPeak, pTrough, pZigZag );
if( pZigZag_DisplaySwitch == 1 )
{
pZZ_Line_Color = IIf( pZigZag, pZZ_UpLine_Color, IIf( pZigZag, pZZ_DownLine_Color, Null ) );
Plot( pZigZag, "", pZZ_Line_Color, pZZ_Line_Style, Null, Null, 0, pZZ_Line_Zorder, pZZ_Line_Width );
}
if( pZZ_PeakTrough_Shapes_DisplaySwitch )
{
PlotShapes( pZZ_Peak_Shape_Type * pPeak, pZZ_Peak_Shape_Color, 0, PaH, pZZ_Peak_Shape_vPosition );
PlotShapes( pZZ_Trough_Shape_Type * pTrough, pZZ_Trough_Shape_Color, 0, PaL, pZZ_Trough_Shape_vPosition );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Coded by @FXshrat
// Asthetic customization options added by @LotusHeart
// Here, I was using 'FX' prefix just to remember the kind help of @FXshrat. You can change the prefix if you want to.
_SECTION_BEGIN( "Top-Lines" );
FX_TopLine_DisplaySwitch = ParamToggle( "Display TopLines", "No|Yes", 1 );
Choose_ZigZagType_to_Display_FX_TopLine = ParamList( "Choose ZigZag-Type to Display TopLines", "Base-ZigZag | Prime-ZigZag", 0 );
FX_TopVisibleChartArea_DisplaySwitch = ParamToggle( "Display TopLines Only in Visible-Area", "No|Yes", 0 );
FX_All_TopLines_DisplaySwitch = ParamToggle( "Display All Top-Lines ?", "No|Yes", 1 );
FX_MLiP = Param( "TopLine's Max-Length in Periods", 1008, 0, 10000, 1 ); // 'FX_MLiP' is the short form for 'Line's Max-Length in Periods.
FX_TopLine_Text_Vertical_Position = Param( "TopLine's Text's Vertical-Position", 1.00, 0.00, 1.00, 0.10 );
FX_TopLine_Style = Param( "TopLine's Style: Solid=0, Dash=1, Dot=2", 2, 0, 2, 1 );
FX_TopLine_Color = ParamColor( "TopLine's Color", colorCustom15 );
FX_TopLine_Width = Param( "TopLine's Width", 1, 1, 10, 1 );
FX_TopLine_Text_Size = Param( "TopLine's Text-Size", 8, 8, 20, 1 );
FX_TopLine_Text_Background_Mode = Param( "TopLine Text's Background_Mode: 2 = Opaque, 1 = Transparent", 1, 1, 2, 1 );
FX_TopLine_Text_Weight = Param( "TopLine's Text-Weight", 400, 300, 800, 100 ); // Typical values are: 300 - light, 400 - normal, 700 - bold, 800 - ultrabold
FX_TopLine_Text_Color = ParamColor( "TopLine's Text-Color", colorCustom9 );
FX_TopLine_Text_Background_Color = ParamColor( "TopLine's Text Background-Color", colorTan );
FX_TopLine_Zorder = Param( "TopLine's Zorder", 5, -5, 5, 1 );
FX_TopPivot_PriceValue_DisplaySwitch = ParamToggle( "Display TopPivot Price-Value ?", "No|Yes", 0 );
FX_TopLine_PeriodCount_DisplaySwitch = ParamToggle( "Display TopLine's Period-Count ?", "No|Yes", 1 );
function FX_TopLines( FX_SignalTop, FX_TargetArrayTop, FX_Visible_ChartArea_Top )
{
FX_VisibleBars_Top = Status( "BarVisible" ); // chart area array
if( FX_Visible_ChartArea_Top )
{
FX_TopCum_s = Cum( IIf( FX_VisibleBars_Top, FX_SignalTop, 0 ) );
FX_TopLastCum = LastVisibleValue( FX_TopCum_s );
}
else
{
FX_TopCum_s = Cum( FX_SignalTop );
FX_TopLastCum = LastValue( FX_TopCum_s, 1 );
}
FX_Display_TopRange = IIf( FX_Visible_ChartArea_Top, FX_VisibleBars_Top, 1 );
FX_TopLastBar = BarCount - 1;
FX_Matrix_StopTop = Matrix( 3, Max( 1, FX_TopLastCum ), 0 );
FX_ColumnTop = MxGetSize( FX_Matrix_StopTop, 1 );
for( i = 0, n = 0; i < BarCount; i++ )
{
if( FX_Display_TopRange[i] ) // if visible chart
{
if( FX_SignalTop[i] ) // if signal
{
if( n < FX_ColumnTop ) // ensure not exceeding matrix size
{
FX_Matrix_StopTop[0][n] = i; // start bar
FX_Matrix_StopTop[1][n] = FX_TopLastBar; // end bar
FX_Matrix_StopTop[2][n] = FX_TargetArrayTop[i]; // level
for( j = i + 1, k = 0; j < BarCount; j++ )
{
if( PaH[j] > FX_Matrix_StopTop[2][n] )
{
FX_Matrix_StopTop[1][n] = j; // end bar
break;
}
}
}
n++;
}
}
}
return FX_Matrix_StopTop;
}
if( FX_TopLine_DisplaySwitch )
{
// Font-Weight - specifies the font weight (in inked pixels per 1000). Typical values are: 300 - light, 400 - normal, 700 - bold, 800 - ultrabold
GfxSetZOrder( FX_TopLine_Zorder );
GfxSetCoordsMode( 1 );
GfxSetBkMode( FX_TopLine_Text_Background_Mode );
GfxSetTextAlign( 0 | 0 );
GfxSelectFont( "Font_Name", FX_TopLine_Text_Size, FX_TopLine_Text_Weight ); // GfxSelectFont( "Arial", 8, 500 );
GfxSetTextColor( FX_TopLine_Text_Color );
GfxSetBkColor( FX_TopLine_Text_Background_Color );
GfxSelectPen( FX_TopLine_Color, FX_TopLine_Width, FX_TopLine_Style );
switch( Choose_ZigZagType_to_Display_FX_TopLine )
{
case "Base-ZigZag":
FX_TargetArrayTop = ValueWhen( nPeak, PaH );
break;
case "Prime-ZigZag":
FX_TargetArrayTop = ValueWhen( pPeak, PaH );
break;
default:
FX_TargetArrayTop = ValueWhen( pPeak, PaH );
break;
}
FX_Max_Bars_Top = FX_MLiP; // edit maximum number of periods of line to be drawn
if( FX_All_TopLines_DisplaySwitch == 1 )
{
FX_Display_All_TopLines = True;
}
else
if( FX_All_TopLines_DisplaySwitch == 0 )
{
FX_Display_All_TopLines = False;
}
if( FX_TopLine_PeriodCount_DisplaySwitch == 1 )
{
FX_Display_PeriodCount_Top = True;
}
else
if( FX_TopLine_PeriodCount_DisplaySwitch == 0 )
{
FX_Display_PeriodCount_Top = False;
}
if( FX_TopPivot_PriceValue_DisplaySwitch == 1 )
{
FX_Display_PriceValue_Top = True;
}
else
if( FX_TopPivot_PriceValue_DisplaySwitch == 0 )
{
FX_Display_PriceValue_Top = False;
}
if( FX_TopVisibleChartArea_DisplaySwitch == 1 )
{
FX_VisibleChartArea_Top = True;
}
else
if( FX_TopVisibleChartArea_DisplaySwitch == 0 )
{
FX_VisibleChartArea_Top = False;
}
FX_Matrix_StopTop = FX_TopLines( PaH == FX_TargetArrayTop, FX_TargetArrayTop, FX_VisibleChartArea_Top );
FX_TopLastBar = BarCount - 1;
FX_ColumnTop = MxGetSize( FX_Matrix_StopTop, 1 );
for( n = 0; n < FX_ColumnTop; n++ )
{
x2 = FX_Matrix_StopTop[1][n];
if( x2 == FX_TopLastBar OR FX_Display_All_TopLines )
{
x1 = FX_Matrix_StopTop[0][n];
if( x2 - x1 <= FX_Max_Bars_Top )
{
y = FX_Matrix_StopTop[2][n];
GfxMoveTo( x1, y );
GfxLineTo( x2, y );
if( FX_Display_PriceValue_Top )
{
GfxTextOut( StrFormat( "[ %g ]", y ), x1, y );
}
if( FX_Display_PeriodCount_Top )
{
GfxTextOut( StrFormat( "%g", x2 - x1 ), ( x1 + x2 ) * 0.5, y + FX_TopLine_Text_Vertical_Position );
}
}
}
}
printf( "\n%s", MxToString( FX_Matrix_StopTop ) );
printf( "\n#lines: %g, BarCount: %g", MxGetSize( FX_Matrix_StopTop, 1 ), BarCount );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Bottom-Lines" );
BottomLine_DisplaySwitch = ParamToggle( "Display BottomLines", "No|Yes", 1 );
Choose_ZigZagType_to_Display_FX_BottomLine = ParamList( "Choose ZigZag-Type to Display BottomLines", "Base-ZigZag | Prime-ZigZag", 0 );
FX_BottomVisibleChartArea_DisplaySwitch = ParamToggle( "Display BottomLines Only in Visible-Area", "No|Yes", 0 );
FX_All_BottomLines_DisplaySwitch = ParamToggle( "Display All Bottom-Lines ?", "No|Yes", 1 );
FX_MLiP = Param( "BottomLine's Max-Length in Periods", 1008, 0, 10000, 1 ); // 'FX_MLiP' is the short form for 'Line's Max-Length in Periods.
FX_BottomLine_Text_Vertical_Position = Param( "BottomLine's Text's Vertical-Position", 0.30, 0.00, 1.00, 0.10 );
BottomLine_OtherOptions_DisplaySwitch = ParamToggle( "Display BottomLine's OtherOptions", "No|Yes", 0 );
FX_BottomLine_Style = Param( "BottomLine's Style: Solid=0, Dash=1, Dot=2", 2, 0, 2, 1 );
FX_BottomLine_Color = ParamColor( "BottomLine's Color", colorCustom14 );
FX_BottomLine_Width = Param( "BottomLine's Width", 1, 1, 10, 1 );
FX_BottomLine_Text_Size = Param( "BottomLine's Text-Size", 8, 8, 20, 1 );
FX_BottomLine_Text_Background_Mode = Param( "BottomLine Text's Background_Mode: 2 = Opaque, 1 = Transparent", 1, 1, 2, 1 );
FX_BottomLine_Text_Weight = Param( "BottomLine's Text-Weight", 400, 300, 800, 100 ); // Typical values are: 300 - light, 400 - normal, 700 - bold, 800 - ultrabold
FX_BottomLine_Text_Color = ParamColor( "BottomLine's Text-Color", colorCustom8 );
FX_BottomLine_Text_Background_Color = ParamColor( "BottomLine's Text Background-Color", colorTan );
FX_BottomLine_Zorder = Param( "BottomLine's Zorder", 5, -5, 5, 1 );
FX_BottomPivot_PriceValue_DisplaySwitch = ParamToggle( "Display BottomPivot Price-Value ?", "No|Yes", 0 );
FX_BottomLine_PeriodCount_DisplaySwitch = ParamToggle( "Display BottomLine's Period-Count ?", "No|Yes", 1 );
function BottomLines( FX_SignalBottom, FX_TargetArrayBottom, FX_Visible_ChartArea_Bottom )
{
FX_VisibleBars_Bottom = Status( "BarVisible" ); // chart area array
if( FX_Visible_ChartArea_Bottom )
{
FX_BottomCum_s = Cum( IIf( FX_VisibleBars_Bottom, FX_SignalBottom, 0 ) );
FX_BottomLastCum = LastVisibleValue( FX_BottomCum_s );
}
else
{
FX_BottomCum_s = Cum( FX_SignalBottom );
FX_BottomLastCum = LastValue( FX_BottomCum_s, 1 );
}
FX_Display_BottomRange = IIf( FX_Visible_ChartArea_Bottom, FX_VisibleBars_Bottom, 1 );
FX_BottomLastBar = BarCount - 1;
FX_Matrix_StopBottom = Matrix( 3, Max( 1, FX_BottomLastCum ), 0 );
FX_ColumnBottom = MxGetSize( FX_Matrix_StopBottom, 1 );
for( i = 0, n = 0; i < BarCount; i++ )
{
if( FX_Display_BottomRange[i] ) // if visible chart
{
if( FX_SignalBottom[i] ) // if signal
{
if( n < FX_ColumnBottom ) // ensure not exceeding matrix size
{
FX_Matrix_StopBottom[0][n] = i; // start bar
FX_Matrix_StopBottom[1][n] = FX_BottomLastBar; // end bar
FX_Matrix_StopBottom[2][n] = FX_TargetArrayBottom[i]; // level
for( j = i + 1, k = 0; j < BarCount; j++ )
{
if( PaL[j] < FX_Matrix_StopBottom[2][n] )
{
FX_Matrix_StopBottom[1][n] = j; // end bar
break;
}
}
}
n++;
}
}
}
return FX_Matrix_StopBottom;
}
if( BottomLine_DisplaySwitch )
{
// Font-Weight - specifies the font weight (in inked pixels per 1000). Typical values are: 300 - light, 400 - normal, 700 - bold, 800 - ultrabold
GfxSetZOrder( FX_BottomLine_Zorder );
GfxSetCoordsMode( 1 );
GfxSetBkMode( FX_BottomLine_Text_Background_Mode );
GfxSetTextAlign( 0 | 0 );
GfxSelectFont( "Font_Name", FX_BottomLine_Text_Size, FX_BottomLine_Text_Weight ); // GfxSelectFont( "Arial", 8, 500 );
GfxSetTextColor( FX_BottomLine_Text_Color );
GfxSetBkColor( FX_BottomLine_Text_Background_Color );
GfxSelectPen( FX_BottomLine_Color, FX_BottomLine_Width, FX_BottomLine_Style );
switch( Choose_ZigZagType_to_Display_FX_TopLine )
{
case "Base-ZigZag":
FX_TargetArrayBottom = ValueWhen( nTrough, PaL );
break;
case "Prime-ZigZag":
FX_TargetArrayBottom = ValueWhen( pTrough, PaL );
break;
default:
FX_TargetArrayBottom = ValueWhen( pTrough, PaL );
break;
}
FX_Max_Bars_Bottom = FX_MLiP; // edit maximum number of periods of line to be drawn
if( FX_All_BottomLines_DisplaySwitch == 1 )
{
FX_Display_All_BottomLines = True;
}
else
if( FX_All_BottomLines_DisplaySwitch == 0 )
{
FX_Display_All_BottomLines = False;
}
if( FX_BottomLine_PeriodCount_DisplaySwitch == 1 )
{
FX_Display_PeriodCount_Bottom = True;
}
else
if( FX_BottomLine_PeriodCount_DisplaySwitch == 0 )
{
FX_Display_PeriodCount_Bottom = False;
}
if( FX_BottomPivot_PriceValue_DisplaySwitch == 1 )
{
FX_Display_PriceValue_Bottom = True;
}
else
if( FX_BottomPivot_PriceValue_DisplaySwitch == 0 )
{
FX_Display_PriceValue_Bottom = False;
}
if( FX_BottomVisibleChartArea_DisplaySwitch == 1 )
{
FX_VisibleChartArea_Bottom = True;
}
else
if( FX_BottomVisibleChartArea_DisplaySwitch == 0 )
{
FX_VisibleChartArea_Bottom = False;
}
FX_Matrix_StopBottom = BottomLines( PaL == FX_TargetArrayBottom, FX_TargetArrayBottom, FX_VisibleChartArea_Bottom );
FX_BottomLastBar = BarCount - 1;
FX_ColumnBottom = MxGetSize( FX_Matrix_StopBottom, 1 );
for( n = 0; n < FX_ColumnBottom; n++ )
{
x2 = FX_Matrix_StopBottom[1][n];
if( x2 == FX_BottomLastBar OR FX_Display_All_BottomLines )
{
x1 = FX_Matrix_StopBottom[0][n];
if( x2 - x1 <= FX_Max_Bars_Bottom )
{
y = FX_Matrix_StopBottom[2][n];
GfxMoveTo( x1, y );
GfxLineTo( x2, y );
if( FX_Display_PriceValue_Bottom )
{
GfxTextOut( StrFormat( "%g", y ), x1, y );
}
if( FX_Display_PeriodCount_Bottom )
{
GfxTextOut( StrFormat( "%g", x2 - x1 ), ( x1 + x2 ) * 0.5, y - FX_BottomLine_Text_Vertical_Position );
}
}
}
}
printf( "\n%s", MxToString( FX_Matrix_StopBottom ) );
printf( "\n#lines: %g, BarCount: %g", MxGetSize( FX_Matrix_StopBottom, 1 ), BarCount );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx