Hi
I have been fighting with AFL to write a sample program that let us combine two 
systems, as I told in a recent thread.
I havenĀ“t been able.
The idea is easy: two type of buy conditions, one in the crossing of two 
averages, the other after falling four bars, using EOD bars.
Both systems uses the same pool of money, and are PORTFOLIO SYSTEMS, buying as 
far as ten stocks, 10% of the money every purchase.

THE BUY condition is easy to combine. But I have to tell AFL that if the last 
BUY as been using the First condition, the SELL has to be checked with the 
crossing of the averages again.
And if the last BUY condition as been the second, the SELL condition has to be 
another one. (2 bars away from buying day).
After trying it many times without using Custom backtester interface, I think 
the only way is using backtester interface.
So I write the exact code, so anybody can test it and fill the custom backtest 
part..
I think it should be easy; the problem is that I don't really understand the 
logic of the custom backtester, so I don't know what to do
Any suggestion will be very very much appreciated..



//BEGGINING OF CODE------------------------
posQty=Param("Posiciones simultaneas",10,1,20,1);
CapMinimo=Param("Cap minimo",2,1,200,5);
SetOption("InitialEquity", 100000 ); 
SetOption("AllowPositionShrinking", True ); 
SetOption("MaxOpenPositions", PosQty );
SetOption ("accountmargin",100);
PositionSize = -100/(posqty); 
Buy=Sell=0;
SetTradeDelays(1,1,1,1);

//FIRST SYSTEM-----------------------------------
Buy1= Cross(MA(C,15),MA(C,70));
BuyPrice1=Open;
SellA=Cross(MA(C,70),MA(C,15));
SellPriceA=Open;

//SECOND SYSTEM-----------------------------------
Buy2= C<O AND Ref(C,-1)<Ref(O,-1) AND Ref(C,-2)<Ref(O,-2) AND 
Ref(C,-3)<Ref(O,-3);
SellB= Ref(Buy,-2);

//BUY---------------------------------
Buy=IIf(Buy1,True,IIf(Buy2,True,False));
BuyPrice=Open;
nombre1=Name();


typeBuy=IIf(Buy1,1,IIf(Buy2,2,0));//if buy1, array 'typebuy' is 1. If Buy2, is 
2. Else is 0
n=BarsSince(Buy);

//NEXT TWO SENTENCES DOES NOT WORK
//Sell= IIf( Ref(typebuy,-n)==1, Cross(MA(C,15),MA(C,70)),False);
//Sell= IIf( NOT Sell AND Ref(Buy2,-n),  Ref(Buy,-2),False);

//INSTEAD, USE OF CUSTOMBACKTESTER
SetCustomBacktestProc("");
if (Status("action") == actionPortfolio) {
    bo = GetBacktesterObject(); //  Get backtester object
    bo.PreProcess();    //  Do pre-processing (always required)
    for (i = 0; i < BarCount; i++)      //  Loop through all bars
    {
        for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
        {       
                        if (sig.isentry() AND Buy1[i])
                                
                               //mmmmm ????

        }       //  End of for loop over signals at this bar
        bo.ProcessTradeSignals(i);      //  Process trades at bar (always 
required)
    }   //  End of for loop over bars
    bo.PostProcess();   //  Do post-processing (always required)
}


PositionScore=Ref(StochK(15,3),-1);

Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy);

PlotShapes(IIf(Ref(Buy,-1),shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Ref(Buy,-1),shapeHollowSquare      
,shapeNone),colorBlue,0,BuyPrice,0);
PlotShapes(IIf(Ref(Sell,-1),shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Ref(Sell,-1),shapeHollowSquare,shapeNone),colorRed,0,SellPrice,0);
//---------------END OF CODE--------------



Reply via email to