I always wanted to have a zigzag where I can have peak-trough on same-bar.
With my little knowledge of AFL I somehow succeded in creating a zigzag using low-level graphics.
This zigzag fulfills my trading needs. On a visual basis everything is fine.
But due to particular section now I am unable to use the peak-trough for another applications.
The code is simple, well-organized and self-explainatory.
My problem is with a section named " _SECTION_BEGIN( "Find Missed Peaks-Troughs" ) ".
The three line comments at the beginning of this section explains my problem.
After applying the code of this section it became impossible for me to make any further use of peak-trough values and their indexes.
I am stucked. Kindly guide me for the solution of this problem.
Especially looking forward to experts: @fxshrat, @beppe, @Panos @Milosz
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Date-Time etc." );
RequestTimedRefresh( 1 );
TTDC = ParamColor( "Title-Text's Default-Color", colorWhite );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MT_Start = BeginValue( BarIndex() );
MT_End = EndValue( BarIndex() );
MT_Periods = MT_End - MT_Start;
MT_ValueStart = BeginValue( C );
MT_ValueEnd = EndValue( C );
MT_Difference = MT_ValueEnd - MT_ValueStart;
MT_Percentage = NumToStr( ( ( MT_Difference / MT_ValueStart ) * 100 ), 1.2 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
TimeFrame = Interval();
SecNumber = GetSecondNum();
NewPeriod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
if( NewPeriod )
{
Say( "New period" );
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LastBar_Price = EndValue( Close );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SetChartOptions( 0, chartShowArrows | chartShowDates );
//TimeFrame = in1Minute * Param( "Time Frame (min)", 5, 1, 1440 * 10, 1 ); // 1440 minutes is 1 day
TimeFrame = in1Minute * Interval() / 60 * 1; // Param( "Chart Time Frame Factor", 1, 1, 10, 1 ); // factor 1 uses timeframe of chart
_N( Title = EncodeColor( TTDC ) + /* GfxSetTextColor(Text_Background_Color) + */ StrFormat( "Symbol-Name = {{NAME}} || Visible-Chart-Area's Date-&-Time = {{DATE}} || Open %g | High %g | Low %g | Close %g | ROC (%.1f%%) || " +
" Last-Price = " + LastBar_Price + "\n TimeFrame: " + TimeFrame / 60 + " Minutes | " + TimeFrame / 3600 + " Hours | " + TimeFrame / ( 3600 * 24 ) + " Days || " +
" Total-Bars = " + MT_Periods + " || Total %%Change = " + MT_Percentage + " || My Machine-Time = " + Now( 2 ) + " || CountDown to Bar-Close = " + SecsToGo +
"{{VALUES}} ", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// SetBarsRequired( -2, -2 );
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 );
SetBarsRequired( ( LVB - FVB ) * 4 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
GraphXSpace = Param( "GraphXSpace", 10, 0, 100, 1 );
GraphLabelDecimals = Param( "Graph-Label's Decimals", 3, 0, 100, 1 );
Decimals = ( Param( "Decimals", 3, 0, 7, 1 ) / 10 ) + 1;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/*
function ParamOptimize( Pname, DefaultValue, MinValue, MaxValue, Step )
{
return Optimize( Pname,
Param( pname, DefaultValue, MinValue, MaxValue, Step ),
MinValue, MaxValue, Step );
}
*/
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Session Seprator Vertical-Lines
/*
Start_Time = 093000;
End_Time = 153000;
Day_Separator = Day() != Ref( Day(), -1 );
In_Session = timenum() >= Start_Time && timenum() <= End_Time;
End_Session = timenum() >= End_Time;
End_Session = ( End_Session - Ref( End_Session, -1 ) ) == 1 OR Ref( Day_Separator, 1 );;
Start_Session = timenum() >= Start_Time;
Start_Session = ( Start_Session - Ref( Start_Session, -1 ) ) == 1;
*/
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Chart's Background-Colors" );
Outer_Panel_Color = ParamColor( "Outer Panel Color", colorDarkGrey );
InnerPanel_UpperHalf_Color = ParamColor( "Inner-Panel Upper-Half's Color", colorDarkGrey );
InnerPanel_LowerHalf_Color = ParamColor( "Inner-Panel Lower-Half's Color", colorDarkGrey );
Chart_Background_Color = ParamColor( "Chart Background Color", colorDarkGrey );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SetChartBkColor( Outer_Panel_Color ); // color of outer border
SetChartBkGradientFill( InnerPanel_UpperHalf_Color, InnerPanel_LowerHalf_Color ); // color of inner panel
SetChartBkColor( Chart_Background_Color );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Style of Price" );
Price_Chart_DisplaySwitch = ParamToggle( "Display Price-Chart", "Off|On", 1 );
Price_Chart_Style = ParamList( "Price-Chart's Style", "Neo-Candle|Meta-Candle|Bar|Line", 0 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Price_Zorder = Param( "Price-Zorder", 1, -5, 5, 1 );
Price_Line_Width = Param( "Price-Line's Width", 2, 1, 5, 1 );
Price_Style = ParamStyle( "Price_Style", styleCandle );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Doji_Color = ParamColor( "Doji Color", colorWhite );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Bar-Color Options
Price_Bull_Color = ParamColor( "Price Bull Color", colorTeal );
Price_Bear_Color = ParamColor( "Price Bear Color", colorOrange );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Meta-Candle Color-Options
Price_Bull_MetaColor = ParamColor( "Price Bull MetaColor", colorWhite );
Price_Bear_MetaColor = ParamColor( "Price Bear MetaColor", colorOrange );
Price_Internal_MetaColor = ParamColor( "Price Internal MetaColor", colorTeal );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Neo-Candle Color-Options
Doji_Bar_Color = ParamColor( "Doji-Bar Color", colorWhite );
BullBar_Color_A = ParamColor( "Bull-Bar Color-A", colorTeal );
BearBar_Color_A = ParamColor( "Bear-Bar Color-A", colorOrange );
BullBar_Color_B = ParamColor( "Bull-Bar Color-B", colorWhite );
BearBar_Color_B = ParamColor( "Bear-Bar Color-B", colorOrange );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Price_Title = "";
// Bar Color-Conditions
Price_Color = IIf( Close > Open, Price_Bull_Color, IIf( Close < Open, Price_Bear_Color, Doji_Color ) );
// Meta-Candle Color-Conditions
Price_MetaColor = IIf( Close > Open, Price_Bull_MetaColor, IIf( Close < Open, Price_Bear_MetaColor, Doji_Color ) );
Price_Inside_MetaColor = IIf( Close < Open, Price_MetaColor, Price_Internal_MetaColor );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( Price_Chart_DisplaySwitch )
{
switch( Price_Chart_Style )
{
case "Meta-Candle":
SetBarFillColor( Price_Inside_MetaColor );
PlotOHLC( Open, High, Low, Close, Price_Title, Price_MetaColor, Price_Style, 0, -5, 0, Price_Zorder );
break;
case "Bar":
PriceStyle = styleBar;
PlotOHLC( Open, High, Low, Close, Price_Title, Price_Color, PriceStyle | styleThick, 0, -5, 0, Price_Zorder, Price_Line_Width );
break;
case "Line":
PriceStyle = styleLine;
Price_Color = IIf( Close >= Open, Price_Bull_Color, Price_Bear_Color );
SetBarFillColor( Price_Color );
PlotOHLC( Open, High, Low, Close, Price_Title, Price_Color, PriceStyle | styleDots | styleThick, 0, -5, 0, Price_Zorder, Price_Line_Width );
break;
case "Neo-Candle":
SetBarFillColor( IIf( Close > Open, BullBar_Color_A, IIf( Close < Open, BearBar_Color_A, Doji_Bar_Color ) ) );
PlotOHLC( Open, High, Low, Close, Price_Title, IIf( Close > O, BullBar_Color_B, IIf( Close < Open, BearBar_Color_B, Doji_Bar_Color ) ),
Price_Style, Null, Null, 0, Price_Zorder, Price_Line_Width );
break;
default:
SetBarFillColor( Price_Color );
Price_Color = cLine;
break;
}
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Price-Mode" );
PriceArrayMode_Switch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( PriceArrayMode_Switch == 1 )
{
PaH = High;
PaL = Low;
}
else
if( PriceArrayMode_Switch == 0 )
{
PaH = C;
PaL = C;
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Bars & Swings" );
Missed_High_Low_HandleSwitch = ParamToggle( "Include Missed Highs-&-Lows ?", "No | Yes", 0 );
Number_of_Bars_for_UpSwing = Param( "Number-of-Bars for ZigZag-Swing", 1, 1, 10, 1 );
Number_of_Bars_for_DownSwing = Number_of_Bars_for_UpSwing; // Param( "Number-of-Bars for DownSwing", 1, 1, 5, 1 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
UpBar = PaH > Ref( PaH, -1 ) and PaL >= Ref( PaL, -1 );
DownBar = PaH <= Ref( PaH, -1 ) and PaL < Ref( PaL, -1 );
OutBar = PaH > Ref( PaH, -1 ) AND PaL < Ref( PaL, -1 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
UpSwing = Sum( UpBar, Number_of_Bars_for_UpSwing ) == Number_of_Bars_for_UpSwing;
DownSwing = Sum( DownBar, Number_of_Bars_for_DownSwing ) == Number_of_Bars_for_DownSwing;
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// This section's code is not mine. A online friend shared a code and I extracted it from his code.
// Already seeked his permission before sharing it here online. Many thanks to him for his kindness.
// Breakout-section is placed below the 'UpSwing-start' AND 'DownSwing-start' sections because then this code is generating better peaks & troughs.
// Changes due to this suffle are very subtle and are observable only when one notices all the fine details of zigzag.
_SECTION_BEGIN( "Calculate Peak-Trough" );
xPeak = xTrough = 0;
xPeak_High = 0;
xTrough_Low = 1e5;
Ups = Downs = 0;
IdxHigh = IdxLow = 0;
High_PriceArray = Low_PriceArray = 0;
Breakout_High = Breakout_Low = 0;
UpSwing_Start = DownSwing_Start = 0;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
for( i = 0; i < BarCount; i++ )
{
// UpSwing start
if( UpSwing[i] AND Ups == 0 )
{
IdxHigh = i;
High_PriceArray = PaH[i];
Ups = 1;
Downs = 0;
UpSwing_Start[i] = 1;
xTrough[IdxLow] = 1;
xTrough_Low[IdxLow] = PaL[IdxLow];
}
else
// UpSwing continuation
if( Ups == 1 AND PaH[i] >= High_PriceArray )
{
IdxHigh = i;
High_PriceArray = PaH[i];
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// DownSwing start
if( DownSwing[i] AND Downs == 0 )
{
IdxLow = i;
Low_PriceArray = PaL[i];
Ups = 0;
Downs = 1;
DownSwing_Start[i] = 1;
xPeak[IdxHigh] = 1;
xPeak_High[IdxHigh] = PaH[IdxHigh];
}
else
// DownSwing continuation
if( Downs == 1 AND PaL[i] <= Low_PriceArray )
{
IdxLow = i;
Low_PriceArray = PaL[i];
}
// breakout lower without swinglow
if( Ups == 1 AND PaL[i] < Low_PriceArray AND !UpSwing[i] )
{
Breakout_Low[i] = 1;
DownSwing[i] = 1;
DownSwing_Start[i] = 1;
IdxLow = i;
Low_PriceArray = PaL[i];
Ups = 0;
Downs = 1;
xPeak[IdxHigh] = 1;
xPeak_High[IdxHigh] = High_PriceArray;
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// breakout higher without swinghigh
if( Downs == 1 AND PaH[i] > High_PriceArray AND !DownSwing[i] )
{
Breakout_High[i] = 1;
UpSwing[i] = 1;
UpSwing_Start[i] = 1;
IdxHigh = i;
High_PriceArray = PaH[i];
Ups = 1;
Downs = 0;
xTrough[IdxLow] = 1;
xTrough_Low[IdxLow] = Low_PriceArray;
}
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// I coded this display is to help myself to understand the outbar-points because Most of the zigzag's problems are found at outside-bars.
// Here, I have invented new terms to expand the concept of outside-bars, for ease of handling.
// As per best of my information, a few of these concepts about outbars might not be in available techinical-analysis theories.
_SECTION_BEGIN( "Outside-Bar Display" );
OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When OutBar' ?", "No|Yes", 0 );
OutBar_Shape_Color = ParamColor( "OutBar Shape-Color", colorWhite );
xAbsolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xAbsolute-OutBar' ?", "No|Yes", 0 );
xAbsolute_OutBar_Shape_Color = ParamColor( "xAbsolute-OutBar Shape-Color", colorGold );
xPeakBar_Absolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xPeak-Bar is also xAbsolute-OutBar' ?", "No|Yes", 0 );
xPeakBar_Absolute_OutBar_Shape_Color = ParamColor( "'xPeakBar-Absolute-OutBar' Shape-Color", colorBrightGreen );
xTroughBar_Absolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xTrough-Bar is also xAbsolute-OutBar' ?", "No|Yes", 0 );
xTroughBar_Absolute_OutBar_Shape_Color = ParamColor( "'xTroughBar-Absolute-OutBar' Shape-Color", colorOrange );
xPeakTrough_SameBar_Absolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xPeakTrough-@-SameBar is also xAbsolute-OutBar' ?", "No|Yes", 0 );
xPeakTrough_SameBar_Absolute_OutBar_Shape_Color = ParamColor( "'xPeakTrough-SameBar is Absolute-OutBar' Shape-Color", colorBlue );
xPeakTrough_SameBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xPeakTrough-@-SameBar' ?", "No|Yes", 0 );
xPeakTrough_SameBar_Shape_Color = ParamColor( "'xPeakTrough_SameBar' Shape-Color", colorAqua );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xRecent_Pivot_Peak = ValueWhen( xPeak, Bi, 1 ) > ValueWhen( xTrough, Bi, 1 );
xRecent_Pivot_Trough = ValueWhen( xTrough, Bi, 1 ) > ValueWhen( xPeak, Bi, 1 );
xRecent_PreviousPivot_Peak = ValueWhen( xPeak, Bi, 2 ) > ValueWhen( xTrough, Bi, 2 ) AND ValueWhen( xTrough, Bi, 1 ) > ValueWhen( xPeak, Bi, 2 ) AND ValueWhen( xPeak, Bi, 1 ) > ValueWhen( xTrough, Bi, 1 );
xRecent_PreviousPivot_Trough = ValueWhen( xTrough, Bi, 2 ) > ValueWhen( xPeak, Bi, 2 ) AND ValueWhen( xPeak, Bi, 1 ) > ValueWhen( xTrough, Bi, 2 ) AND ValueWhen( xTrough, Bi, 1 ) > ValueWhen( xPeak, Bi, 1 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OutBar = PaH > Ref( PaH, -1 ) AND PaL < Ref( PaL, -1 );
OutBar_High = ValueWhen( OutBar, PaH );
OutBar_Low = ValueWhen( OutBar, PaL );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xAbsolute_OutBar = OutBar AND( ValueWhen( xPeak, PaH, 1 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 1 ) > ValueWhen( OutBar, PaL ) );
xPeakBar_Absolute_OutBar = OutBar AND( ValueWhen( xPeak, PaH, 1 ) == ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 1 ) != ValueWhen( OutBar, PaL ) ) AND
( ValueWhen( xPeak, PaH, 2 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 1 ) > ValueWhen( OutBar, PaL ) );
xTroughBar_Absolute_OutBar = OutBar AND( ValueWhen( xPeak, PaH, 1 ) != ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 1 ) == ValueWhen( OutBar, PaL ) ) AND
( ValueWhen( xPeak, PaH, 1 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 2 ) > ValueWhen( OutBar, PaL ) );
xPT_SameBar_Absolute_OutBar = OutBar AND( ValueWhen( xPeak, PaH, 1 ) == ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 1 ) == ValueWhen( OutBar, PaL ) ) AND
( ValueWhen( xPeak, PaH, 2 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( xTrough, PaL, 2 ) > ValueWhen( OutBar, PaL ) );
xPeakTrough_SameBar = xPeak AND xTrough;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( OutBar_DisplaySwitch == 1 )
{
PlotShapes( shapeSquare * OutBar, OutBar_Shape_Color, 0, High, 70 );
PlotShapes( shapeSquare * OutBar, OutBar_Shape_Color, 0, Low, -70 );
}
if( xAbsolute_OutBar_DisplaySwitch == 1 )
{
PlotShapes( shapeSquare * xAbsolute_OutBar, xAbsolute_OutBar_Shape_Color, 0, High, 60 );
PlotShapes( shapeSquare * xAbsolute_OutBar, xAbsolute_OutBar_Shape_Color, 0, Low, -60 );
}
if( xPeakTrough_SameBar_Absolute_OutBar_DisplaySwitch == 1 )
{
PlotShapes( shapeSquare * xPT_SameBar_Absolute_OutBar, xPeakTrough_SameBar_Absolute_OutBar_Shape_Color, 0, High, 50 );
PlotShapes( shapeSquare * xPT_SameBar_Absolute_OutBar, xPeakTrough_SameBar_Absolute_OutBar_Shape_Color, 0, Low, -50 );
}
if( xPeakBar_Absolute_OutBar_DisplaySwitch == 1 )
{
PlotShapes( shapeSquare * xPeakBar_Absolute_OutBar, xPeakBar_Absolute_OutBar_Shape_Color, 0, High, 40 );
PlotShapes( shapeSquare * xPeakBar_Absolute_OutBar, xPeakBar_Absolute_OutBar_Shape_Color, 0, Low, -40 );
}
if( xTroughBar_Absolute_OutBar_DisplaySwitch == 1 )
{
PlotShapes( shapeSquare * xTroughBar_Absolute_OutBar, xTroughBar_Absolute_OutBar_Shape_Color, 0, High, 30 );
PlotShapes( shapeSquare * xTroughBar_Absolute_OutBar, xTroughBar_Absolute_OutBar_Shape_Color, 0, Low, -30 );
}
if( xPeakTrough_SameBar_DisplaySwitch == 1 )
{
PlotShapes( shapeSquare * xPeakTrough_SameBar, xPeakTrough_SameBar_Shape_Color, 0, High, 20 );
PlotShapes( shapeSquare * xPeakTrough_SameBar, xPeakTrough_SameBar_Shape_Color, 0, Low, -20 );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "Find Missed Peaks-Troughs" );
// The idea I have used in this section is workable but visually only.
// It has gnerated a problem which makes difficlut to use Troughs for any applications which reqire peaks and trough.
// This problem can be visually seen if one tries to display the peaks and troughs via ploting shapes.
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xTrough_Bar_01 = ValueWhen( xTrough, Bi, 1 );
xPeak_Bar_01 = ValueWhen( xPeak, Bi, 1 );
xTrough_Bar_Low_01 = xTrough;
xPeak_Bar_High_01 = xPeak;
xRecentPivot_Trough = IIf( xTrough_Bar_01 > xPeak_Bar_01, 1, 0 );
PT_Bar_Count = IIf( xRecentPivot_Trough == 1, abs( xPeak_Bar_01 - xTrough_Bar_01 ), Null );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function LookBack_LowestLow( Tr )
{
iLL_Value = Null;
for( i = 0; i < BarCount - 1; i++ )
{
if( xTrough[i] )
{
ii = i;
iL = 1e7; // I put this value to avoid any possible encounter with faulty zero-value operations.
//Loop-back the bars to find the lowest-low
for( j = 0; j < PT_Bar_Count[i]; j++ )
{
if( L[i - j] < iL )
{
ii = i - j;
iL = L[ii];
}
}
iLL_Value[ii] = iL; // set the array of the lowest-low
}
}
return iLL_Value;
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( Missed_High_Low_HandleSwitch == 1 )
{
Looped_LowestLow = LookBack_LowestLow( xTrough );
Missed_LowestLow = IIf( ( xRecentPivot_Trough == 1 ) AND( Looped_LowestLow <= xTrough ), 1, 0 );
xTrough = IIf( Missed_LowestLow == 1, 0, Looped_LowestLow );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "xPivot-Camparison" );
for( i = 0; i < 3; i++ )
{
VarSet( "xPeak_x" + i, ValueWhen( xPeak, Bi, i ) );
VarSet( "xTrough_x" + i, ValueWhen( xTrough, Bi, i ) );
VarSet( "xPeakHigh_" + i, ValueWhen( xPeak, PaH, i ) );
VarSet( "xTroughLow_" + i, ValueWhen( xTrough, PaL, i ) );
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xLL = xTrough AND xTroughLow_1 < xTroughLow_2; // LL = LowerLow
xHL = xTrough AND xTroughLow_1 > xTroughLow_2; // HL = HigherLow
xHH = xPeak AND xPeakHigh_1 > xPeakHigh_2; // HH = HigherHigh
xLH = xPeak AND xPeakHigh_1 < xPeakHigh_2; // LH = LowerHigh
xDT = xPeak AND xPeakHigh_1 == xPeakHigh_2; // DT = DoubleTop
xDB = xTrough AND xTroughLow_1 == xTroughLow_2; // DB = DoubleBottom
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xHH_Bar_01 = ValueWhen( xHH, Bi, 1 );
xLH_Bar_01 = ValueWhen( xLH, Bi, 1 );
xLL_Bar_01 = ValueWhen( xLL, Bi, 1 );
xHL_Bar_01 = ValueWhen( xHL, Bi, 1 );
xDT_Bar_01 = ValueWhen( xDT, Bi, 1 );
xDB_Bar_01 = ValueWhen( xDB, Bi, 1 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xHH_Bar_High_01 = ValueWhen( xHH, PaH );
xLH_Bar_High_01 = ValueWhen( xLH, PaH );
xLL_Bar_Low_01 = ValueWhen( xLL, PaL );
xHL_Bar_Low_01 = ValueWhen( xHL, PaL );
xDT_Bar_High_01 = ValueWhen( xDT, PaH );
xDB_Bar_Low_01 = ValueWhen( xDB, PaL );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
_SECTION_BEGIN( "xPivot Comparison-Lables" );
xPivotLabels_DisplaySwitch = ParamToggle( "Display xPivot-Labels", "No|Yes", 0 );
xPivotLabels_Zorder = Param( "xPivot-Label's Zorder", 5, -5, 5, 1 );
xLabel_Background_Color = ParamColor( "xPivot-Label's Background-Color", colorBlack );
xUpper_Label_Color = ParamColor( "xPivot's Upper-Label Color", colorYellow );
xLower_Label_Color = ParamColor( "xPivot's Lower-Lable Color", colorCustom11 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( xPivotLabels_DisplaySwitch )
{
GfxSetZOrder( xPivotLabels_Zorder );
for( i = 0; i < BarCount; i++ )
{
if( xLL[i] )
{
xString = "LL";
PlotTextSetFont( xString, Font_Name, Text_Size, i, Low[i], xLower_Label_Color, xLabel_Background_Color, -30 );
}
if( xHL[i] )
{
xString = "HL";
PlotTextSetFont( xString, Font_Name, Text_Size, i, Low[i], xLower_Label_Color, xLabel_Background_Color, -30 );
}
if( xDB[i] )
{
xString = "DB";
PlotTextSetFont( xString, Font_Name, Text_Size, i, Low[i], xLower_Label_Color, xLabel_Background_Color, -30 );
}
if( xHH[i] )
{
xString = "HH";
PlotTextSetFont( xString, Font_Name, Text_Size, i, High[i], xUpper_Label_Color, xLabel_Background_Color, 30 );
}
if( xLH[i] )
{
xString = "LH";
PlotTextSetFont( xString, Font_Name, Text_Size, i, High[i], xUpper_Label_Color, xLabel_Background_Color, 30 );
}
if( xDT[i] )
{
xString = "DT";
PlotTextSetFont( xString, Font_Name, Text_Size, i, High[i], xUpper_Label_Color, xLabel_Background_Color, 30 );
}
}
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// This entire section is also coded by me and therby some errors might be there. Because I am just a beginner in AFL coding.
// However after checking the output quite extensively and thoroughly, no errors have been found yet. But still I have doubt.
_SECTION_BEGIN( "Gfx-ZigZag" );
nZigZag_DisplaySwitch = ParamToggle( "Display nZigZag ", "No|Yes", 1 );
nPeakTrough_Shapes_DisplaySwitch = ParamToggle( "Display nPeak-Trough Shapes", "No|Yes", 0 );
nPeakTrough_SameBar_HandleSwitch = ParamToggle( "Handle nPeakTrough-@-SameBar", "No|Yes", 1 );
nZigZag_Line_Zorder = Param( "nZigZag's Line-Zorder", 5, -5, 5, 1 );
nZigZag_Line_Width = Param( "nZigZag's Line-Width", 2, 0, 5, 1 ); // If this value is 0, the width in device units is always 1 pixel, regardless of the mapping mode (this is useful for drawing hairline lines on printer outputs).
nZigZag_Line_Style = Param( "nZigZag's Line-Style", 0, 0, 5, 1 ); // Solid=0, Dash=1, Dot=2, Null=5 (Invisible-Pen).
nZigZag_Line_Color = ParamColor( "nZigZag's Line-Color", colorWhite );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
nPeak = xPeak;
nTrough = xTrough;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function Draw_UpLine( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, TroughBar_01, TroughBarLow_01, PeakBar_01, PeakBarHigh_01 )
{
GfxSetCoordsMode( GfxCoordsMode );
GfxSetZOrder( Line_Zorder );
GfxSelectPen( Line_Color, Line_Width, Line_Style );
GfxMoveTo( TroughBar_01, TroughBarLow_01 );
GfxLineTo( PeakBar_01, PeakBarHigh_01 );
}
function Draw_DownLine( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, PeakBar_01, PeakBarHigh_01, TroughBar_01, TroughBarLow_01 )
{
GfxSetCoordsMode( GfxCoordsMode );
GfxSetZOrder( Line_Zorder );
GfxSelectPen( Line_Color, Line_Width, Line_Style );
GfxMoveTo( PeakBar_01, PeakBarHigh_01 );
GfxLineTo( TroughBar_01, TroughBarLow_01 );
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function Draw_UpLine_PT_SameBar( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, TroughBar_02, TroughBarLow_02, PeakBar_01, PeakBarHigh_01 )
{
GfxSetCoordsMode( GfxCoordsMode );
GfxSetZOrder( Line_Zorder );
GfxSelectPen( Line_Color, Line_Width, Line_Style );
GfxMoveTo( TroughBar_02, TroughBarLow_02 );
GfxLineTo( PeakBar_01, PeakBarHigh_01 );
}
function Draw_DownLine_PT_SameBar( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, PeakBar_02, PeakBarHigh_02, TroughBar_01, TroughBarLow_01 )
{
GfxSetCoordsMode( GfxCoordsMode );
GfxSetZOrder( Line_Zorder );
GfxSelectPen( Line_Color, Line_Width, Line_Style );
GfxMoveTo( PeakBar_02, PeakBarHigh_02 );
GfxLineTo( TroughBar_01, TroughBarLow_01 );
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
function Draw_Line_PT_SameBar_to_PT_SameBar( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, TroughBar_02, TroughBarLow_02, PeakBar_01, PeakBarHigh_01 )
{
GfxSetCoordsMode( GfxCoordsMode );
GfxSetZOrder( Line_Zorder );
GfxSelectPen( Line_Color, Line_Width, Line_Style );
GfxMoveTo( TroughBar_02, TroughBarLow_02 );
GfxLineTo( PeakBar_01, PeakBarHigh_01 );
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( nZigZag_DisplaySwitch )
{
GfxCoordsMode = 1;
Line_Zorder = nZigZag_Line_Zorder;
Line_Color = nZigZag_Line_Color;
Line_Width = nZigZag_Line_Width;
Line_Style = nZigZag_Line_Style;
PeakBar_01 = ValueWhen( nPeak, Bi, 1 );
PeakBar_02 = ValueWhen( nPeak, Bi, 2 );
TroughBar_01 = ValueWhen( nTrough, Bi, 1 );
TroughBar_02 = ValueWhen( nTrough, Bi, 2 );
PeakBarHigh_01 = ValueWhen( nPeak, PaH, 1 );
PeakBarHigh_02 = ValueWhen( nPeak, PaH, 2 );
TroughBarLow_01 = ValueWhen( nTrough, PaL, 1 );
TroughBarLow_02 = ValueWhen( nTrough, PaL, 2 );
PeakTrough_SameBar_01 = ValueWhen( nPeak, Bi, 1 ) == ValueWhen( nTrough, Bi, 1 );
PeakTrough_SameBar_02 = ValueWhen( nPeak, Bi, 2 ) == ValueWhen( nTrough, Bi, 2 );
Recent_Previous_Pivot_Peak = ValueWhen( nPeak, Bi, 2 ) > ValueWhen( nTrough, Bi, 2 ) AND ValueWhen( nTrough, Bi, 1 ) > ValueWhen( nPeak, Bi, 2 );
Recent_Previous_Pivot_Trough = ValueWhen( nTrough, Bi, 2 ) > ValueWhen( nPeak, Bi, 2 ) AND ValueWhen( nPeak, Bi, 1 ) > ValueWhen( nTrough, Bi, 2 );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
for( i = 0; i < BarCount - 1; i++ )
{
Draw_UpLine( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, TroughBar_01[i], TroughBarLow_01[i], PeakBar_01[i], PeakBarHigh_01[i] );
Draw_DownLine( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, PeakBar_01[i], PeakBarHigh_01[i], TroughBar_01[i], TroughBarLow_01[i] );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( nPeakTrough_SameBar_HandleSwitch == 1 )
{
if( PeakTrough_SameBar_01[i] AND Recent_Previous_Pivot_Trough[i] )
{
Draw_UpLine_PT_SameBar( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, TroughBar_02[i], TroughBarLow_02[i], PeakBar_01[i], PeakBarHigh_01[i] );
}
if( PeakTrough_SameBar_01[i] AND Recent_Previous_Pivot_Peak[i] )
{
Draw_DownLine_PT_SameBar( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, PeakBar_02[i], PeakBarHigh_02[i], TroughBar_01[i], TroughBarLow_01[i] );
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( PeakTrough_SameBar_01[i] AND PeakTrough_SameBar_02[i] )
{
Draw_Line_PT_SameBar_to_PT_SameBar( GfxCoordsMode, Line_Zorder, Line_Color, Line_Width, Line_Style, TroughBar_02[i], TroughBarLow_02[i], PeakBar_01[i], PeakBarHigh_01[i] );
}
}
}
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if( nPeakTrough_Shapes_DisplaySwitch )
{
nPeak_Shape_Color = ParamColor( "nPeak Shape-Color", colorCustom12 );
nTrough_Shape_Color = ParamColor( "nTrough Shape-Color", colorYellow );
nPeak_Shape_Type = Param( "nPeak Shape-Type", 13, 0, 50, 1 );
nTrough_Shape_Type = Param( "nTrough Shape-Type", 13, 0, 50, 1 );
PlotShapes( nPeak_Shape_Type * nPeak, nPeak_Shape_Color, 0, High, 10 );
PlotShapes( nTrough_Shape_Type * nTrough, nTrough_Shape_Color, 0, Low, -10 );
}
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx