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

Re: [amibroker] 'remebering' a value



PureBytes Links

Trading Reference Links

Hello,

> In an example of VBScript, Tomasz Janeczko wrote:
> 
> > close = AFL("close")
> > buy = AFL( "buy" )
> > sell = AFL("sell")
> > ' this variable holds last buying price
> > ' if it is zero it means that no trade is open
> 
> Is this the price at which one actually bought or the
> last price for which conditions matched the buy criteria?
> That is, will this get reset tomorrow if the buy conditions
> are still met, as happens within AFL? Looks like it must.

No in script you loop through bars by yourself. 
The following if clause:
if ( lastbuyprice = 0 ) AND (buy( i ) = 1) then
lastbuyprice = close( i )
end if

ensures that lastbuyprice changes only if it was zero and a buy signal
occured. So once it is set to non-zero value (on buy signal)
it is not changed until a sell condition happens:

if (lastbuyprice >0 ) AND ( close( i ) > ( 1.1 * lastbuyprice ) ) then
sell( i ) = 1
lastbuyprice = 0
end if

(in this example this is a 10% profit target)

As to your second question:
"Sell on Open if BarsSince(Buy) > N AND Open > BuyPrice"
you can do this in AFL using the following code:

Buy = ... your rule here...
N = 7; // the number of bars to wait
Buy = ExRemSpan( Buy, N ); // filter out repeated buys signals that occur in N days from buy

Sell = BarsSince( Buy ) > N AND Open > ValueWhen( Buy, BuyPrice );
SellPrice = Open;


Best regards,
Tomasz Janeczko
amibroker.com