[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] request for help with trailing stops



PureBytes Links

Trading Reference Links

Hi all

I hope someone can help me out with my trailing stops problem. Now that 
I have purchased the s/w I can backtest multiple securities. However, 
when I backtest trying to use the 'percent of profit' type stops, I have 
a problem. Let's say I short MMM at the open at 50.00, with a trailing 
'percent of profit' stop of 20%. If MMM trades down to 49.80 by days 
end, all is well. However, if it opens at 49.90 the next day, I am 
stopped out because $0.10 is 50% of my total profit which is $0.20.

I asked Marcin for some help with this and he sent me the following 
code. I am not sure if he meant this as a fix for my specific problem or 
not. The trouble is... and I am sorry about this... the following 
doesn't mean much to me, being a total AFL newbie.

Can anyone review the following and either give me a plain English idea 
of what it says or simply re-read the above and suggest a way that I can 
tell AB that I want to give my trades a bit of 'room to breathe' and 
that even if a trade goes immediately positive, then backs up and maybe 
even goes slightly negative, that I want to stay in? I can envision 
using an n-bars stop, but how can I tell AB to not allow the 'percent of 
profit' stop to kick in until xx actual profit has been made (a 
threshold large enough that I am not taken out prematurely)?

Yes, I have read all the helps re: trailing stops and if someone can 
show me where this specific issue is addressed, I would welcome it.

I wish I could offer more (or more accurately, anything at all) in 
return for the help... maybe someday.

Regards, Nikku

/* a sample low-level implementation of trailing stop in AFL: */
Short = your rule here
 

trailstop =0;
 
for( i = 1; i < BarCount; i++ )
{
 
if( trailstop == 0 && Short[ i ] ) trailstop = High[ i ];
 
if( trailstop > 0 AND High[ i ] > trailstop )
{
Cover[ i ] = True;
CoverPrice[ i ] = trailstop;
trailstop= 0;
}
else Cover[ i ] = 0;
 
if( trailstop > 0 )
{
trailstop = Min( High[ i - 1 ], trailstop );
}
 
}



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/