pls help to Plot Stop Loss and T1,T2 levels

pareshR

Well-Known Member
#1
i got this afl from : www.traderji.com/amibroker/94785-amibroker-ib.html


pls help to plots " Stop Loss and T1,T2 levels "


thx



StopMode = ParamList("Stop Mode", "Fixed|Chandelier|Modified ATR" );

StopLevel = Param("Fixed perc %", 1, 0.1, 5, 0.1)/100;


StopATRFactor = Param("ATR multiple", 4, 0.5, 10, 0.1 );
StopATRPeriod = Param("ATR period", 14, 3, 50,1 );



// calculate support and resistance levels
if( StopMode == "Fixed" ) // fixed percent trailing stop
{
sup = C * ( 1 - stoplevel );
res = C * ( 1 + stoplevel );
}
else // Chandelier ATR-based stop
if( StopMode == "Chandelier" )
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}
else
{
HL = H - L;
MAHL = 1.5 * MA( HL, StopATRPeriod );
HiLo = IIf( HL < MAHL, HL, MAHL );
H1 = Ref( H, -1 );
L1 = Ref( L, -1 );
C1 = Ref( C, -1 );
Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 );
Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 );

diff1 = Max( HiLo, HRef );
diff2 = Max( diff1, LRef );

ATRmod = Wilders( diff2, StopATRPeriod );

sup = C - StopATRFactor * ATRmod ;
res = C + StopATRFactor * ATRmod ;
}

// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
//if( Started[ i ] == 0 ) continue;

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;
}

// generate buy/sell signals based on crossover with trail stop line
Buy = Cross( C, trailArray );
Sell = Cross( trailArray, C );

PlotShapes(Buy*shapeUpArrow,colorGreen,0,trailarray);
PlotShapes(Sell*shapeDownArrow,colorRed,0,trailarray);

//
GraphXSpace = 4;
dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy@ \n@" + C[ i ], i, L[ i ]-dist, colorYellow, colorBlue );
if( Sell ) PlotText( "Sell@ \n@" + C[ i ], i, H[ i ]+dist, colorYellow, colorRed );

}

AlertIf( Buy, "SOUND C:\\Windows\\Media\\disconnect_11.wav", "Audio alert", 1 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\cuckoo.wav", "Audio alert", 2 );


//Plot( Close,"Price",colorBrightGreen,styleBar);
Plot( Close,"Price",colorBrightGreen,styleCandle);

//SetBarFillColor( colorYellow );
TRAILCOLOR =IIf(C>trailARRAY,colorBlue,colorRed);
Plot( trailARRAY,"trailing stop level", TRAILCOLOR, styleStaircase) ;

//Plot( trailARRAY,"Trailing SL", TRAILCOLOR, styleStaircase) ;
 
#2
corrected....


StopMode = ParamList("Stop Mode", "Fixed|Chandelier|Modified ATR" );

StopLevel = Param("Fixed perc %", 1, 0.1, 5, 0.1)/100;


StopATRFactor = Param("ATR multiple", 4, 0.5, 10, 0.1 );
StopATRPeriod = Param("ATR period", 14, 3, 50,1 );



// calculate support and resistance levels
if( StopMode == "Fixed" ) // fixed percent trailing stop
{
sup = C * ( 1 - stoplevel );
res = C * ( 1 + stoplevel );
}
else // Chandelier ATR-based stop
if( StopMode == "Chandelier" )
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}
else
{
HL = H - L;
MAHL = 1.5 * MA( HL, StopATRPeriod );
HiLo = IIf( HL < MAHL, HL, MAHL );
H1 = Ref( H, -1 );
L1 = Ref( L, -1 );
C1 = Ref( C, -1 );
Href = IIf( L <= H1, H - C1, ( H - C1 ) - ( L - H1 ) / 2 );
Lref = IIf( H >= L1, C1 - L, ( C1 - L ) - ( L1 - H ) / 2 );

diff1 = Max( HiLo, HRef );
diff2 = Max( diff1, LRef );

ATRmod = Wilders( diff2, StopATRPeriod );

sup = C - StopATRFactor * ATRmod ;
res = C + StopATRFactor * ATRmod ;
}

// calculate trailing stop line
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
//if( Started[ i ] == 0 ) continue;

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;
}

// generate buy/sell signals based on crossover with trail stop line
Buy = Cross( C, trailArray );
Sell = Cross( trailArray, C );

PlotShapes(Buy*shapeUpArrow,colorGreen,0,trailarray);
PlotShapes(Sell*shapeDownArrow,colorRed,0,trailarray);

//
GraphXSpace = 4;
dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
if( Buy ) PlotText( "Buy@ \n@" + C[ i ], i, L[ i ]-dist, colorYellow, colorBlue );
if( Sell ) PlotText( "Sell@ \n@" + C[ i ], i, H[ i ]+dist, colorYellow, colorRed );

}

AlertIf( Buy, "SOUND C:\\Windows\\Media\\disconnect_11.wav", "Audio alert", 1 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\cuckoo.wav", "Audio alert", 2 );


//Plot( Close,"Price",colorBrightGreen,styleBar);
Plot( Close,"Price",colorBrightGreen,styleCandle);

//SetBarFillColor( colorYellow );
TRAILCOLOR =IIf(C>trailARRAY,colorBlue,colorRed);
Plot( trailARRAY,"trailing stop level", TRAILCOLOR, styleStaircase) ;

//Plot( trailARRAY,"Trailing SL", TRAILCOLOR, styleStaircase) ;
 

bunti_k23

Well-Known Member
#6
bunti_k23

thank you very much 4 ur help,
its working
Also u can adjust these target lines as per ur requirement.
Just find these lines in the code.
Tar1 = .........( *0.050).
Tar2 = ......
Tar3 = ......

Just change the value after *

Make sure u change for both sides buy as well as sell.

Happy trading.
Amit:)