Average Down / Rebalancing

#1
Hi, im a noob to Amibroker.

Looking for an example of code that Averages Down a trade using AFL.

For instance, during a backtest, if the Current Bar Close Price is 30% less than the Last Open Position, then trigger a "sigScaleIn" signal.

The problem Im having is getting the Price of the last trade or the Original Opening Trade.

Ive tried using BuyPrice but im not sure what it is that is contained within that Variable. Reading some of the DOCs, it seems it holds the Buy Point info (O, H, L, C) and not the actual purchase price of the current open position.

Or am I just really screwed up here - :)

I am a programmer - But only been playing with the AFL for a few days.

Or:

Is the only real way to do this is by using a FOR loop and run through the array to find the price? - Kinda looks like that after going through some of the other examples.

Kevin :D
 
Last edited:

iamaaditya

Active Member
#2
no, you don't have to use for loop,.....
use ValueWhen
ie. say you want the value of buyprice last time when buy was true..
simple...
bPrice = ValueWhen(Buy, BuyPrice, 1);

the last 1 represents the last value , if you want the second last value it would be 2 , so on and so forth. hope this helps....
 

Similar threads