You will need to increase the loop to cover the number of times the
sigscalein can be used.
btw the did not need to use a loop for the buy that you have,
*Buy* = IIf(BuySig,*sigScaleIn*,0);


and what you are using in the loop is incorrect as you are referencing the
bar number in this instance and the results you would ahve gotten would be
based on incorrect calculations
here is a rough idea on how to put this together. This does not take into
account everything possible, but should be a start
**

BuySig = Cross(*C*,EMA(*C*,20));

Sell= Cross(EMA(*C*,50),*C*);



*PositionSize* = -3;

SetFormulaName("Test");

SetOption("MaxOpenPositions",12);

SetOption("CommissionAmount",0.00);

SetOption("CommissionMode",2);

SetOption("InitialEquity",100000);

SetOption("PriceBoundChecking",1);

SetOption("UsePrevBarEquityForPosSizing",0);

SetOption("PortfolioReportMode",0);

SetTradeDelays(0,0,0,0);

*BuyPrice*=*SellPrice*=*ShortPrice*=*CoverPrice*=*Close*;



buy = 0;
count = 0;
*for*(i=1; i<barcount; i++);

{

* if(BuySig*[i] and count<5)

{

 Buy[i] = *sigScaleIn*;

  Count++;

}

if(Sell[i]) count = 0;
}


--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://www.aflwriting.com

On 20/11/06, Fred S. Esch <[EMAIL PROTECTED]> wrote:

 I am presently also trying to understand how to employ SigScaleIn
effectively.  I wish to go Long using 3% of available equity no more than
four times prior to a Sell for a given equity assuming repeated buy signals
are received prior to a Sell signal.  Following your suggestions I've tried
to encode a For Loop for this purpose but I obtain no Buy signals.
Replacing the For Loop with "Buy = BuySig" in the code below I obtain 77
trades.  Would you (or anyone else) be kind enough to indicate the error of
my ways?



BuySig = Cross(*C*,EMA(*C*,20));

SellSig= Cross(EMA(*C*,50),*C*);



*PositionSize* = -3;

SetFormulaName("Test");

SetOption("MaxOpenPositions",12);

SetOption("CommissionAmount",0.00);

SetOption("CommissionMode",2);

SetOption("InitialEquity",100000);

SetOption("PriceBoundChecking",1);

SetOption("UsePrevBarEquityForPosSizing",0);

SetOption("PortfolioReportMode",0);

SetTradeDelays(0,0,0,0);

*BuyPrice*=*SellPrice*=*ShortPrice*=*CoverPrice*=*Close*;



  *for*(i=1; i<5; i++);

  {  *Buy* = IIf(BuySig[i],*sigScaleIn*,0);

  }





*Sell*   = SellSig;




 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Graham
*Sent:* Wednesday, November 15, 2006 2:15 PM
*To:* [email protected]
*Subject:* Re: [amibroker] Re: Pyramiding: buy a 2nd time if buy cryteria
is reached,



supistarde

maxopenpositions limits the number of stocks that can have trades open
duiring a backtest

scaling into trades is not affected this setting
How you define the scaling depends on what you wnat to do

eg to scale in every time you get a buy condtion true you can simply write

buy = ( buyconditions ) * sigscalein;
sell = sellconditions;

alternatively something like this could be used

buy = buyconditions;
sell = sellconditions;
inTrade = flip(buy,sell);
buy = buy and iif( intrade, sigscalein, 1);

to change the positionsixze for the scalein then you use setpositionsize
function, see examples in help for this

there are a number of methods to achieve the scaling and what you use
depends on the conditions for the buys and sells. sometimes straight
condition statements are enough, other times you may nbeed to place them
into a for loop, or in extreme cases when the scaling is dependant on the
results of the first pass backtest then the custom backtest code is needed
(as you are a beginner in AFL I suggest you stay with the simpler methods
and build your knowledges of AB and the aFL)

Look through the help files and also search on the archives of this group
for information on writing AFL.

--
Cheers
Graham
AB-Write >< Professional AFL Writing Service
Yes, I write AFL code to your requirements
http://www.aflwriting.com

On 16/11/06, *Mark H* <[EMAIL PROTECTED]> wrote:

You would need to use the custom backtester (CBT) to do the position
sizing. See amibroker knowledge base for some examples.



 ----- Original Message -----

*From:* supistarde <[EMAIL PROTECTED]>

*To:* [email protected]

*Sent:* Wednesday, November 15, 2006 1:22 PM

*Subject:* [amibroker] Re: Pyramiding: buy a 2nd time if buy cryteria is
reached,



does it not work at amibroker?

--- In [email protected], "supistarde" <[EMAIL PROTECTED]> wrote:
>
> Hello community,
>
> I know how to minimize open positions:
> SetOption("maxopenpositions",2);
>
> but how does this sigScaleIn work?
> I want to buy further stocks if my buy conditions are met a second
> time. The second position should have half the size of the first
> position.
> How do I do this?
>
> Buy = Buy + sigScaleIn * DoScaleIn
> How do I link sigscalein to my buy signal?
>
> Regards,
>



Reply via email to