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

[amibroker] Re: Trading equity-curve in Amibroker



PureBytes Links

Trading Reference Links



Hi,

You must write custom backtester code to do what you are asking. Your final ~~~Equity is simply an array of the bar by bar values of the backtester's Equity property (verify that Plots overlap). As such, you can build up an equivalent equity array as you iterate through the bars in a custom backtest, calculate a MA using that array, and reduce your postion size accordingly.

I have not done any extensive testing on the following code. But, I believe that it will give you what you are asking for. The logic is simply to refer to the equity of the previous bar compared to the MA of equity for that same bar, and reduce position size of the current bar when the relation is not favorable.

Double check the trades to make sure that the timing is right.

Mike

optimistic = Param("Optimistic", 20, 1, 100, 1);
pessimistic =
Param("Pessimistic", 10, 1, 100, 1);
period =
Param("Period", 20, 1, 50, 1);

SetTradeDelays(0, 0, 0, 0);
PositionSize = -1 * optimistic;

weekDay =
DayOfWeek();

Buy = weekDay == 1;
BuyPrice = Open;

Sell = weekDay == 5;
SellPrice = Close;

SetCustomBacktestProc("");

if (Status("action") == actionPortfolio) {
   bo =
GetBacktesterObject();
   bo.PreProcess();

   eq[
0] = 0;

   
for (bar = 0; bar < BarCount; bar++) {
      reduceSize =
false;

      
if (bar > period) {
         eqMA =
MA(eq, period);

         
if (eq[bar - 1] <= eqMA[bar - 1]) {
            reduceSize =
true;
         }
      }

      
if (reduceSize) {
         
for (sig = bo.GetFirstSignal(bar); sig; sig = bo.getNextSignal(bar)) {
            sig.PosSize = -
1 * pessimistic;
         }
      }

      bo.ProcessTradeSignals(bar);
      eq[bar] = bo.Equity;
   }

   bo.PostProcess();

   
AddToComposite(eq, "~~~EQ", "X", atcFlagDefaults | atcFlagEnableInPortfolio);
}

eq =
Foreign("~~~EQ", "C");
Plot(eq, "EQ", colorGreen, styleLine);
Plot(Foreign("~~~Equity", "C"), "Equity", colorBlue, styleLine);
Plot(MA(eq, period), "MA20-EQ", colorRed, styleLine);


--- In amibroker@xxxxxxxxxxxxxxx, Wolfgang Hader <faked@xxx> wrote:
>
> Hi all,
>
> how can I code some like this in Amibroker
> (I know the following code is wrong, but how can I do it correctly in
> Amiboker)?
>
> iif(equity() > ma(equity(),20), positionsize=-20, positionsize=-10);
>
> Thank you,
> BR
>



__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___