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

[amibroker] Re: Best exit price?



PureBytes Links

Trading Reference Links


Hi Herman,

Thanks for all your advice, really appreciated,

Sam


--- In amibroker@xxxxxxxxxxxxxxx, "Herman van den Bergen" 
<psytek@xxxx> wrote:
> Sorry sam, got busy with some other stuff...your code looks OK. 
Best check
> is always to plot various variables and see whether things line up.
> 
> Only comment is that a Null doesn't plot, a zero would plot down 
to zero.
> 
> herman.
>   -----Original Message-----
>   From: qweds_560 [mailto:qweds_560@x...]
>   Sent: Thursday, January 20, 2005 1:27 PM
>   To: amibroker@xxxxxxxxxxxxxxx
>   Subject: [amibroker] Re: Best exit price?
> 
> 
> 
>   Hi Herman,
> 
>   Thanks for this. You have written pos=flip(buy,sell). I didn't
>   understand why since this is not referred to by any of the other
>   variables and so is not used. Is this correct?
> 
>   I tried your code and it did give the best exits (yes, optimizing
>   gives phenomenal results- wish i could see future prices!).
> 
>   I then had an idea and using the previous code you gave me, I
>   managed to obtain output in the backtester which gave the entries
>   together with the BEST exits! The key seems to be adding:
> 
>   SetOption("PriceBoundChecking",False);
> 
>   and also setting:
> 
>   Sell=SellPrice == bestSellPrice;
>   Cover=CoverPrice == bestcoverPrice;
> 
>   The whole code I used is as follows:
> 
>   SetOption("PriceBoundChecking",False);//switches off checking
>   high/low in bar
> 
>   Buy = ..conditions;
>   Short = ...conditions;
> 
>   Sell = Short;
>   Cover = Buy;
> 
>   BuyPrice = ...
>   ShortPrice = ...
>   SellPrice=High;
>   CoverPrice=Low;
> 
>   Buy = ExRem(Buy,Short);
>   Sell = ExRem(Sell,Buy);
> 
>   Short = ExRem(Short,Buy);
>   Cover = ExRem(Cover,Short);
> 
>   Pos = Flip(Buy,Short);//returns 1 on each bar until it has a 
short
>   signal where it reverts to 0
> 
>   Temp = HighestSince(Buy,H);//highest high since a buy signal
> 
>   Temp = ValueWhen(Short,Temp ,0);//value of the highest buy since 
a
>   buy signal if there is a short signal
> 
>   Temp = IIf(pos, Temp , Null);//if in long mode, then return 
value of
>   the highest buy since a buy signal as long as there is a short
>   signal, otherwise  0
> 
>   BestSellPrice = Temp;
> 
>   pos1 = Flip(Short,Buy);
>   Temp1 = LowestSince(Short,L);
>   Temp1 = ValueWhen(Buy,Temp1 ,0);
>   Temp1 = IIf(pos1, Temp1 , Null);
>   BestcoverPrice = Temp1;
> 
>   Sell=SellPrice == bestSellPrice;//sell where sellprice becomes 
equal
>   to bestsellprice
>   Cover=CoverPrice == bestcoverPrice;
> 
>   This has the added benefit of correct time of the best exit (I am
>   testing on intraday data). However, a minor inconvenience is 
that it
>   does not calculate the best exits for the first buy and first 
short
>   trade that occurs in the data (probably because there were no 
buys
>   and sells previously to reference from).
> 
>   Herman, can you tell me if the comments against the code are
>   correct? It's just that I am not 100% sure why the code should 
work.
> 
>   Many thanks for all your assistance
> 
>   Sam
> 
> 
>   --- In amibroker@xxxxxxxxxxxxxxx, "Herman van den Bergen"
>   <psytek@xxxx> wrote:
>   > Sam,
>   >
>   > To see the difference between normal exit prices and best exit
>   prices you
>   > have to set the SellPrice and Cover price. Run the code below 
on,
>   try LLTC
>   > EOD, in the optimizer. You get two result lines, one using best
>   prices and
>   > one using normal prices. I think you can place some of the
>   variables in
>   > AddColumn()s to allow verification - I did not test the code
>   extensively.
>   > You must enter at the open because the MFE and MAEs can happen 
any
>   time
>   > during the day. I think you have to delay the best price to 
make it
>   > available at the time of the exit signal. The profit ratio is
>   something like
>   > 8000%(normal prices) to 4 billion%(BestPrices) in about ten 
years.
>   Try the
>   > system you might be able to improve it... it is an old one 
from my
>   files.
>   >
>   > Good luck,
>   > herman
>   >
>   > // BestSellPrice experiment
>   > // Run in Optimizer on LLTC, when Test==1 you are trading best
>   prices
>   > SetTradeDelays(1,1,1,1);
>   > SetOption("PriceBoundChecking",False);
>   > Test = Optimize("Test",0,0,1,1);
>   > BuyPrice = SellPrice = ShortPrice = CoverPrice = Open;
>   >
>   > //////////////// SumRSI system by herman ////////////////
>   > Ind=(Sum(RSI(3)-LLV(RSI(3),17),6)/Sum(HHV(RSI(3),17)-LLV(RSI
>   (3),17),6))*100;
>   > Buy=Cross(50,Ind);
>   > Sell=Cross(Ind,50);
>   > Short = Sell;
>   > Cover = Buy;
>   > E=Equity(1);
>   > ///////////////////////////////////////////////////////
>   >
>   > Pos = Flip(Buy,Sell);
>   > BestSellPrice       = Ref(ValueWhen(Sell,HighestSince
(Buy,H),0),-
>   1);
>   > BestCoverPrice = Ref(ValueWhen(Cover,LowestSince(Short,L),0),-
1);
>   >
>   > if(Test)
>   >       {
>   >       SellPrice = BestSellPrice;
>   >       CoverPrice = BestCoverPrice;
>   >       }
>   > else
>   >       {
>   >       SellPrice = Open;
>   >       CoverPrice = Open;
>   >       }
>   >
>   > Plot(C,"C",1,128);
>   > PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),5);
>   > PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),4);
>   > Plot(BestSellPrice,"BestSellPrice",5,styleStaircase);
>   > Plot(BestCoverPrice,"BestCoverPrice",4,styleStaircase);
>   > //Plot(E,"E",2,1);
>   >
>   >
>   > -----Original Message-----
>   > From: qweds_560 [mailto:qweds_560@x...]
>   > Sent: Wednesday, January 19, 2005 5:55 PM
>   > To: amibroker@xxxxxxxxxxxxxxx
>   > Subject: [amibroker] Re: Best exit price?
>   >
>   >
>   >
>   > Hi Herman,
>   >
>   > Yes, I did mange to plot (by creating a new indicator), many
>   thanks.
>   > It does show the best prices that could have been achieved. 
The ref
>   > function in the last line:
>   >
>   > BestSellPrice = Ref(Temp ,-1);
>   >
>   > seems redundant. I used BuySellPrice = temp and it gives the 
same
>   > results.
>   >
>   > I then pasted the whole code into Explorer and I managed to 
obtain
>   > some output. I then copied and pasted into Excel (had to do 
this
>   > twice, with different filter settings in Explorer) and then 
had to
>   > do a few manipulations in Excel to obtain something which was 
close
>   > to what I wanted. Not at all elegant, i'm afraid!!!
>   >
>   > I tried to use the code in the backtester (without the plot) 
but it
>   > didn't work there. I set SELL= bestsellprice. Any way of just 
using
>   > the code in the backtester?
>   >
>   > Any further suggestions to try and simplify would be 
appreciated!!
>   >
>   > Many thanks again
>   >
>   > Sam
>   >
>   >
>   >
>   >
>   >
>   > --- In amibroker@xxxxxxxxxxxxxxx, "Herman van den Bergen"
>   > <psytek@xxxx> wrote:
>   > > Did you plot the code i posted [ Tue 01/18/2005 7:59 PM ]? 
Your
>   > best bet to
>   > > solve this problem is to visualize it.
>   > >
>   > > herman
>   > >   -----Original Message-----
>   > >   From: qweds_560 [mailto:qweds_560@x...]
>   > >   Sent: Wednesday, January 19, 2005 12:34 PM
>   > >   To: amibroker@xxxxxxxxxxxxxxx
>   > >   Subject: [amibroker] Re: Best exit price?
>   > >
>   > >
>   > >
>   > >   Many thanks Graham,
>   > >
>   > >   Unfortunately, it doesn't seem to work. I may be doing
>   something
>   > >   wrong:
>   > >
>   > >   My code is:
>   > >
>   > >   buy=...conditions
>   > >   short=...conditions
>   > >
>   > >   sell=short;
>   > >   cover=buy;
>   > >
>   > >   BestLong = valuewhen( sell, highestsince(buy,h) );
>   > >   BestShort = valuewhen( cover, lowestsince(short,L) );
>   > >
>   > >   Sell=bestlong;
>   > >   Cover=bestshort;
>   > >
>   > >   Buy = ExRem(Buy,Short);
>   > >   Sell = ExRem(Sell,Buy);
>   > >   Short = ExRem(Short,Buy);
>   > >   Cover = ExRem(Cover,Short);
>   > >
>   > >   The sell happens on the next bar after a buy rather than
>   > searching
>   > >   for the highest high before a short signal.
>   > >
>   > >   Any assistance would be appreciated,
>   > >
>   > >   Cheers
>   > >
>   > >   Sam
>   > >
>   > >   --- In amibroker@xxxxxxxxxxxxxxx, Graham 
<kavemanperth@xxxx>
>   > wrote:
>   > >   > You can probably get more complex or easier solutions, 
here
>   is
>   > one
>   > >   >
>   > >   >
>   > >   > BestLong = valuewhen( sell, highestsince(buy,h) );
>   > >   > BestShort = valuewhen( cover, lowestsince(short,L) );
>   > >   >
>   > >   >
>   > >   >
>   > >   > On Tue, 18 Jan 2005 23:22:43 -0000, qweds_560
>   <qweds_560@xxxx>
>   > >   wrote:
>   > >   > >
>   > >   > >
>   > >   > > Hello,
>   > >   > >
>   > >   > > I have been trying to solve this problem for some time
>   using
>   > all
>   > >   > > sorts of functions in the backtester: HHV, barssince,
>   > valuewhen,
>   > >   > > barindex and so on.
>   > >   > >
>   > >   > > Consider a simple stop and reverse system. I want to 
know
>   > what
>   > >   the
>   > >   > > best exit price could have been from a long position 
before
>   > the
>   > >   > > system reverses and what the best exit price that 
could be
>   > from a
>   > >   > > short position before the system reverses and goes 
long.
>   > >   > >
>   > >   > > To put it another way, I would like to peek into the 
future
>   > to
>   > >   see
>   > >   > > what the best price I could exit my position at BEFORE 
I
>   > receive
>   > >   a
>   > >   > > signal in the opposite direction.
>   > >   > >
>   > >   > > I am trying to find out the maximum profit that could 
be
>   made
>   > >   using
>   > >   > > the system if you had the foresight to know exactly 
when to
>   > exit
>   > >   > > each and every position.
>   > >   > >
>   > >   > > I would be grateful for any suggestions.
>   > >   > >
>   > >   > > Many thanks
>   > >   > >
>   > >   > > Sam
>   > >   > >
>   > >   > >
>   > >   > > Check AmiBroker web page at:
>   > >   > > http://www.amibroker.com/
>   > >   > >
>   > >   > > Check group FAQ at:
>   > >   http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>   > >   > > Yahoo! Groups Links
>   > >   > >
>   > >   > >
>   > >   > >
>   > >   > >
>   > >   > >
>   > >   >
>   > >   >
>   > >   > --
>   > >   > Cheers
>   > >   > Graham
>   > >   > http://e-wire.net.au/~eb_kavan/
>   > >
>   > >
>   > >
>   > >
>   > >
>   > >   Check AmiBroker web page at:
>   > >   http://www.amibroker.com/
>   > >
>   > >   Check group FAQ at:
>   > > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>   > >
>   > >
>   > >
>   > > -------------------------------------------------------------
----
>   --
>   > ---------
>   > > --
>   > >   Yahoo! Groups Links
>   > >
>   > >     a.. To visit your group on the web, go to:
>   > >     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.
>   >
>   >
>   >
>   >
>   >
>   > Check AmiBroker web page at:
>   > http://www.amibroker.com/
>   >
>   > 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 the Yahoo! Terms of
>   Service.
> 
> 
> 
> 
> 
>   Check AmiBroker web page at:
>   http://www.amibroker.com/
> 
>   Check group FAQ at:
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> 
> 
> 
> -------------------------------------------------------------------
---------
> --
>   Yahoo! Groups Links
> 
>     a.. To visit your group on the web, go to:
>     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.





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Has someone you know been affected by illness or disease?
Network for Good is THE place to support health awareness efforts!
http://us.click.yahoo.com/Rcy2bD/UOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

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/