NexusFi: Find Your Edge


Home Menu

 





Vary a trailing stop with a filter


Discussion in Platforms and Indicators

Updated
    1. trending_up 2,787 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Vary a trailing stop with a filter

  #1 (permalink)
rshor
Johannesburg + South Africa
 
Posts: 4 since Jul 2014
Thanks Given: 0
Thanks Received: 0

Hi Folks,

Amibroker trailing stop:
StopLevel = 1 - Param("trailing stop %", 3, 0.1, 10, 0.1)/100;

Buy = Cross( MACD(), Signal() );
Sell = 0;
trailARRAY = Null;
trailstop = 0;

for( i = 1; i < BarCount; i++ )
{

if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel;
}
else Buy[ i ] = 0; // remove excess buy signals

if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}

if( trailstop > 0 )
{
trailstop = Max( High[ i ] * stoplevel, trailstop );
trailARRAY[ i ] = trailstop;
}

}

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

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

Is there a way to change the code to become more conservative when a filter is added? E.g. filter:
X=Foreign("^GSPC", "C", True);
IMA=WMA(X,75);
When X<IMA the filter is triggered.

How can the above coding be changed so that the stop becomes tighter. So if the initial stop is 20% from position entry, the new coding provides for a move to 15% when the filter is triggered and when filter is relaxed stop moves back to 20% ?

Thanks
rshor

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
Are there any eval firms that allow you to sink to your …
Traders Hideout
Futures True Range Report
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #2 (permalink)
 coolblonde 
NY/USA
 
Posts: 4 since Jun 2014

Try this (not tested)

 
Code
StopLevel  = 1 - Param( "trailing stop %", 3, 0.1, 10, 0.1 ) / 100;
StopLevel2 = 1 - Param( "trailing stop2 %", 1.5, 0.1, 10, 0.1 ) / 100;

Buy = Cross( MACD(), Signal() );
Sell = 0;

X = Foreign( "^GSPC", "C", True );
IMA = WMA( X, 75 );
Longstop = IIf( X < IMA, H * stoplevel2, H * stoplevel );

trailARRAY = Null;
trailstop = 0;

for ( i = 1; i < BarCount; i++ )
{
    if ( trailstop == 0 AND Buy[ i ] )
    {
        trailstop = longstop[i];
    }
    else
        Buy[ i ] = 0; // remove excess buy signals

    if ( trailstop > 0 AND Low[ i ] < trailstop )
    {
        Sell[ i ] = 1;
        SellPrice[ i ] = trailstop;
        trailstop = 0;
    }

    if ( trailstop > 0 )
    {
        trailstop = Max( longstop[i], trailstop );
        trailARRAY[ i ] = trailstop;
    }

}

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

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

Reply With Quote
  #3 (permalink)
rshor
Johannesburg + South Africa
 
Posts: 4 since Jul 2014
Thanks Given: 0
Thanks Received: 0



Reply With Quote




Last Updated on July 11, 2014


© 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