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

[amibroker] If



PureBytes Links

Trading Reference Links




snif...
it plots exactly what I have sent to 
you

 
TrStop[0<FONT 
size=1>]=Null;
nP = 0.004; 
// define your own value here <FONT 
size=1>
for(i=1<FONT 
size=1>;i<BarCount;i++)
{
if<FONT 
size=1>(C[i]==TrStop[i-1<FONT 
size=1>])
{
TrStop[i]=TrStop[i-1<FONT 
size=1>];
}
else
{
if<FONT 
size=1>(C[i-1<FONT 
size=1>]<TrStop[i-1] 
&& C[i]<TrStop[i-<FONT color=#ff00ff 
size=1>1])
{
TrStop[i]=Min<FONT 
size=1>(TrStop[i-1<FONT 
size=1>],C[i]*(1<FONT 
size=1>+nP));
}
else
{
if<FONT 
size=1>(C[i-1<FONT 
size=1>]>TrStop[i-1] 
&& C[i]>TrStop[i-<FONT color=#ff00ff 
size=1>1])
{
TrStop[i]=Max<FONT 
size=1>(TrStop[i-1<FONT 
size=1>],C[i]*(1<FONT 
size=1>-nP));
}
else
{
if<FONT 
size=1>(C[i]>TrStop[i-1<FONT 
size=1>])
{
TrStop[i]=C[i]*(1<FONT 
size=1>-nP);
}
else
{
TrStop[i]=C[i]*(1<FONT 
size=1>+nP);
}
}
}
}
}
 
 
Up= Cross<FONT 
size=1>(Close,TrStop);
Down= Cross<FONT 
size=1>(TrStop,C);
 
