# Add a second "param" to a formula

Hi members, Promise that I searched and tryed to rewrite the formula. I saw a formula in the members area of amibroker ( ZigZag Trend Indicator). The formula have the param "amount" but that param change the value for both buy and sell signals. And I want to have two "params"; one for buy, one for sell signals. Thanks a lot. Somebody could suggest or help me with a solution? the formula is:

``````array = Close;
amount = Param("Amount", 15.5, 1, 50, 0.5 );
//amount_2_for_sell_signal = ?????

zz0 = Zig( array, amount );
zz1 = Ref( zz0, -1 );
zz2 = Ref( zz0, -2 );

tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1);
pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1);
PU = tr + 0.01 * abs(tr)*amount;
PD = pk - 0.01 * abs(pk)*amount;

ZZT = IIf( array >= PU AND zz0 > zz1, 1,
IIf( array <= PD AND zz0 < zz1, -1, 0 ) );

ZZT = ValueWhen( ZZT != 0, ZZT );

// plot price bar chart
Plot( Close, "Price", colorBlack, styleBar );

// plot Zigzag and zigzag trend
Plot( ZZT, "ZigZagTrend", colorRed, styleOwnScale );
Plot( zz0, "ZigZag line", colorBlue, styleThick );

// Plot the ribbon
ribboncol= IIf( ZZT > 0, colorGreen, colorRed );
Plot( 2, "ZZT Ribbon", ribboncol, styleArea | styleOwnScale | styleNoLabel, 0, 100 );

GraphXSpace = 10;

Buy = Cover = Cross( ZZT, 0 );
Sell = Short = Cross( 0, ZZT );

// plot arrows
PlotShapes( Buy + 2 * Sell, ribboncol, 0, IIf( Buy, L, H ), -30 );
``````

If you copy code from elsewhere then it is basic rule to add link to original source!

``````/// Original code
/// modified to use separate amounts
array = Close;
amount1 = Param("Amount1", 2, 1, 50, 0.5 );
amount2 = Param("Amount2", 5, 1, 50, 0.5 );

for ( i = 1; i <= 2; i++ ) {
amount = VarGet("amount" + i);
zz0 = Zig( array, amount );
zz1 = Ref( zz0, -1 );
zz2 = Ref( zz0, -2 );

tr = ValueWhen(zz0 > zz1 AND zz1 < zz2, zz1);
pk = ValueWhen(zz0 < zz1 AND zz1 > zz2, zz1);
PU = tr + 0.01 * abs(tr)*amount;
PD = pk - 0.01 * abs(pk)*amount;

ZZT = IIf( array >= PU AND zz0 > zz1, 1, IIf( array <= PD AND zz0 < zz1, -1, 0 ) );
ZZT = ValueWhen( ZZT != 0, ZZT );
VarSet( "zz0_"+i, zz0 );
VarSet( "ZZT"+i, ZZT );
}

// plot price bar chart
Plot( Close, "Price", colorBlack, styleBar );

// plot Zigzag and zigzag trend
Plot( ZZT1, "\nZigZagTrend1", colorRed, styleOwnScale );
Plot( ZZT2, "ZigZagTrend2", colorOrange, styleOwnScale );
Plot( zz0_1, "\nZigZag line1", colorBlue, styleThick );
Plot( zz0_2, "ZigZag line2", colorViolet, styleThick );

// Plot the ribbon
ribboncol1= IIf( ZZT1 > 0, colorGreen, colorRed );
ribboncol2= IIf( ZZT2 > 0, colorGreen, colorRed );
Plot( 1, "\nZZT Ribbon1", ribboncol1, styleArea | styleOwnScale | styleNoLabel, 0, 100 );
Plot( 2, "ZZT Ribbon2", ribboncol2, styleArea | styleOwnScale | styleNoLabel, 0, 100 );

GraphXSpace = 10;

Buy = Cross( ZZT1, 0 );
Sell = Cross( 0, ZZT2 );

Short = Cross( 0, ZZT1 );
Cover = Cross( ZZT2, 0 );

// plot arrows
PlotShapes( Buy + 2 * Sell, ribboncol1, 0, IIf( Buy, L, H ), -30 );
``````
3 Likes