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

RE: [amibroker] Re: Initiating Trailing Stop after hitting Profit Target



PureBytes Links

Trading Reference Links

Dear David,

I’ve made a stab at it, but problems remain, eg, there are excess buy and sell signals.  Would anyone care to lend a hand here?  My looping abilities are pretty meager and I’ve likely made a hash of it.

 

Regards,

 

Fred

 

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

Sell = 0;

 

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

ProfitLevel   = Param("ProfitLevel",10,5,100,5)/100;

ProfitTarget  = ValueWhen(Buy,BuyPrice*(1+ProfitLevel));

 

trailARRAY    = Null;

trailstop     = 0;

priceatbuy    = 0;

highsincebuy  = 0;

 

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

{

       if( Buy[i] )

       {

              priceatbuy = BuyPrice[i];  //Establishes Long Entry Price

       }

 

       if( priceatbuy > 0 )      

       {                   

              highsincebuy = Max( High[i], highsincebuy);  //Establishes High since Entry

       }

             

   if( highsincebuy >= (1 + ProfitLevel)*priceatbuy)

       {

              trailstop = Max( High[i] * stoplevel, trailstop );  //Establishes trailing stop only when profit target is reached

       }

 

       if( trailstop > 0 AND Low[ i ] < trailstop )  //Establishes trigger for trailing stop

   {

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

Plot( ProfitTarget, "ProfitTarget",colorGreen);

 

 


From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Tomasz Janeczko
Sent: Sunday, March 25, 2007 3:28 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Re: Initiating Trailing Stop after hitting Profit Target

 

Hello,

> I think that I understand the example in the Knowledge Base, but it
> doesn't seem to address my question directly.

You mean that KB article is not ready to use copy-paste code for your specific request?
No it isn't. It is not supposed to be.
It was written well before you asked the question. But it is on related stuff.
It is just an example on how to do that on your own.

> Are you saying that by adding more logic to the example loop, I could
> detect that the Profit Target has been hit, and then start looking
> for a trailing stop trigger?

Yes exactly - add few lines and you will be done.

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "dweilmuenster95125" <dweilmuenster95125@yahoo.com>
To: <amibroker@xxxxxxxxxps.com>
Sent: Sunday, March 25, 2007 6:13 PM
Subject: [amibroker] Re: Initiating Trailing Stop after hitting Profit Target

> Tomasz, thanks fo your quick reply <g>.
>
> I think that I understand the example in the Knowledge Base, but it
> doesn't seem to address my question directly.
>
> The goal is to have no trailing stop in place until the trade reaches
> a Profit Target, say of y%, then to implement a trailing stop from
> that point into the future.
>
> Are you saying that by adding more logic to the example loop, I could
> detect that the Profit Target has been hit, and then start looking
> for a trailing stop trigger?
>
>
>
> Thanks,
> David
>
>
> --- In amibroker@xxxxxxxxxps.com, "Tomasz Janeczko" <groups@xxx>
> wrote:
>>
>> Hello,
>>
>> Yes it is possible without custom backtester.
>> All you need is to write relatively simple loop.
>> Example of such loop is in the Knowledge Base:
>> http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-
> in-the-price-chart/
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>> ----- Original Message -----
>> From: "dweilmuenster95125" <dweilmuenster95125@...>
>> To: <amibroker@xxxxxxxxxps.com>
>> Sent: Sunday, March 25, 2007 1:06 PM
>> Subject: [amibroker] Initiating Trailing Stop after hitting Profit
> Target
>>
>>
>> > Hi,
>> >
>> > Can't figure out if it's possible without the Custom Backtester
> to
>> > initiate a Trailing Stop only after a specified Profit Target is
> hit.
>> >
>> > Suggestions?
>> >
>> > If it's documented somewhere that I've missed, please point me in
> the
>> > right direction?
>> >
>> >
>> > Thanks,
>> >
>> > David
>> >
>> > San Jose, CA
>> >
>> >
>> >
>> > Please note that this group is for discussion between users only.
>> >
>> > To get support from AmiBroker please send an e-mail directly to
>> > SUPPORT {at} amibroker.com
>> >
>> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
>> > http://www.amibroker.com/devlog/
>> >
>> > For other support material please check also:
>> > http://www.amibroker.com/support.html
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>> >
>> >
>>
>
>
>
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
> Yahoo! Groups Links
>
>
>
>
>

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___