SEGUE
_SECTION_BEGIN( "TEXT TO GANN SWING CHART" );
BarsOffset = Param("Shift Text Sideways", -1, -10, 0, 1);
dist = Param("Shift Text Up or Down", 1.2, 0.1, 10, 0.1)*ATR(200);
bi = BarIndex();
dt = DateTime();
textUPStartX = myGraph1 > Ref( MyGraph1, -1);
textDNStartX = myGraph1 < Ref( MyGraph1, -1);
UPsw = BarsSince( textUPStartX ) < BarsSince( textDNStartX ) ;
textUpStartBI = ValueWhen( textUPStartX , bi );
textUpEndBI = ValueWhen( textDnStartX , bi,0 );
textDnStartBI = ValueWhen( textDnStartX , bi );
textDnEndBI = ValueWhen( textUPStartX , bi,0 );
upBarsCount = ValueWhen( textDnStartX OR Lastbar, ValueWhen( H == myGraph1,
BarsSince(L == myGraph1) ),0 );
DnBarsCount = ValueWhen( textUPStartX OR Lastbar, ValueWhen( L == myGraph1,
BarsSince(H == myGraph1) ),0 );
DateUp = ValueWhen( textDnStartX OR Lastbar, ValueWhen( H == myGraph1, dt
),0 );
DateDn = ValueWhen( textUPStartX OR Lastbar, ValueWhen( L == myGraph1, dt ),0
);
TextUpPosition = bi == floor( (textUpEndBI + textUpStartBI)/2) AND Upsw;
TextDnPosition = bi == floor( (textDnEndBI + textDnStartBI)/2) AND NOT Upsw;
TextUpPosition = Ref(TextUpPosition , -BarsOffset);
TextDnPosition = Ref(TextDnPosition , -BarsOffset);
CurrentSwing = ValueWhen( textUPStartX OR textDNStartX, myGraph1);
PreviousSwing = ValueWhen( textUPStartX OR textDNStartX, Ref( myGraph1,-1) );
range = abs(CurrentSwing - PreviousSwing);
CurrentSwingShifted = Ref( CurrentSwing , -BarsOffset);
LevelUP = Ref( myGraph1, -BarsOffset) + dist;
LevelDN = Ref( myGraph1, -BarsOffset) - (dist*0.5); // Adjusted Level down
range = Ref( range , -BarsOffset);
upBarsCount = Ref( upBarsCount , -BarsOffset);
DnBarsCount = Ref( DnBarsCount , -BarsOffset);
DateUp = Ref( DateUp , -BarsOffset);
DateDn = Ref( DateDn , -BarsOffset);
if ( ( PlotType2 OR Plottype3 ) AND displaytext )
{
for ( i = 0; i < BarCount; i++ )
{
if ( TextUpPosition )
{
textUp = NumToStr( CurrentSwingShifted [ i ], 1.2, 0 )
+ "\n"
+ DateTimeToStr( DateUp [ i ] )
+ "\n"
+ "R:" + NumToStr( range[ i ], 1.2, 0 )
+ "\n"
+ "Bars:" + NumToStr( upBarsCount [ i ], 1 )
+ "\n" ;
PlotText( textUp , i, LevelUP[ i ], UpTextColor );
}
if ( TextDnPosition )
{
textDn = NumToStr( CurrentSwingShifted [ i ], 1.2, 0 )
+ "\n"
+ DateTimeToStr( DateDn [ i ] )
+ "\n"
+ "R: " + NumToStr( range[ i ], 1.2, 0 )
+ "\n"
+ "Bars: " + NumToStr( DnBarsCount [ i ], 1 )
+ "\n";
PlotText( textDn , i, LevelDN[ i ], DnTextColor );
}
}
}
if ( DisplaySwing AND PlotType2 )
{
Plot( myGraph1, "Swing Chart", swingColor, styleStaircase, Null, Null, 0,
0, SwingWidth );
}
if ( DisplaySwing AND PlotType3 )
{
Plot( myGraph1, "Swing Chart", swingColor, styleStaircase | styleSwingDots,
Null, Null, 0, Zorder = 1 );
}
if ( displayEMA AND PlotType2 )
{
Plot( EMA( Close, 200 ), "",colorTurquoise, styleLine|styleNoRescale, Null,
Null, 0, 0, EMAWidth );
Plot( EMA( Close, 50 ), "",colorLime, styleLine|styleNoRescale, Null, Null,
0, 0, EMAWidth );
Plot( EMA( Close, 20 ), "",colorBlue, styleLine|styleNoRescale, Null, Null,
0, 0, EMAWidth );
}
if ( displayEMA AND PlotType3 )
{
Plot( EMA( Close, 200 ), "",colorTurquoise, styleLine|styleNoRescale );
Plot( EMA( Close, 50 ), "",colorLime, styleLine|styleNoRescale);
Plot( EMA( Close, 20 ), "",colorBlue, styleLine|styleNoRescale );
}
//equal width swings
bars = Param( "MODE 1 - Equal bars swing width", 5, 3, 10, 1 );
Count = 2;
myVal = LastValue( myGraph1 );
myNewChart = Null;
myNewChart[ BarCount-1 ] = myVal;
positionUp = IIf( LastValue( BarsSince( textUpStartX ) < BarsSince(
textDnStartX ) ), 1, -1 );//-1
if ( PlotType1 )
{
j = BarCount - 1;
for ( i = BarCount - 1; i > 0; i-- )
{
if ( Count == ceil( bars / 2 ) - BarsOffset )
{
bar = Max( 0, Min( j + BarsOffset, BarCount - 1 ) );
bbarsCount = IIf( positionUp == 1, upBarsCount [ bar ],
dnBarsCount [ bar ] );
bdate = IIf( positionUp == 1, DateUp[ bar ], DateDn[ bar ] );
dist2 = IIf( positionup == 1, dist, dist * 0.4 ); // Made up
dist2 to raise the lower swing text
textUp = NumToStr( CurrentSwingShifted [ bar ], 1.2, 0 )
+ "\n"
+ DateTimeToStr( bdate [ bar ] )
+ "\n"
+ "R:" + NumToStr( range[ bar ], 1.2, 0 )
+ "\n"
+ "Bars:" + NumToStr( bbarsCount , 1 )
+ "\n" ;
PlotText( textUp , i, myVal + positionUp * dist2[ j ], IIf(
positionUp == 1, UpTextColor, DnTextColor) );
}
if ( Count < bars )
{
myNewChart[ i ] = myVal;
Count++;
}
else
{
while ( mygraph1[ j ] == myVal AND j > 0 )
{
j--;
}
myNewChart[ i ] = myVal;
myVal = myGraph1[ j ];
Count = 1;
positionUp *= -1;
}
}
Plot( myNewChart, "Swing Chart", ParamColor( "Equal Swing Color",
colorBlack ), styleSwingDots | styleStaircase, Null, Null, 0, 0, EMAWidth );
}
_SECTION_END();
_SECTION_BEGIN( "TEXT TO GANN SWING CHART" );
BarsOffset = Param("Shift Text Sideways", -1, -10, 0, 1);
dist = Param("Shift Text Up or Down", 1.2, 0.1, 10, 0.1)*ATR(200);
bi = BarIndex();
dt = DateTime();
textUPStartX = myGraph1 > Ref( MyGraph1, -1);
textDNStartX = myGraph1 < Ref( MyGraph1, -1);
UPsw = BarsSince( textUPStartX ) < BarsSince( textDNStartX ) ;
textUpStartBI = ValueWhen( textUPStartX , bi );
textUpEndBI = ValueWhen( textDnStartX , bi,0 );
textDnStartBI = ValueWhen( textDnStartX , bi );
textDnEndBI = ValueWhen( textUPStartX , bi,0 );
upBarsCount = ValueWhen( textDnStartX OR Lastbar, ValueWhen( H == myGraph1,
BarsSince(L == myGraph1) ),0 );
DnBarsCount = ValueWhen( textUPStartX OR Lastbar, ValueWhen( L == myGraph1,
BarsSince(H == myGraph1) ),0 );
DateUp = ValueWhen( textDnStartX OR Lastbar, ValueWhen( H == myGraph1, dt
),0 );
DateDn = ValueWhen( textUPStartX OR Lastbar, ValueWhen( L == myGraph1, dt ),0
);
TextUpPosition = bi == floor( (textUpEndBI + textUpStartBI)/2) AND Upsw;
TextDnPosition = bi == floor( (textDnEndBI + textDnStartBI)/2) AND NOT Upsw;
TextUpPosition = Ref(TextUpPosition , -BarsOffset);
TextDnPosition = Ref(TextDnPosition , -BarsOffset);
CurrentSwing = ValueWhen( textUPStartX OR textDNStartX, myGraph1);
PreviousSwing = ValueWhen( textUPStartX OR textDNStartX, Ref( myGraph1,-1) );
range = abs(CurrentSwing - PreviousSwing);
CurrentSwingShifted = Ref( CurrentSwing , -BarsOffset);
LevelUP = Ref( myGraph1, -BarsOffset) + dist;
LevelDN = Ref( myGraph1, -BarsOffset) - (dist*0.5); // Adjusted Level down
range = Ref( range , -BarsOffset);
upBarsCount = Ref( upBarsCount , -BarsOffset);
DnBarsCount = Ref( DnBarsCount , -BarsOffset);
DateUp = Ref( DateUp , -BarsOffset);
DateDn = Ref( DateDn , -BarsOffset);
if ( ( PlotType2 OR Plottype3 ) AND displaytext )
{
for ( i = 0; i < BarCount; i++ )
{
if ( TextUpPosition )
{
textUp = NumToStr( CurrentSwingShifted [ i ], 1.2, 0 )
+ "\n"
+ DateTimeToStr( DateUp [ i ] )
+ "\n"
+ "R:" + NumToStr( range[ i ], 1.2, 0 )
+ "\n"
+ "Bars:" + NumToStr( upBarsCount [ i ], 1 )
+ "\n" ;
PlotText( textUp , i, LevelUP[ i ], UpTextColor );
}
if ( TextDnPosition )
{
textDn = NumToStr( CurrentSwingShifted [ i ], 1.2, 0 )
+ "\n"
+ DateTimeToStr( DateDn [ i ] )
+ "\n"
+ "R: " + NumToStr( range[ i ], 1.2, 0 )
+ "\n"
+ "Bars: " + NumToStr( DnBarsCount [ i ], 1 )
+ "\n";
PlotText( textDn , i, LevelDN[ i ], DnTextColor );
}
}
}
if ( DisplaySwing AND PlotType2 )
{
Plot( myGraph1, "Swing Chart", swingColor, styleStaircase, Null, Null, 0,
0, SwingWidth );
}
if ( DisplaySwing AND PlotType3 )
{
Plot( myGraph1, "Swing Chart", swingColor, styleStaircase | styleSwingDots,
Null, Null, 0, Zorder = 1 );
}
if ( displayEMA AND PlotType2 )
{
Plot( EMA( Close, 200 ), "",colorTurquoise, styleLine|styleNoRescale, Null,
Null, 0, 0, EMAWidth );
Plot( EMA( Close, 50 ), "",colorLime, styleLine|styleNoRescale, Null, Null,
0, 0, EMAWidth );
Plot( EMA( Close, 20 ), "",colorBlue, styleLine|styleNoRescale, Null, Null,
0, 0, EMAWidth );
}
if ( displayEMA AND PlotType3 )
{
Plot( EMA( Close, 200 ), "",colorTurquoise, styleLine|styleNoRescale );
Plot( EMA( Close, 50 ), "",colorLime, styleLine|styleNoRescale);
Plot( EMA( Close, 20 ), "",colorBlue, styleLine|styleNoRescale );
}
//equal width swings
bars = Param( "MODE 1 - Equal bars swing width", 5, 3, 10, 1 );
Count = 2;
myVal = LastValue( myGraph1 );
myNewChart = Null;
myNewChart[ BarCount-1 ] = myVal;
positionUp = IIf( LastValue( BarsSince( textUpStartX ) < BarsSince(
textDnStartX ) ), 1, -1 );//-1
if ( PlotType1 )
{
j = BarCount - 1;
for ( i = BarCount - 1; i > 0; i-- )
{
if ( Count == ceil( bars / 2 ) - BarsOffset )
{
bar = Max( 0, Min( j + BarsOffset, BarCount - 1 ) );
bbarsCount = IIf( positionUp == 1, upBarsCount [ bar ],
dnBarsCount [ bar ] );
bdate = IIf( positionUp == 1, DateUp[ bar ], DateDn[ bar ] );
dist2 = IIf( positionup == 1, dist, dist * 0.4 ); // Made up
dist2 to raise the lower swing text
textUp = NumToStr( CurrentSwingShifted [ bar ], 1.2, 0 )
+ "\n"
+ DateTimeToStr( bdate [ bar ] )
+ "\n"
+ "R:" + NumToStr( range[ bar ], 1.2, 0 )
+ "\n"
+ "Bars:" + NumToStr( bbarsCount , 1 )
+ "\n" ;
PlotText( textUp , i, myVal + positionUp * dist2[ j ], IIf(
positionUp == 1, UpTextColor, DnTextColor) );
}
if ( Count < bars )
{
myNewChart[ i ] = myVal;
Count++;
}
else
{
while ( mygraph1[ j ] == myVal AND j > 0 )
{
j--;
}
myNewChart[ i ] = myVal;
myVal = myGraph1[ j ];
Count = 1;
positionUp *= -1;
}
}
Plot( myNewChart, "Swing Chart", ParamColor( "Equal Swing Color",
colorBlack ), styleSwingDots | styleStaircase, Null, Null, 0, 0, EMAWidth );
}
_SECTION_END();