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

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



PureBytes Links

Trading Reference Links

And by the way, this could help.  It was written by TJ. The problem with AB is the lack of doc. It’s all scattered in the yahoo group and it really takes a lot of effort and time to find the things you want to learn. This formula will sell at the open on the first profitable day.

 

Buy=H > O + Ref(H - L,-1);

BuyPrice=Max(O, Ref(H - L,-1) + TickSize);

 

entrybar = -1;

 

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

{

if( entrybar == -1 AND Buy[ i ] )

{

entrybar = i;

}

 

if( entrybar != -1 AND i > entrybar + 1 AND Open[ i ] > Close[ entrybar ] )

{

Sell[ i ] = 1;

SellPrice[ i ] = Open[ i ];

entrybar = -1;

}

else

{

Sell[ i ] = 0;

}

}

 

-----Message d'origine-----
De : amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] De la part de Peter
Envoyé : 25 mai 2005 23:51
À : amibroker@xxxxxxxxxxxxxxx
Objet : [amibroker] BarsSince(Buy == 1)

 

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






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


--
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.322 / Virus Database: 266.11.17 - Release Date: 2005-05-25


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.322 / Virus Database: 266.11.17 - Release Date: 2005-05-25