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

RE: [amibroker] Photos of people at the Clearwater Conference



PureBytes Links

Trading Reference Links




<FONT face=Arial color=#0000ff 
size=2>Robert,
<FONT face=Arial color=#0000ff 
size=2> 
You 
might want to have a look at AMA and AMA2 functions. the other solution is to 
reference the previous value via loops...You will find that AMA saves you a lot 
of coding..
<FONT face=Arial color=#0000ff 
size=2> 
Here 
is an example of the Laguerre RSI in MS using prev..
<FONT face=Arial color=#0000ff 
size=2> 

g:=0.5;L0:=((1-g)*C) + (g*PREV);L1:=(-g*L0) + Ref(L0,-1) + 
(g*PREV);L2:=(-g*L1) + Ref(L1,-1) + (g*PREV);L3:=(-g*L2) + Ref(L2,-1) + 
(g*PREV);
cu:= If(L0>L1, L0-L1,0) + If(L1>L2, L1-L2,0) + If(L2>L3, 
L2-L3,0);cd:= If(L0<L1, L1-L0,0) + If(L1<L2, L2-L1,0) + If(L2<L3, 
L3-L2,0);
temp:= If(cu+cd=0, -1,cu+cd);If(temp=-1,0,cu/temp)
 
And the 
same indicator in AFL using AMA2<SPAN 
class=628112521-23042004>
g=<FONT face=Arial 
color=#0000ff size=2>0.5<FONT face=Arial 
color=#0000ff>;
 
