Display Swing HH and Swing LL in Charts

BuyPrice=ValueWhen(Buy,o);

could you please advise how to amend the above line so that the buy price is the actual buy price not the open/close of the candle.

not sure what you mean, I already added the entry/exit price, see code below

// Fractal Pivots, E.M.Pottasch 2/2018
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

rightstrength = Param( "Right Strength", 5, 2, 50, 1 );
leftstrength = Param( "Left Strength", 5, 2, 50, 1 );
fact = Param( "Chart Time Frame Factor", 2, 1, 10, 1 );

rightStrength = rightStrength * fact;
leftStrength = leftStrength * fact;

pk = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
pkl = H == HHV( H, leftstrength );
trl = L == LLV( L, leftstrength );

for( i = 0; i < 3; i++ )
{
    VarSet( "px" + i, ValueWhen( pk, bi, i ) );
    VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
    VarSet( "ph" + i, ValueWhen( pk, H, i ) );
    VarSet( "tl" + i, ValueWhen( tr, L, i ) );
}

ll = tr AND tl1 < tl2;
hl = tr AND tl1 > tl2;
hh = pk AND ph1 > ph2;
lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );

PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 0, 255 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );
PlotShapes( shapeSmallCircle * trl, ColorRGB( 80, 0, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pkl, ColorRGB( 0, 80, 0 ), 0, H, 10 );

for( i = lvb; i > fvb; i-- )
{
    // troughs
    if( ll[i] )
    {
        str = "LL";
        PlotTextSetFont( str, "Arial Black", 8, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    if( hl[i] )
    {
        str = "HL";
        PlotTextSetFont( str, "Arial Black", 8, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    if( db[i] )
    {
        str = "DB";
        PlotTextSetFont( str, "Arial Black", 8, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    //peaks
    if( hh[i] )
    {
        str = "HH";
        PlotTextSetFont( str, "Arial Black", 8, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( lh[i] )
    {
        str = "LH";
        PlotTextSetFont( str, "Arial Black", 8, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( dt[i] )
    {
        str = "DT";
        PlotTextSetFont( str, "Arial Black", 8, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }
}

Title = Name() +
        " | " + Now( 2 ) +
        " | " + "Pivot Timeframe Factor: " + fact;


Plot( tl1, "", colorRed, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( ph1, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

// trading system
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "CommissionMode", 3 );
SetOption( "CommissionAmount", 3.5 );
SetOption( "FuturesMode", True );
NumContracts = 1;
PositionSize = NumContracts * MarginDeposit;
SetOption( "MaxOpenPositions", 1 );

Buy = Cross( H, Ref( ph1, -1 ) );
BuyPrice = Max( O, Ref( ph1, -1 ) );
Short = Cross( Ref( tl1, -1 ), L );
ShortPrice = Min( O, Ref( tl1, -1 ) );
Buy = ExRem( Buy, Short );
Short = ExRem( Short, Buy );
Sell = Short;
Cover = Buy;
SellPrice = ShortPrice;
CoverPrice = BuyPrice;

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), ColorRGB( 0, 255, 255 ), 0, L, -15 );
PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorLightBlue, 0, BuyPrice, 0 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), ColorRGB( 255, 165, 0 ), 0, H, -15 );
PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorOrange, 0, SellPrice, 0 );
PlotShapes( IIf( Short, shapeSmallDownTriangle, shapeNone ), ColorRGB( 255, 165, 0 ), 0, H, IIf( Short AND Sell, -30, -15 ) );
PlotShapes( IIf( Short, shapeSmallCircle, shapeNone ), colorWhite, 0, ShortPrice, 0 );
PlotShapes( IIf( Cover, shapeSmallUpTriangle, shapeNone ), ColorRGB( 0, 255, 255 ), 0, L, IIf( Cover AND Buy, -30, -15 ) );
PlotShapes( IIf( Cover, shapeSmallCircle, shapeNone ), colorWhite, 0, CoverPrice, 0 );
3 Likes

I just added my code in addition to your above code .

so in general i asked how to catch the actual buy price instead of the open/close of the candle in which the buy happens.

I modified your code to detect a double top formation.
I have detected successfully both tops but I have a problem in getting the peak bars.
The first peak bars is correct but the problem is in the second peak bars.
Any help will be appreciated.
Here is the modified code:

// DOUBLE TOP EXPLORATION

rightstrength = Param( "Right Strength", 5, 2, 50, 1 );
leftstrength = Param( "Left Strength", 5, 2, 50, 1 );
fact = Param( "Chart Time Frame Factor", 2, 1, 10, 1 );
ATR1=ATR(30);
MUL=3;  //ATRMULTIPLE
rightStrength = rightStrength * fact;
leftStrength = leftStrength * fact;

pk = H == HHV( H, leftstrength ) AND H>Ref( HHV( H, rightstrength ), rightstrength )  AND H>MUL*ATR1+LLV(L,leftstrength) 
AND H>MUL*ATR1+Ref(LLV(L,rightstrength),rightstrength);

pkl = H == HHV( H, leftstrength );

for( i = 0; i < 3; i++ )
{    
    VarSet( "ph" + i, ValueWhen( pk, H, i ) );
    }
pkbars1=BarsSince(H == ph1);
 pkbars2=BarsSince(H==ph2);
FILTER =C> 0; 

AddColumn(Close,"Close",1.4);
AddColumn(ph1,"ph1",1.2);
AddColumn(pkbars1,"pkbars1",1);
AddColumn(ph2,"ph2",1.2);
AddColumn(pkbars2,"pkbars2",1);

Hello,
just a thought, instead displaying word SH and SL, how can we display the swing high price and swing low price instead?

thanks

I am not sure I understand your method. But I would look for 2 adjacent peaks that are close at the same level using the following:

// Fractal Pivots, E.M.Pottasch 2/2018
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

rightstrength = Param( "Right Strength", 5, 1, 50, 1 );
leftstrength = Param( "Left Strength", 5, 1, 50, 1 );
fact = Param( "Chart Time Frame Factor", 2, 1, 10, 1 );

rightStrength = rightStrength * fact;
leftStrength = leftStrength * fact;

pk = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
pkl = H == HHV( H, leftstrength );
trl = L == LLV( L, leftstrength );

for( i = 0; i < 3; i++ )
{
    VarSet( "px" + i, ValueWhen( pk, bi, i ) );
    VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
    VarSet( "ph" + i, ValueWhen( pk, H, i ) );
    VarSet( "tl" + i, ValueWhen( tr, L, i ) );
}

ll = tr AND tl1 < tl2;
hl = tr AND tl1 > tl2;
hh = pk AND ph1 > ph2;
lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );

//PlotShapes( shapeSmallCircle * trl, ColorRGB( 80, 0, 0 ), 0, L, -10 );
//PlotShapes( shapeSmallCircle * pkl, ColorRGB( 0, 80, 0 ), 0, H, 10 );
PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 255, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );

doubleTopThreshold = 0.75 * Ref( ATR( 20 ), -1 );
doubleTop = pk && abs( ph1 - ph2 ) < doubleTopThreshold;

for( i = lvb; i > fvb; i-- )
{
    sz = 8;

    // troughs
    if( ll[i] )
    {
        str = "LL";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    if( hl[i] )
    {
        str = "HL";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    if( db[i] )
    {
        str = "DB";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    //peaks
    if( hh[i] )
    {
        str = "HH";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( lh[i] )
    {
        str = "LH";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( dt[i] )
    {
        str = "DT";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( doubleTop[i] )
    {
        str = "Double Top";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 125, 0 ), colorDefault, 40 );
    }
}

Title = Name() +
        " | " + Now( 2 ) +
        " | " + "Pivot Timeframe Factor: " + fact;

1 Like

to add the price you can do this => example for lower low.

    if( ll[i] )
    {
        str = "LL / " + L[i];
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

2 Likes

thank you!
@empottasch how to code how many bars since previous bars is happend? lets say we don't want to buy breakout if bars since previous HH are only 3 bars before the breakout occur...

thanks

you can use barssince,

so for instance:

Buy = Cross( H, ph1 ) && BarsSince( pk ) > 10;
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), ColorRGB( 0, 255, 255 ), 0, L, -15 );

@awilson
using valuewhen & iif give exact result…..

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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Lower = Low < Ref(LLV(Low, 4), -1);
scLow = ValueWhen(Lower, Low,1);
scLower = scLow < Ref(scLow, -1);
Lower = IIf(Lower, scLower,Null);

Higher = High > Ref(HHV(High, 4), -1);
scHigh = ValueWhen(Higher,High,1);
scHigher = scHigh > Ref(scHigh, -1);
Higher = IIf(Higher, scHigher,Null);

barsSinceBot = LowestSinceBars(Higher, Low);
PlotShapes( IIf(barsSinceBot==0 AND Lower, shapeUpArrow, shapeNone), colorGreen, 0, Low, -10 );

barsSinceTop = HighestSinceBars(Lower, High);
PlotShapes( IIf(barsSinceTop==0 AND Higher, shapeDownArrow, shapeNone), colorRed, 0, High, -19);

@Tomasz
What’s your thought process behind sparsecompress is it any trading related idea or just for coding ease……

@Fossil Try this one How can I make only current date's graph as intraday( 5min / 10 min interval etc) and older data as daily using AFL?

2 Likes

@awilson
Not fair …. just learn pronouncing & you telling me to read a complete sentence :sweat_smile::sweat_smile:
anyway that’s a good code.....

Hi,
I am using amibroker with AFL’s available in websites. I don’t have any programming knowledge. That’s why I could not able to use my strategies and make profits.
So could please edit this swing low/ high AFL as per the following criteria’s:

  1. I will consider only “x” points (Instead of %) movements for a swing, this could be editable (eg: 20 points, no upper limit), anything lesser than that should be avoided.
  2. I also want to export these data as CSV file. (Candle time, Swing H/L values)

THANKS IN ADVANCE.

/*
Zig-Hi-Zag-Lo

To use to plot the true Peak High and Trough Low
for study of chart pattern, to create trading system

Modified from http://trader.online.pl/MSZ/e-w-ZigZag_HiLo.html

By TohMz
*/
pr=Param("ZigZag change amount", 5, 0.1,100,0.1);

pk=PeakBars(H,pr)==0;
tr=TroughBars(L,pr)==0;

zzHi=Zig(H,pr);
zzLo=Zig(L,pr);
Avg=(zzHi+zzLo)/2;

x=IIf(pk,zzHi,IIf(tr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
zzHiLo=Zig(x,pr);

Plot( zzHiLo, "", ParamColor("Color",colorYellow), ParamStyle("Style"));

//-- Delete below, to allow attach to any price chart
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
PriceStyle = GetPriceStyle();
PriceStyleOpt = ParamStyle("Style") | PriceStyle;

if (PriceStyle==styleCandle)
Plot( C, "", colorBlack, PriceStyleOpt);
else
Plot( C, "", IIf( Close >= Ref(C, -1), colorBlue, colorRed ), PriceStyleOpt);

have a look at this code:

it is pretty nice and is actually profitable with futures like gold and oil in the 1 hour timeframe, although not fantastically but still pretty nice code

Thank you very much for your reply.

I simply want to mark all swings which moved more than a specific points (Eg: 20 points), That swing continues until whenever there is an opposite move more than 20 points.
The above code marks all swings using a %. I just want to change it with points movement and need to export these data to CSC file.

Swing%20Low%20High

you can just add the point distance. My code uses ATR not percent. See code example below. You can for instance just show the label if the threshold is exceeded. But you need to start coding yourself else you will not learn

im1

// E.M.Pottasch, 3/2018
// ATR ZigZag
// http://forum.amibroker.com/t/help-me-understand-peakbars-troughbars/5072

// OptimizerSetEngine( "cmae" );
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "CommissionMode", 3 );
SetOption( "CommissionAmount", 2.32 );
SetOption( "FuturesMode", True );
NumContracts = 1;
PositionSize = NumContracts * MarginDeposit;
SetOption( "MaxOpenPositions", 4 );

function ParamOptimize( pname, defaultval, minv, maxv, step )
{
    return Optimize( pname,
                     Param( pname, defaultval, minv, maxv, step ),
                     minv, maxv, step );
}

// perBull = Param( "perBull", 50, 1, 300, 1 );
perBull = perBear = ParamOptimize( "perBear", 50, 1, 300, 1 );
// multBull = ParamOptimize( "multBull", 10, 1, 20, 0.1 );
multBull = multBear = ParamOptimize( "multBear", 10, 1, 20, 0.1 );
shiftLabels = Param( "Shift Labels", 12, -20, 100, 1 );
labelsswitch = ParamToggle( "Show Labels", "Off|On", 1 );
sz = Param( "Font Size", 8, 4, 16, 1 );

upColor = ColorRGB( 0, 250, 250 );
dnColor = ColorRGB( 250, 250, 0 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

sup = C - multBull * ATR( perBull );
res = C + multBear * ATR( perBear );

trailArray = Null;
trailstop = 0;

for( i = 1; i < BarCount; i++ )
{
    if( C[ i ] > trailstop AND C[ i - 1 ] > trailstop )
        trailstop = Max( trailstop, sup[ i ] );
    else
        if( C[ i ] < trailstop AND C[ i - 1 ] < trailstop )
            trailstop = Min( trailstop, res[ i ] );
        else
            trailstop = IIf( C[ i ] > trailstop, sup[ i ], res[ i ] );

    trailArray[ i ] = trailstop;
}

dntrend = ts = IIf( trailArray > C, trailArray, Null ); // dntrend
uptrend = tl = IIf( trailArray < C, trailArray, Null ); // uptrend

lll = LLV( L, BarsSince( !IsEmpty( tl ) ) );
//lll = LowestSince( !IsEmpty( tl ), L );
lll = IIf( ts, lll, Null );
trm = ts AND L == lll;

hhh = HHV( H, BarsSince( !IsEmpty( ts ) ) );
//hhh = HighestSince( !IsEmpty( ts ), H );
hhh = IIf( tl, hhh, Null );
pkm = tl AND H == hhh;

tr = ExRem( Reverse( trm ), Reverse( pkm ) );
pk = ExRem( Reverse( pkm ), Reverse( trm ) );

tr = Reverse( tr );
pk = Reverse( pk );

for( i = 0; i < 3; i++ )
{
    VarSet( "px" + i, ValueWhen( pk, bi, i ) );
    VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
    VarSet( "ph" + i, ValueWhen( pk, H, i ) );
    VarSet( "tl" + i, ValueWhen( tr, L, i ) );
}

ll = tr AND tl1 < tl2;
hl = tr AND tl1 > tl2;
hh = pk AND ph1 > ph2;
lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

trn = LowestSince( pk, L ) == L && dntrend;
pkn = HighestSince( tr, H ) == H && uptrend;

Buy = uptrend && IsEmpty( dntrend );
BuyPrice = C;
Short = dntrend && IsEmpty( uptrend );
ShortPrice = C;
Buy = ExRem( Buy, Short );
Short = ExRem( Short, Buy );

Sell = Short;
SellPrice = C;
Cover = Buy;
CoverPrice = C;

BuyPrice = ValueWhen( Buy, BuyPrice );
ShortPrice = ValueWhen( Short, ShortPrice );
CoverPrice = ValueWhen( Cover, CoverPrice );
SellPrice = ValueWhen( Sell, SellPrice );

longResult = Prec( IIf( Sell, SellPrice - ValueWhen( Buy, BuyPrice ), 0 ), 2 );
shortResult = Prec( IIf( Cover, ValueWhen( Short, ShortPrice ) - CoverPrice, 0 ), 2 );

GraphGridZOrder = 0;
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
Plot( ts, "Buy Trigger", upColor, styleDashed | styleStaircase | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 1 );
Plot( tl, "Short Trigger", dnColor, styleDashed | styleStaircase | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 1 );
Plot( 1, "", IIf( uptrend, ColorRGB( 0, 0, 20 ), ColorRGB( 20, 0, 0 ) ), styleArea | styleOwnScale | styleNoLabel | styleNoRescale, 0, 1, 0, -2, 5 );
PlotShapes( shapeSmallCircle * trn, ColorRGB( 0, 60, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pkn, ColorRGB( 80, 0, 0 ), 0, H, 10 );
PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 255, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), upColor, 0, L, -15 );
PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), upColor, 0, BuyPrice, 0 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), dnColor , 0, H, -15 );
PlotShapes( IIf( Short, shapeSmallCircle, shapeNone ), dnColor, 0, ShortPrice, 0 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), upColor, 0, L, -15 );
PlotShapes( IIf( Cover, shapeSmallCircle, shapeNone ), upColor, 0, CoverPrice, 0 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), dnColor , 0, H, -15 );
PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), dnColor, 0, SellPrice, 0 );

dup = ph1 - tl1;
ddn = tl1 - ph1;

ft = "Helvetica";
clr = ColorRGB( 10, 10, 10 );//colorDefault;
GfxSetZOrder( 0 );
GfxSetCoordsMode( 1 );

if( labelsswitch )
{
    for( i = fvb; i <= lvb; i++ )
    {
        if( Buy[i] && Cover[i] )
        {
            str = "Buy: " + BuyPrice[i];
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -35 - shiftLabels );
            str = "Cover: " + CoverPrice[i] + " (" + shortResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -50 - shiftLabels );
        }

        if( !Buy[i] && Cover[i] )
        {
            str = "Cover: " + CoverPrice[i] + " (" + shortResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -35 - shiftLabels );
        }

        if( Buy[i] && !Cover[i] )
        {
            str = "Buy: " + BuyPrice[i];
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -35 - shiftLabels );
        }

        if( Short[i] && Sell[i] )
        {
            str = "Short: " + ShortPrice[i];
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 25 + shiftLabels );
            str = "Sell: " + SellPrice[i] + " (" + longResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 40 + shiftLabels );
        }

        if( !Short[i] && Sell[i] )
        {
            str = "Sell: " + SellPrice[i] + " (" + longResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 25 + shiftLabels );
        }

        if( Short[i] && !Sell[i] )
        {
            str = "Short: " + ShortPrice[i];
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 25 + shiftLabels );
        }

        if( ll[i] )
        {
            str = "LL";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
        }

        if( hl[i] )
        {
            str = "HL";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
        }

        if( db[i] )
        {
            str = "DB";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
        }

        if( hh[i] )
        {
            str = "HH";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 20 );
        }

        if( lh[i] )
        {
            str = "LH";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 20 );
        }

        if( dt[i] )
        {
            str = "DT";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 20 );
        }

        if( tr[i] )
        {
            GfxSelectPen( dnColor, 1 );
            GfxMoveTo( tx1[i], tl1[i] );
            GfxLineTo( px1[i], ph1[i] );
            PlotTextSetFont( "" + Prec( ddn[i], 2 ), ft, sz, i, L[i], colorBlack, colorWhite, -50 );
        }

        if( pk[i] )
        {
            GfxSelectPen( upColor, 1 );
            GfxMoveTo( px1[i], ph1[i] );
            GfxLineTo( tx1[i], tl1[i] );
            PlotTextSetFont( "" + Prec( dup[i], 2 ), ft, sz, i, H[i], ColorBlack, colorWhite, 40 );
        }
    }
}
7 Likes

Thank you very much. I will try to learn AFL.

Can you please help me to export these swing high/ low values to excel (csv file)?

i suggest to study code by Graham: http://amibroker.com/members/library/formula.php?id=327

also look in the manual for the functions "fopen", "fputs". Actually in the manual "fputs" has an example how to do it.

1 Like