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

Re: [amibroker] Re: ApplyStop question



PureBytes Links

Trading Reference Links




Nick,
 
in my opinion it could be done like this (see code 
below). What you do is you look for an RSI cross 1 bar back (yesterday with EOD 
data). Then you give an additional constraint that you only buy today if the 
price goes below yesterdays close minus a certain percentage (I use 0.5% in this 
example).
 
Now you do not need a tradedelay of 1 bar (or 
day).
 
regards, Ed
 
 
 
 
<FONT 
color=#0000ff>SetTradeDelays(<FONT 
color=#ff00ff>0,<FONT 
color=#ff00ff>0,<FONT 
color=#ff00ff>0,<FONT 
color=#ff00ff>0<FONT 
color=#000000>); // set 
percentage<FONT 
color=#000000> perc = <FONT 
color=#ff00ff>0.5<FONT 
size=2>; <FONT 
color=#000000>Buy = <FONT 
color=#0000ff>Cross( <FONT 
color=#0000ff>Ref(<FONT 
color=#0000ff>RSI(<FONT 
color=#ff00ff>14),-<FONT 
color=#ff00ff>1), <FONT 
color=#ff00ff>30 ) <FONT 
color=#000000>AND <FONT 
color=#000000>L <= <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1) - <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1)*perc/<FONT 
color=#ff00ff>100<FONT 
size=2>; <FONT 
color=#000000>BuyPrice = <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1) - <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1)*perc/<FONT 
color=#ff00ff>100<FONT 
size=2>; <FONT 
color=#000000>Short = <FONT 
color=#0000ff>Cross( <FONT 
color=#ff00ff>70, <FONT 
color=#0000ff>Ref(<FONT 
color=#0000ff>RSI(<FONT 
color=#ff00ff>14),-<FONT 
color=#ff00ff>1) ) <FONT 
color=#000000>AND <FONT 
color=#000000>H >= <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1) + <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1)*perc/<FONT 
color=#ff00ff>100<FONT 
size=2>; <FONT 
color=#000000>ShortPrice = <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1) + <FONT 
color=#0000ff>Ref(<FONT 
color=#000000>C,-<FONT 
color=#ff00ff>1)*perc/<FONT 
color=#ff00ff>100<FONT 
size=2>; <FONT 
color=#0000ff>ApplyStop(<FONT 
color=#000000>stopTypeLoss,<FONT 
color=#000000>stopModePercent,<FONT 
color=#ff00ff>2.15,<FONT 
color=#ff00ff>1<FONT 
color=#000000>); ApplyStop<FONT 
color=#000000>(stopTypeProfit<FONT 
color=#000000>,stopModePercent<FONT 
color=#000000>,3<FONT 
color=#000000>,1<FONT 
face="Courier New">); <FONT 
color=#008000>// Sell and Cover only at stops. They will be filled with signals 
by Equity(1)<FONT 
color=#000000> Sell<FONT 
color=#000000> = 0<FONT 
face="Courier New">; <FONT 
color=#000000>Cover = <FONT 
color=#ff00ff>0<FONT 
color=#000000>; // for charting 
purposes<FONT 
color=#000000> Equity<FONT 
color=#000000>(1<FONT 
face="Courier New">); <FONT 
color=#008000>// replace various numbers by plain 1 (for charting 
purposes)<FONT 
color=#000000> Sell<FONT 
color=#000000> = IIf<FONT 
color=#000000>(Sell 
!= 0, <FONT 
color=#ff00ff>1, <FONT 
color=#ff00ff>0<FONT 
color=#000000>); Cover<FONT 
color=#000000> = IIf<FONT 
color=#000000>(Cover<FONT 
color=#000000> != 0, 
1, <FONT 
color=#ff00ff>0<FONT 
color=#000000>); Plot<FONT 
color=#000000>(C<FONT 
color=#000000>,"C"<FONT 
color=#000000>,1<FONT 
color=#000000>,64<FONT 
face="Courier New">); <FONT 
color=#0000ff>PlotShapes(<FONT 
color=#000000>shapeUpArrow*<FONT 
color=#000000>Buy,<FONT 
color=#000000>colorWhite, layer = <FONT 
color=#ff00ff>0, yposition = <FONT 
color=#000000>BuyPrice, offset = -<FONT 
color=#ff00ff>12<FONT 
color=#000000> ); PlotShapes<FONT 
color=#000000>(shapeDownArrow<FONT 
color=#000000>*Sell<FONT 
color=#000000>,colorYellow<FONT 
color=#000000>, layer = 0, 
yposition = SellPrice<FONT 
color=#000000>, offset = -<FONT 
color=#ff00ff>12<FONT 
color=#000000> ); PlotShapes<FONT 
color=#000000>(shapeDownArrow<FONT 
color=#000000>*Short<FONT 
color=#000000>,colorWhite<FONT 
color=#000000>, layer = 0, 
yposition = ShortPrice<FONT 
color=#000000>, offset = -<FONT 
color=#ff00ff>12<FONT 
color=#000000> ); PlotShapes<FONT 
color=#000000>(shapeUpArrow<FONT 
color=#000000>*Cover<FONT 
color=#000000>,colorYellow<FONT 
color=#000000>, layer = 0, 
yposition = CoverPrice<FONT 
color=#000000>, offset = -<FONT 
color=#ff00ff>12<FONT 
color=#000000> ); Title<FONT 
color=#000000>=Name()+ 
", O: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>O)+ <FONT 
color=#ff00ff>", H: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>H)+ <FONT 
color=#ff00ff>", L: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>L)+ <FONT 
color=#ff00ff>", C: "+<FONT 
color=#0000ff>WriteVal(<FONT 
color=#000000>C<FONT 
size=2>); // for analysis 
purposes<FONT 
color=#000000> Filter<FONT 
color=#000000> = 1<FONT 
face="Courier New">; <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>Buy,<FONT 
color=#ff00ff>"Buy"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>BuyPrice,<FONT 
color=#ff00ff>"BuyPrice"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>Sell,<FONT 
color=#ff00ff>"Sell"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>SellPrice,<FONT 
color=#ff00ff>"SellPrice"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>Short,<FONT 
color=#ff00ff>"Short"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>ShortPrice,<FONT 
color=#ff00ff>"ShortPrice"<FONT 
size=2>); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>Cover,<FONT 
color=#ff00ff>"Cover"<FONT 
face="Courier New">); <FONT 
color=#0000ff>AddColumn(<FONT 
color=#000000>CoverPrice,<FONT 
color=#ff00ff>"CoverPrice"); 

 
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  <A title=tessaglia@xxxxxxxxxxx 
  href="">chassis_73 
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Sunday, May 23, 2004 10:32 AM
  Subject: [amibroker] Sellprice/Applystop 
  problem
  Hi,mates.I'm going crazy about a problem that troubles al 
  my TS.SystemBuy = Cross( RSI(14), 30 );Sell = Cross( 70, 
  RSI(14) );BuyPrice=O*0.9705;//Buy when the stock goes down -2.95% from 
  Open.SetTradeDelays(0,0,0,0);ApplyStop(stopTypeLoss,stopModePercent,2.15,1);ApplyStop(stopTypeProfit,stopModePercent,3,1);ObjectiveI'd 
  like to buy the stock all the days it goes down till about -2.95 % from 
  open.I'd like to sell when Sell = Cross( 70, RSI(14) ) occurs or when i 
  can take profit about 3% from Buyprice.TroublesNo trouble 
  about Buy.It works perfectly.Sell instead has its logic but there's a 
  wrong situation when it's a black candle day.i.d  O 2.42 H 2.42 L 
  2.32 C 2.32 What happens here?Naturally I buy at 2.35 and IN THE SAME DAY 
  i sell at 2.42 to take profit.Obviously it's not possible because the 
  stock went down till 2.32 and I'm losing in fact.Let us suppose that 
  the day after O 2.31 H 2.44 L 2.31 C 2.42 .I 'd like to take my 3% when 
  the stock cross up 2.42 the day after.In the backtest there are a lot of 
  days like this so results are wrong.Naturally I tried many rules but 
  Applystop always prevails over all.Immediate IF function doesn't 
  work.i.d.IIf(C < 
  O,ApplyStop(stopTypeProfit,stopModeDisable,3,1),ApplyStop(stopTypeProfit,stopModePercent,3,1));Has 
  anyone had the same trouble?Best 
  regards,NickSend BUG REPORTS to 
  bugs@xxxxxxxxxxxxxSend SUGGESTIONS to 
  suggest@xxxxxxxxxxxxx-----------------------------------------Post 
  AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A 
  href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check 
  group FAQ at: <A 
  href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
  


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








Yahoo! Groups Sponsor


  ADVERTISEMENT 












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 the Yahoo! Terms of Service.