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

[amibroker] Use of ApplyStop



PureBytes Links

Trading Reference Links


Hi,

I'm trying to use ApplyStop so that a trailing stop of the previous 
bar's low kicks in ONLY after an indicator (call it MyIndicator) has 
reached a certain value.

The code snippet I'm using appears below, but it doesn't work. What 
happens is that ONLY the "Sell = L < SellStop;" condition kicks in --
causing many more losing trades than would have otherwise been exited 
profitably. The trailing stop that I want to kick in after 
MyIndicator has reached the specified level doesn't.

// -- Code snippet

// -- arbitrary buysetup
BuySetup = foo;
// -- If the buysetup occurred yesterday and the stock 
//    trades above the yesterday's high, enter trade
Buy = (Ref(BuySetup, -1) AND C > Ref(H, -1));
// -- The worst-case sell stop is the low of the setup day
SellStop = ValueWhen(BuySetup, L);
// -- Btw, how do I prevent a sell on the same day I enter?
//    Not sure I understand how "zero delays" 
//    "Activate Stops Immediately" work together
Sell = L < SellStop;

// -- Here is where I want to implement a trailing stop. First,
//    convert arrays to numbers for if statement (using IIf() inside
//    apply stop generated an error of illegal arguments).
LastBuyBar = StrToNum(NumToStr(ValueWhen(Buy, BarIndex())));
LastSellBar = StrToNum(NumToStr(ValueWhen(Sell, BarIndex())));
LastMyIndicator = StrToNum(NumToStr(MyIndicator));

// -- Ok, if we're currently in a buy, and MyIndicator is equal
//    to or greater than .8, I now want to trail a stop below
//    the previous day's low
if (LastBuyBar>LastSellBar AND LastMyIndicator >= .8) {

  ApplyStop(stopTypeTrailing, stopModePoint, Ref(L, -1), 1, True);

// -- otherwise, I only want to worst-case sell stop of the low
//    of the setup day to be active, so I'll turn off appply stop
} else {
  ApplyStop(stopTypeTrailing, stopModeDisable, Ref(L, -1), 1, True);
}

I want the stops used in the system to be intra-day, and to 
kick in no sooner than the second day of the trade. Is anyone aware
of why the code above would not work/what the correct settings would 
be? Thank you for your input.

Btw, also, does anyone know if you have more than one ApplyStop in a 
backtest, and what to do with the Sell variable if ApplyStops take 
care of all of your sell scenarios?

Regards,

Gordon





------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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 other support material please check also:
http://www.amibroker.com/support.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/