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

[amibroker] Re: BarsSince(Buy == 1)



PureBytes Links

Trading Reference Links

When you start trying to simulate limit orders and further when you 
have multiple entry and/or exit criteria you will see what I mean.

Basically even in your code below if on bar 1 you have "buy" 
conditions and you bought, but you also had "buy" conditions on bars 
2 and 3, then barssince would be calculated from bar 3.

Ah, I hear you say, what about EXREM. Well there's nothing magical 
about that. It will simply zero all further buy conditions until you 
get to a sell condition. Not the actual trade. Lets give an example.

"If today's price is less than yesterday's price then we want to buy 
tomorrow at today's price or better on limit. Th exact opposite for a 
sell."

So 
Bar1  $10
Bar2  $9
Bar3  $8
Bar4  $11
Bar5  $8
Bar6  $7
Bar7  $9
Bar8  $9

So our order is at the end of bar2 at $9 or better. We buy bar3 @ $8.
Bar5 we want $11 or better as an exit, but there is no fill.
So we try again after Bar7 @ $9. This gets filled and we are out @ $9 
on Bar8. 

Your exrem statement is "foiled" by Bar4 & Bar5. This is a "Sell" 
condition. So now Amibroker does not have to ignore the next "Buy" 
condition at Bar5 for a trade on Bar6. 

Therefore if you ask for any stats via valuewhen/barssince etc you 
will be "told" you got in at Bar6, where in fact you got in at Bar3.

Max



--- In amibroker@xxxxxxxxxxxxxxx, Graham <kavemanperth@xxxx> wrote:
> What do you mean by this?
> >>But it does have a major flaw vs other software
> products. AFL code has NO ACCESS to your ACTUAL trade stats
> (entryprice, bars in trade etc). <<
> Scan and backtest gives you all of this
> or
> you can simply write an exploration to provide all that data and 
more
> 
> or maybe I missed your point!
> 
> buy=yourbuyconditions;
> sell=yoursellconditions;
> buy=exrem(buy,sell);
> sell=exrem(sell,buy);
> 
> filter=1;
> addcolumn(barssince(buy),"BarsInTrade",1);
> addcolumn(valuewhen(buy,buyprice),"BuyPrice",1.3);
> adddcolumn(c/valuewhen(buy,buyprice),"TradeMove",1.3);
> 
> 
> etc
> 
> 
> 
> 
> 
> On 5/26/05, fanziguk <maxdanzig@xxxx> wrote:
> > Ill put you out of your misery, Peter, and save you weeks if not
> > months of mucking around as I have.
> > 
> > Amibroker is a wonderful program - uniquely fast with it's array
> > based technology. But it does have a major flaw vs other software
> > products. AFL code has NO ACCESS to your ACTUAL trade stats
> > (entryprice, bars in trade etc). Unless you use the built in 
commands
> > to do ultra simple stuff (Applystop etc), you are simply guessing
> > based on the movement of the market. EXREM and EXREMSPAN just help
> > you guess better!
> > 
> > Don't be too depressed though, as the new Custom Backtester does 
have
> > access to the actual trade. But it is very cryptic (easy to make a
> > mistake) and Tomasz appears reluctant to give support for it. I 
have
> > written a piece of CB code that will do what you want. It looks
> > correct but does not work presently. Tomasz has it and 
(hopefully!)
> > one rainy day he might get around to correcting it. I will post it
> > here if so. Or perhaps he would like to?
> > 
> > Max
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Peter" <pa299@xxxx> wrote:
> > > Hi
> > > I'm a new to AFL and need some help with code for a exit on 
first
> > > profitable open.
> > >
> > > I've been using this code in a Commentary window to check if it
> > > works.
> > >
> > > The problem I have is that at times after entering a long 
position
> > > (Buy = false) the variable BuyBarsSince in the line
> > > BuyBarsSince = BarsSince(Buy == 1);
> > > will reset to 0 when Cond1 AND Cond2 AND Cond3 are all true
> > >
> > > The result is an exit below the entry price.
> > >
> > > My question is why at times does
> > > BarsSince(Buy == 1)
> > > reset to 0 when Buy = false?
> > >
> > >
> > > Am I missing obvious?
> > > Any help would be appreciated?
> > > Thanks
> > > Peter
> > >
> > >
> > > //3Down Close Commentary
> > >
> > > Cond1 = Ref(C,1) > Ref(C,0);
> > > Cond2 = Ref(C,-2) > Ref(C,-1);
> > > Cond3 = Ref(C,-3) > Ref(C,-2);
> > >
> > > Buy = Cond1 AND Cond2 AND Cond3 ;
> > > BuyPrice = Ref(Open,0);
> > >
> > > //------------------------------------------
> > > // Exit 1st Profitable Open
> > > // How many bars ago was the last Buy signal?
> > > BuyBarsSince = BarsSince(Buy == 1);
> > > // Actual Price of buy
> > > Price4LastBuy = Ref(BuyPrice, -BuyBarsSince);
> > >
> > > SellCond1 = Cross(Open,Price4LastBuy);
> > > SellCond2 = BarsSince(Buy == 1) > 0;
> > >
> > > Sell = SellCond1 AND SellCond2;
> > > SellPrice = Ref(O,0);
> > >
> > > Sell=ExRem(Sell,Buy); Buy=ExRem(Buy,Sell);
> > >
> > >
> > >
> > > //------------------------------------------
> > >
> > > "3 Down Close Commentary";
> > > "";
> > > "Cond1 is " + WriteVal(Cond1);
> > > "Cond2 is " + WriteVal(Cond2);
> > > "Cond3 is " + WriteVal(Cond3);
> > > "Buy is " + WriteVal(Buy);
> > >
> > > "";
> > > "BuyPrice is " + WriteVal(Price4LastBuy );
> > > "BarsSince(Buy)is " + WriteVal(BarsSince(Cond1 AND Cond2));
> > > "Price4LastBuy is " + WriteVal(Price4LastBuy);
> > >
> > > "";
> > > "SellCond1 is " + WriteVal(SellCond1 );
> > > "SellCond2 is " + WriteVal(SellCond2 );
> > >
> > > "Sell is " + WriteVal(Sell );
> > > "SellPrice is " + WriteVal(SellPrice );
> > 
> > 
> > 
> > 
> > 
> > Please note that this group is for discussion between users only.
> > 
> > To get support from AmiBroker please send an e-mail directly to
> > SUPPORT {at} amibroker.com
> > 
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> > 
> > 
> > Yahoo! Groups Links
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> 
> 
> -- 
> Cheers
> Graham
> http://e-wire.net.au/~eb_kavan/




------------------------ 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
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.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/