L0=<FONT 
color=#0000ff>AMA2((<FONT 
size=2>1-g)*<FONT 
size=2>C<FONT 
size=2>,1<FONT color=#282828 
size=2>,g);
L1=<FONT 
color=#0000ff>AMA2((-g*L0) +<FONT 
size=2>Ref( L0,-1<FONT 
size=2>),1<FONT color=#282828 
size=2>,g);
L2=<FONT 
color=#0000ff>AMA2((-g*L1) +<FONT 
size=2>Ref( L1,-1<FONT 
size=2>),1<FONT color=#282828 
size=2>,g);
L3=<FONT 
color=#0000ff>AMA2((-g*L2) +<FONT 
size=2>Ref( L2,-1<FONT 
size=2>),1<FONT color=#282828 
size=2>,g);
cu= <FONT 
color=#0000ff>IIf(L0>L1, L0-L1,<FONT 
size=2>0) +IIf<FONT 
size=2>(L1>L2, L1-L2,0) + 
IIf(L2>L3, L2-L3,<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>);
cd= <FONT 
color=#0000ff>IIf(L0<L1, L1-L0,<FONT 
size=2>0) + IIf<FONT 
size=2>(L1<L2, L2-L1,0) + 
IIf(L2<L3, L3-L2,<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>);
temp= <FONT 
color=#0000ff>IIf(cu+cd==<FONT 
size=2>0, -1<FONT 
color=#282828 size=2>,cu+cd);
x=<FONT 
color=#0000ff>IIf(temp== -<FONT 
size=2>1,0<FONT 
color=#282828 size=2><FONT face=Arial 
color=#0000ff>,cu/temp);
<FONT face=Arial 
color=#0000ff> 
<FONT face=Arial 
color=#0000ff size=2>and finally the code in AFL using 
loops.....
<FONT face=Arial 
color=#0000ff size=2> 
<FONT color=#282828 
size=2> 
g=<FONT face=Arial 
color=#0000ff size=2>0.5<FONT face=Arial 
color=#0000ff>;
L0[<FONT 
color=#0000ff>0]=<FONT 
size=2>0;<FONT color=#008000 
size=2>//initialize values to 
zero
L1[<FONT 
color=#0000ff>0]=<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>;
L2[<FONT 
color=#0000ff>0]=<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>;
L3[<FONT 
color=#0000ff>0]=<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>;
 
for<FONT 
color=#0000ff>( i=1<FONT 
size=2>;i<BarCount;i++) 
<FONT face=Arial 
color=#0000ff>//loop through all bars<FONT color=#282828 
size=2>
{
L0[i]= (<FONT 
color=#0000ff>1-g)*<FONT 
size=2>Close<FONT 
size=2>[i] + (g*L0[i-1<FONT 
color=#282828 size=2>]); 
L1[i]= -g*L0[i] + L0[i-<FONT 
face=Arial>1] + 
(g*L1[i-1<FONT color=#282828 
size=2>]);
L2[i]= -g*L1[i] + L1[i-<FONT 
face=Arial>1] + 
(g*L2[i-1<FONT color=#282828 
size=2>]);
L3[i]= -g*L2[i] + L2[i-<FONT 
face=Arial>1] + 
(g*L3[i-1<FONT color=#282828 
size=2>]);
}
 
cu= <FONT 
color=#0000ff>IIf(L0>L1, L0-L1,<FONT 
size=2>0) +IIf<FONT 
size=2>(L1>L2, L1-L2,0) + 
IIf(L2>L3, L2-L3,<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>);
cd= <FONT 
color=#0000ff>IIf(L0<L1, L1-L0,<FONT 
size=2>0) + IIf<FONT 
size=2>(L1<L2, L2-L1,0) + 
IIf(L2<L3, L3-L2,<FONT 
size=2>0<FONT face=Arial 
color=#0000ff>);
temp= <FONT 
color=#0000ff>IIf(cu+cd==<FONT 
size=2>0, -1<FONT 
color=#282828 size=2>,cu+cd);
x=<FONT 
color=#0000ff>IIf(temp==-<FONT 
size=2>1,0<FONT 
color=#282828 size=2>,cu/temp);
 
Plot<FONT color=#282828 
size=2>(x,""<FONT color=#282828 
size=2>,4<FONT color=#282828 
size=2>);
 
<FONT 
color=#0000ff> 
 
Regards,Jayson 

  <FONT face=Tahoma 
  size=2>-----Original Message-----From: rocou 
  [mailto:rocou@xxxxxxxxx]Sent: Friday, April 23, 2004 3:18 
  PMTo: amibroker@xxxxxxxxxxxxxxxSubject: [amibroker] Re: 
  CMS Trailing Stop System in AFLHello Stephane, 
  thanks for your answer. The definition of "PREV" and "Ref" 
  is:PREVThe PREV constant allows you to create self-referencing 
  formulas. A self referencing formula is one that is able to reference 
  the "previous" period''s value of itself.RefReferences a 
  previous OR subsequent element in a DATA ARRAY.  A positive PERIOD 
  references "n" periods in the future; a negative PERIOD references "n" 
  periods ago.So how could we "translate" these formula from CMS´s 
  language into AFL ?The trading system should look like this - we 
  still have to substitute "PREV" and "Ref" 
  ..._________________________________________________________________nPips=Optimize("nPips",1,1,50,1);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)))));Buy = 
  Cross(Close,TrStopLevel);Sell = Cross(TrStopLevel,Close);Short =  
  Cross(TrStopLevel,Close);Cover =  
  Cross(Close,TrStopLevel);PositionSize = 
  100000;_________________________________________________________________Thanks 
  for your help again in 
  advanceRegardsRobert--- In 
  amibroker@xxxxxxxxxxxxxxx, "Stephane Carrasset" <s.carrasset@xxxx> 
  wrote:> Hello,> > I am not sure to have done a correct 
  interpretation of Prev but it is a begin> > Stephane> 
  > > > TrStop[0]=Null;> > nP=0.1;> 
  > for(i=1;i<BarCount;i++)> > {> > 
  if(C[i]==TrStop[i-1])> > {> > 
  TrStop[i]=TrStop[i-1];> > }> > else> 
  > {> > if(C[i-1]<TrStop[i-1] && 
  C[i]<TrStop[i-1])> > {> > 
  TrStop[i]=Min(TrStop[i-1],C[i]*(1+nP));> > }> > 
  else> > {> > if(C[i-1]>TrStop[i-1] && 
  C[i]>TrStop[i-1])> > {> > 
  TrStop[i]=Max(TrStop[i-1],C[i]*(1-nP));> > }> > 
  else> > {> > if(C[i]>TrStop[i-1])> 
  > {> > TrStop[i]=C[i]*(1-nP);> > }> 
  > else> > {> > 
  TrStop[i]=C[i]*(1+nP);> > }> > }> > 
  }> > }> > }> > > > 
  > > Up= Cross(Close,TrStop);> > Down= 
  Cross(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,"",1,64);> > Plot(TrStop,"TrStop",2,1);> > 
  PlotShapes(IIf(up,> > 
  shapeUpArrow,shapeNone),colorGreen,0,L,-10); > > 
  PlotShapes(IIf(down,> > 
  shapeDownArrow,shapeNone),colorRed,0,H,-10); > >   
  ----- Original Message ----- >   From: rocou 
  >   To: amibroker@xxxxxxxxxxxxxxx >   Sent: 
  Friday, April 23, 2004 8:47 AM>   Subject: [amibroker] CMS 
  Trailing Stop System in AFL> > >   Dear 
  Traders, > >   may I please ask for your help - how do 
  I have to program the >   following >   
  "trailing stop system" of my broker CMS in AFL, to backtest/optimize 
  >   the "n pips" stop values ?> >   
  Thank you for your help in advance.>   Kind 
  regards>   Robert> > >   
  {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, CloseBuy, 
  OpenSell, CloseSell}>   OpenBuy:= Up and 
  (eventCount('OpenBuy')= eventCount('CloseBuy'));>   
  CloseBuy:= Down and 
  (eventCount('OpenBuy')>eventCount('CloseBuy'));>   
  OpenSell:=  Down and (eventCount('OpenSell')= 
  eventCount>   ('CloseSell'));>   
  CloseSell:=  Up and 
  (eventCount('OpenSell')>eventCount('CloseSell'));> > 
  > > > > >   Send BUG REPORTS to 
  bugs@xxxx>   Send SUGGESTIONS to 
  suggest@xxxx>   
  ----------------------------------------->   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 
  > > >         
  Yahoo! Groups Sponsor 
  >               
  ADVERTISEMENT>              
  >        
  >        > > > 
  ------------------------------------------------------------------------------>   
  Yahoo! Groups Links> >     a.. To visit your 
  group on the web, go to:>     <A 
  href="">http://groups.yahoo.com/group/amibroker/>       
  >     b.. To unsubscribe from this group, send an 
  email to:>     
  amibroker-unsubscribe@xxxxxxxxxxxxxxx>       
  >     c.. Your use of Yahoo! Groups is subject to 
  the Yahoo! Terms of Service. > > > 
  >   __________ NOD32 1.732 (20040422) Information 
  __________> >   This message was checked by NOD32 
  antivirus system.>   <A 
  href="">http://www.nod32.comSend 
  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.