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

[amibroker] Re: Trailing Stops



PureBytes Links

Trading Reference Links

This sample is unique to my own trading systems but you should be able
to manipulate this code as needed. The trailing Stop is set at
previous days close minus 0.50, and if the stock Opens below that
figure then it takes you out of the trade at the Open price. And this
particular trading system does not set a Stop Loss on the day that a
position is entered.

Just my way of doing it.

Good luck... Phsst



SetTradeDelays(1,0,0,0); // Affects Back Test (not Scan or Explore)

Buy = <buy condition>

LongBars = BarsSince(Buy==0); // Used to prevent S/L on 1st day

SellPrice = IIf(LongBars == 2,0,Ref(L - .50,-1)); // No S/L 1st Day
-(2 needed for SetTradeDelays)

PrevSellPrice = IIf(SellPrice == 0,0,Ref(L - .50,-1));   // Trailing  

SellPrice = Max(SellPrice,PrevSellPrice);                //    Stop

SellPrice = Min(SellPrice,O);                            //       Loss

Sell = L <= SellPrice;


--- In amibroker@xxxxxxxxxxxxxxx, "Tony/Dianne" <awenos@xxxx> wrote:
> Hello,
> 
> For the past several days, I have been trying to code a Trailing
Stop without success.
> 
> I'm using both AFL and VB Script.
> 
> My problem is that I always seem to end up with a circular reference
problem which
> boils down to:  I need a Trailing stop variable to define the Sell
condition and I need
> the Sell condition to define the Trailing stop variable.
> 
> Can anyone give me advice/code sample to help?
> 
> As an aside, I've looked at the ApplyStop function and it does not
seem to do what I
> am seeking .  
> 
> My goal is, for a long entry, to have an amount defined by the ATR
function, which is subtracted from
> the low creating the stop level.  The stop level would then trail up
only.
> 
> Any help would be appreciated.
> 
> Regards,
> 
> Tony


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Make Money Online Auctions! Make $500.00 or We Will Give You Thirty Dollars for Trying!
http://us.click.yahoo.com/yMx78A/fNtFAA/i5gGAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

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