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

[amibroker] BarsSince(Buy == 1)



PureBytes Links

Trading Reference Links

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 );






------------------------ Yahoo! Groups Sponsor --------------------~--> 
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/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/