/*
if(C=PREV, PREV, if(((Ref(C,-1)<PREV)
AND (C<PREV)), Min(PREV,C*(1+nPips)), if((Ref(C,-1)>PREV) 
AND (C>PREV), Max(PREV,C*(1-nPips)), if(C>PREV,C*(1-nPips),C*
(1+nPips)))));
*/
Plot(C,<FONT color=#ff00ff 
size=1>"",1<FONT 
size=1>,64<FONT 
size=1>);
Plot(TrStop,<FONT color=#ff00ff 
size=1>"TrStop",<FONT color=#ff00ff 
size=1>2,1<FONT 
size=1>);
PlotShapes(<FONT color=#0000ff 
size=1>IIf(up,
shapeUpArrow,shapeNone),colorGreen,<FONT 
color=#ff00ff size=1>0,L,-<FONT color=#ff00ff 
size=1>10); 
PlotShapes(<FONT color=#0000ff 
size=1>IIf(down,
shapeDownArrow,shapeNone),colorRed,<FONT 
color=#ff00ff size=1>0,H,-<FONT color=#ff00ff 
size=1>10); 
<BLOCKQUOTE 
>
  ----- Original Message ----- 
  <DIV 
  >From: 
  Tomasz Janeczko 
  
  To: <A title=amibroker@xxxxxxxxxxxxxxx 
  href="">amibroker@xxxxxxxxxxxxxxx 
  Sent: Monday, April 26, 2004 11:23 
  PM
  Subject: Re: [amibroker] Dear Traders, 
  this seems to be an absolutely amazing ...
  
  Rocou,
   
  The "PREV" has been covered many times in the 
  past.
  It is easy to find in the mailing list 
  archive
  <FONT face=Arial 
  size=2>http://www.amibroker.com/listarchive.html
   
  Take a look at: 
  <FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/message/45225
   
  <FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/message/4507
  <FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/message/11896
  <FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/message/31088
   
  Some of formulas using PREV may be rewritten 
  using AMA/AMA2
  but ALL (I mean *ALL*) of them can be rewritten 
  using looping 
  (see <A 
  href=""><FONT face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/message/45225<FONT 
  face=Arial size=2> )
   
  Specifically your "problem" code:
  TrStopLevel:=If(C=PREV, PREV, 
  If(((Ref(C,-1)<PREV)AND (C<PREV)), 
  Min(PREV,C*(1+nPips)),If((Ref(C,-1)>PREV)AND (C>PREV), 
  Max(PREV,C*(1-nPips)), 
  If(C>PREV,C*(1-nPips),C*(1+nPips)))));
   
  can be rewritten using loop too.
   
  First step is to "UNFOLD" ugly written code to 
  the form that is easier to read and understand:
   
  TrStopLevel = 
  If( C = PREV,  PREV,  
  
  <FONT face="Courier New" 
  size=2>         If( ( (Ref(C,-1) < 
  PREV) AND (C < PREV) ), 
  <FONT face="Courier New" 
  size=2>         Min( PREV, C* 
  (1+nPips) ),
  <FONT face="Courier New" 
  size=2>         If( (Ref(C,-1) > 
  PREV) AND ( C > PREV ),  
  <FONT face="Courier New" 
  size=2>              
  Max( PREV, C * (1 - nPips ) ), 
  <FONT face="Courier New" 
  size=2>              
  If( C > PREV, C * (1-nPips), C * (1+nPips) ) ) ) );
   
   
  Now this can be rewritten using for 
  loop:
   
  SetBarsRequired<FONT 
  color=#000000>( 10000, 
  0 ); nPips = 
  0.004; <FONT 
  color=#008000>// define your own value here<FONT 
  color=#000000> PREV = TrStopLevel = <FONT 
  color=#000000>C[ <FONT 
  color=#ff00ff>0 ]; // 
  init first element <FONT 
  color=#000000>for( i = <FONT 
  color=#ff00ff>1; i < <FONT 
  color=#000000>BarCount; i++ ) { 
    CurC = C<FONT 
  color=#000000>[ i ]; // current value of 
  close   PrevC = <FONT 
  color=#000000>C[ i - <FONT 
  color=#ff00ff>1 ]; // 
  previous bar value of close 
    CurTrStopLevel =   <FONT 
  color=#0000ff>IIf( CurC == 
  PREV,  PREV,   
           <FONT 
  color=#0000ff>IIf( ( (PrevC < PREV) <FONT 
  color=#000000>AND (CurC < PREV) ), 
           <FONT 
  color=#0000ff>Min( PREV, CurC * ( <FONT 
  color=#ff00ff>1 + nPips) ), 
           <FONT 
  color=#0000ff>IIf( ( PrevC > PREV) <FONT 
  color=#000000>AND ( CurC > PREV 
  ),   
                <FONT 
  color=#0000ff>Max( PREV, CurC * (<FONT 
  color=#ff00ff>1 - nPips ) ), 
                <FONT 
  color=#0000ff>IIf( CurC > PREV, CurC * ( 
  1 - nPips), CurC * ( 
  1 + nPips) ) ) ) ); 
     TrStopLevel[ i ] = CurTrStopLevel; <FONT 
  color=#008000>// store result    PREV 
  = CurTrStopLevel; // save previous value for next 
  iteration } <FONT 
  color=#000000>Graph0 = TrStopLevel; 
  // just for plotting
   
  What I did ?
  It is fairly simple:
  I have just wrapped the MS code into the for 
  loop, replaced arrays with scalars
  ( C replaced with CurC = C[ i ] , Ref( C, -1 
  ) replaced with PrevC = C[ i - 1 ].
  PREV in my code is a temporary variable that 
  holds previous value of calculation in the loop .
   
  This way I can keep almost entire code as it 
  was.
   
  Advantage? It runs 100x faster than in Metastock. 
  Try it - run backtest in MS and in AB and compare times.
  Best 
  regards,Tomasz Janeczkoamibroker.com
  ----- Original Message ----- 
  From: "rocou" <<A 
  href=""><FONT face=Arial 
  size=2>rocou@xxxxxxxxx>
  To: <<A 
  href=""><FONT face=Arial 
  size=2>amibroker@xxxxxxxxxxxxxxx<FONT face=Arial 
  size=2>>
  Sent: Monday, April 26, 2004 9:51 PM
  Subject: [amibroker] Dear Traders, this seems to 
  be an absolutely amazing ...
  <FONT face=Arial 
  size=2>Dear Traders, this seems to be an absolutely amazing 
  formulafrom my broker CMS. Sorry if I am getting on your nerves again, 
  but I really need your help how to EXACTLY translate the formulainto 
  Amibroker´s AFL for backtesting.The trailing stop is based on a 
  certain amount of pips ("nPip")that you define , NOT on any kind of 
  ATR/volatility !!Buy/Sell and Short/Cover signals are generated, if 
  close valuecrosses the TrailingStoppLevel Line. That is the whole 
  story.You only have to define the amount of "nPip"´s.The image 
  shows the 15min chart EURUSD and 15 as the valuefor the nPips 
  parameter.The image is in folder "Photos" of this group: <A 
  href=""><FONT 
  face=Arial 
  size=2>http://photos.groups.yahoo.com/group/amibroker/vwp?.dir=/&.src="";><FONT 
  face=Arial 
  size=2>=Trailing+Stop+System.jpg&.view=t&.done=http%3a//photos.groups.yahoo.com/group/amibroker/lst%3f%26.dir=/%26.src="">26.view=t[/img]I 
  politely ask all of you to help me EXACTLY translating this formula into 
  AFL for backtesting/optimizing "nPip" possibilities. I guess it would be a 
  great chance for all of us to trade witha simple but very effective 
  trading system.Kindest regardsRobert  Here again the 
  formula from 
  CMS:___________________________________________________________{Trailing 
  Stop Loss}TrStopLevel:=If(C=PREV, PREV, If(((Ref(C,-1)<PREV)AND 
  (C<PREV)), Min(PREV,C*(1+nPips)),If((Ref(C,-1)>PREV)AND (C>PREV), 
  Max(PREV,C*(1-nPips)), 
  If(C>PREV,C*(1-nPips),C*(1+nPips)))));{Signal Up and 
  Down}Up:= Cross(Close,TrStopLevel);Down:= 
  Cross(TrStopLevel,C);{OpenBuy and CloseBuy}OpenBuy:= Up 
  and (eventCount('OpenBuy')= eventCount('CloseBuy'));CloseBuy:= Down 
  and (eventCount('OpenBuy')>eventCount('CloseBuy'));{OpenSell and 
  CloseSell}OpenSell:=  Down and (eventCount('OpenSell')= 
  eventCount('CloseSell'));CloseSell:=  Up and 
  (eventCount('OpenSell')>eventCount('CloseSell'));___________________________________________________________Send 
  BUG REPORTS to <FONT face=Arial 
  size=2>bugs@xxxxxxxxxxxxxSend 
  SUGGESTIONS to <FONT face=Arial 
  size=2>suggest@xxxxxxxxxxxxx<FONT face=Arial 
  size=2>-----------------------------------------Post AmiQuote-related 
  messages ONLY to: <FONT 
  face=Arial size=2>amiquote@xxxxxxxxxxxxxxx 
  (Web page: <A 
  href=""><FONT face=Arial 
  size=2>http://groups.yahoo.com/group/amiquote/messages/<FONT 
  face=Arial size=2>)--------------------------------------------Check 
  group FAQ at: <A 
  href=""><FONT 
  face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/files/groupfaq.html<FONT 
  face=Arial size=2> Yahoo! Groups Links<*> To visit your 
  group on the web, go to:     <A 
  href=""><FONT face=Arial 
  size=2>http://groups.yahoo.com/group/amibroker/<FONT 
  face=Arial size=2><*> To unsubscribe from this group, send an email 
  to:     <A 
  href=""><FONT face=Arial 
  size=2>amibroker-unsubscribe@xxxxxxxxxxxxxxx<FONT 
  face=Arial size=2><*> Your use of Yahoo! Groups is subject 
  to:     <A 
  href=""><FONT face=Arial 
  size=2>http://docs.yahoo.com/info/terms/<FONT face=Arial 
  size=2> Send 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 
  __________ 
  NOD32 1.737 (20040426) Information __________This message was checked 
  by NOD32 antivirus system.<A 
  href="">http://www.nod32.com


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.