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

RE: [amibroker] Preferences(Ask to save changes)



PureBytes Links

Trading Reference Links

Hello Tomasz, 

thank you again - for example like this ...?

********************************************************
SetBarsRequired( 10000, 0 ); 

nPips = Optimize("nPips",0.0001,0.0001,0.0150,0.0001);
//nPips = 0.0015; // define your own value here 

PREV = TrStopLevel = C[ 0 ]; // init first element 

for( i = 1; i < BarCount; i++ ) 

{ 
CurC = C[ i ]; // current value of close 
PrevC = C[ i - 1 ]; // previous bar value of close 

CurTrStopLevel = 
IIf( CurC == PREV, PREV, 
IIf( ( (PrevC < PREV) AND (CurC < PREV) ), 
Min( PREV, CurC * ( 1 + nPips) ), 
IIf( ( PrevC > PREV) AND ( CurC > PREV ), 
Max( PREV, CurC * (1 - nPips ) ), 
IIf( CurC > PREV, CurC * ( 1 - nPips), CurC * ( 1 + nPips) ) ) ) ); 

TrStopLevel[ i ] = CurTrStopLevel; // store result 
PREV = CurTrStopLevel; // save previous value for next iteration 
} 

Buy = Cross(Close,TrStopLevel);
Sell = Cross(TrStopLevel,Close);
Short = Cross(TrStopLevel,Close);
Cover = Cross(Close,TrStopLevel);

PositionSize = 100000;

//Graph0 = TrStopLevel; // just for plotting 

********************************************************

Kindest regards
Robert


--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx> 
wrote:
> Hello,
> 
> First please note that the code is for trailing stop part only.
> It does NOT contain buy/sell rules therefore can not be directly
> "backtested" - you have to add buy/sell rules first.
> 
> Second - you should not change SetBarsRequired nor PREV = 
TrStopLevel = C[ 0 ]
> - those lines must remain the same.
> 
> Third - the only line you may to change in the code fragment I 
posted is
> nPips line.
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "rocou" <rocou@xxxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Tuesday, April 27, 2004 12:28 AM
> Subject: [amibroker] Re: Dear Traders, this seems to be an 
absolutely amazing ...
> 
> 
> Tomasz,
> 
> may I ask once more:
> 
> what do I have to fill in, if I want to backtest the past
> from January 1999 until today ?
> 
> ->  SetBarsRequired( ______,__ );    ?
> ->  PREV = TrStopLevel = C[ __ ];    ?
> 
> and is there anything else except "nPips"that I have
> to specify ??
> 
> Thanks again
> Kindest regards
> Robert
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx>
> wrote:
> > Hello,
> >
> > >the "maximum amount of thanks" for your help !!!!!
> > >I will try to follow your explanation.
> >
> > You are welcome.
> >
> > >I tried to contact you via email several times,
> > >but never received an answer. Might it be, that there
> > >is something wrong with your email client or are you
> > >"just" too busy ?
> >
> > I have checked my e-mail box and I have received
> > only one e-mail from you recently (23 April). You have sent
> > the same message to support address too and Marcin answered
> > initially and today I have provided longer reply including the 
same
> > code that I posted here.
> > Did you send anything more that I am not aware of?
> >
> > Best regards,
> > Tomasz Janeczko
> > amibroker.com
> > ----- Original Message ----- 
> > From: "rocou" <rocou@xxxx>
> > To: <amibroker@xxxxxxxxxxxxxxx>
> > Sent: Monday, April 26, 2004 11:45 PM
> > Subject: [amibroker] Re: Dear Traders, this seems to be an
> absolutely amazing ...
> >
> >
> >
> >
> > I tried to contact you via email several times,
> > but never received an answer. Might it be, that there
> > is something wrong with your email client or are you
> > "just" too busy ?
> >
> > Thanks again for your very apreciated help !!
> > Kindest regards
> > Robert
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" 
<amibroker@xxxx>
> > wrote:
> > > Rocou,
> > >
> > > The "PREV" has been covered many times in the past.
> > > It is easy to find in the mailing list archive
> > > http://www.amibroker.com/listarchive.html
> > >
> > > Take a look at:
> > > http://groups.yahoo.com/group/amibroker/message/45225
> > >
> > > http://groups.yahoo.com/group/amibroker/message/4507
> > > http://groups.yahoo.com/group/amibroker/message/11896
> > > 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 http://groups.yahoo.com/group/amibroker/message/45225 )
> > >
> > > 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,
> > >          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) ) ) ) );
> > >
> > >
> > > Now this can be rewritten using for loop:
> > >
> > > SetBarsRequired( 10000, 0 );
> > >
> > > nPips = 0.004; // define your own value here
> > >  PREV = TrStopLevel = C[ 0 ]; // init first element
> > >
> > > for( i = 1; i < BarCount; i++ )
> > > {
> > >   CurC = C[ i ]; // current value of close
> > >   PrevC = C[ i - 1 ]; // previous bar value of close
> > >
> > >   CurTrStopLevel =
> > >   IIf( CurC == PREV,  PREV,
> > >          IIf( ( (PrevC < PREV) AND (CurC < PREV) ),
> > >          Min( PREV, CurC * ( 1 + nPips) ),
> > >          IIf( ( PrevC > PREV) AND ( CurC > PREV ),
> > >               Max( PREV, CurC * (1 - nPips ) ),
> > >               IIf( CurC > PREV, CurC * ( 1 - nPips), CurC * ( 1 
+
> > nPips) ) ) ) );
> > >
> > >    TrStopLevel[ i ] = CurTrStopLevel; // store result
> > >    PREV = CurTrStopLevel; // save previous value for next
> iteration
> > > }
> > >
> > > 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 Janeczko
> > > amibroker.com
> > > ----- Original Message ----- 
> > > From: "rocou" <rocou@xxxx>
> > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > Sent: Monday, April 26, 2004 9:51 PM
> > > Subject: [amibroker] Dear Traders, this seems to be an 
absolutely
> > amazing ...
> > >
> > >
> > > Dear Traders,
> > >
> > > this seems to be an absolutely amazing formula
> > > from my broker CMS. Sorry if I am getting on your nerves again,
> > > but I really need your help how to EXACTLY translate the formula
> > > into 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 value
> > > crosses 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 value
> > > for the nPips parameter.
> > >
> > > The image is in folder "Photos" of this group:
> > >
> >
> 
http://photos.groups.yahoo.com/group/amibroker/vwp?.dir=/&.src=gr&.dnm
> > > =Trailing+Stop+System.jpg&.view=t&.done=http%
> > > 3a//photos.groups.yahoo.com/group/amibroker/lst%3f%26.dir=/%
> > 26.src=gr%
> > > 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 with
> > > a simple but very effective trading system.
> > >
> > > Kindest regards
> > > Robert
> > >
> > > 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 bugs@xxxx
> > > Send SUGGESTIONS to suggest@xxxx
> > > -----------------------------------------
> > > 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 Links
> >
> >
> >
> >
> > Send BUG REPORTS to bugs@xxxx
> > Send SUGGESTIONS to suggest@xxxx
> > -----------------------------------------
> > 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 Links
> 
> 
> 
> Send BUG REPORTS to bugs@xxxx
> Send SUGGESTIONS to suggest@xxxx
> -----------------------------------------
> 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 Links



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com.  Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/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 
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/