NexusFi: Find Your Edge


Home Menu

 





Coding an Exit method


Discussion in Platforms and Indicators

Updated
      Top Posters
    1. looks_one Alessandro47 with 5 posts (0 thanks)
    2. looks_two occasionallurker with 3 posts (1 thanks)
    3. looks_3 colion with 1 posts (0 thanks)
    4. looks_4 AHMED IBRAHIM with 1 posts (0 thanks)
    1. trending_up 6,189 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

Coding an Exit method

  #11 (permalink)
 jlwtrading 
Toronto, Canada
 
Experience: Advanced
Platform: Amibroker, Multicharts
Trading: Stocks
Posts: 3 since Mar 2013
Thanks Given: 0
Thanks Received: 1

A few good examples of trailing stops in Amibroker.
From the Traders Tips section of Technical Analysis of Stocks and Commodities magazine, May 2009:
Version(5.20); // requires v5.20
SetBarsRequired(sbrAll);

// get start date
Start = Cross( DateNum(), ParamDate(„Start date”, „2005-10-30” ) );
Started = Flip( Start, 0 );

StopMode = ParamToggle(„Stop Mode”, „Fixed|Chandelier” );
StopLevel = Param(„Fixed perc %”, 14, 0.1, 50, 0.1)/100;
StopATRFactor = Param(„Chandelier ATR multiple”, 4, 0.5, 10, 0.1 );
StopATRPeriod = Param(„Chandelier ATR period”, 14, 3, 50 );

// calculate support and resistance levels
if( StopMode == 0 ) // fixed percent trailing stop
{
sup = C * ( 1 - stoplevel );
res = C * ( 1 + stoplevel );
}
else // Chandelier ATR-based stop
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}

// 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 = Start OR Cross( C, trailArray );
Sell = Cross( trailArray, C );

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

Plot( Close,”Price”,colorBlack,styleBar);
Plot( trailARRAY,”trailing stop level”, colorRed );

—Tomasz Janeczko

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Increase in trading performance by 75%
The Elite Circle
How to apply profiles
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #12 (permalink)
AHMED IBRAHIM
wadi hof + cairo/EGYPT
 
Posts: 2 since Sep 2014
Thanks Given: 0
Thanks Received: 0


jlwtrading View Post
A few good examples of trailing stops in Amibroker.
From the Traders Tips section of Technical Analysis of Stocks and Commodities magazine, May 2009:
Version(5.20); // requires v5.20
SetBarsRequired(sbrAll);

// get start date
Start = Cross( DateNum(), ParamDate(„Start date”, „2005-10-30” ) );
Started = Flip( Start, 0 );

StopMode = ParamToggle(„Stop Mode”, „Fixed|Chandelier” );
StopLevel = Param(„Fixed perc %”, 14, 0.1, 50, 0.1)/100;
StopATRFactor = Param(„Chandelier ATR multiple”, 4, 0.5, 10, 0.1 );
StopATRPeriod = Param(„Chandelier ATR period”, 14, 3, 50 );

// calculate support and resistance levels
if( StopMode == 0 ) // fixed percent trailing stop
{
sup = C * ( 1 - stoplevel );
res = C * ( 1 + stoplevel );
}
else // Chandelier ATR-based stop
{
sup = C - StopATRFactor * ATR( StopATRPeriod );
res = C + StopATRFactor * ATR( StopATRPeriod );
}

// 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 = Start OR Cross( C, trailArray );
Sell = Cross( trailArray, C );

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

Plot( Close,”Price”,colorBlack,styleBar);
Plot( trailARRAY,”trailing stop level”, colorRed );

—Tomasz Janeczko

please , i need to change the start date from long side to short side
thanks

Reply With Quote




Last Updated on May 2, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts