Hi Mike,
I went over the code that you referred to,and I do have a couple of questions 
if it is OK with you(or anyone else).The code is below,which I am referring to..

I understand your definition of Bull100,not quite sure why == is used as 
opposed to =.I will read up on that.

I dont follow why the third trigger has 3000,4000 in the code,and there is no 
IFF(fourthtrigger)

"SetPositionSize(IIf(firstTrigger, 1000, IIf(secondTrigger, 2000,
IIf(thirdTrigger, 3000, 4000))), spsValue);"

In regards to reports,it appears that there is only one entry price even though 
there may be multiple scale in entries.Where could i see a detailed list of the 
actual entries

Thanks in advance,

Allan



SetTradeDelays(0, 0, 0, 0);
BuyPrice = Close;
SellPrice = Close;

previousClose = Ref(Close, -1);
rsi2 = RSI(2);

Sell = Cross(rsi2, 70);

//bull100 = Close > EMA(Close, 200) AND Sum(rsi2 < 25, 2) == 2;
bull100 = Close > MA(Close, 200) AND MA(Close, 200) > 0 AND Sum(rsi2 < 25, 2)== 
2;
inFirstPos = Flip(bull100, Sell);
firstTrigger = ExRem(inFirstPos, Sell);

bull200 = Close < ValueWhen(firstTrigger, Close) AND inFirstPos AND
Ref(inFirstPos, -1);
inSecondPos = Flip(bull200, Sell);
secondTrigger = ExRem(inSecondPos, Sell);

bull300 = Close < ValueWhen(secondTrigger, Close) AND inSecondPos AND
Ref(inSecondPos, -1);
inThirdPos = Flip(bull300, Sell);
thirdTrigger = ExRem(inThirdPos, Sell);

bull400 = Close < ValueWhen(thirdTrigger, Close) AND inThirdPos AND
Ref(inThirdPos, -1);
inFourthPos = Flip(bull400, Sell);
fourthTrigger = ExRem(inFourthPos, Sell);

Buy = firstTrigger + (secondTrigger * sigScaleIn) + (thirdTrigger * sigScaleIn)
+ (fourthTrigger * sigScaleIn);
//SetPositionSize(IIf(firstTrigger, 100, IIf(secondTrigger, 200,
//IIf(thirdTrigger, 300, 400))), spsShares);
SetPositionSize(IIf(firstTrigger, 1000, IIf(secondTrigger, 2000,
IIf(thirdTrigger, 3000, 4000))), spsValue);


priceColors = IIf(Close > previousClose, colorDarkGreen, IIf(Close <
previousClose, colorDarkRed, colorDarkGrey));
buyColors = IIf(firstTrigger, colorGreen, IIf(secondTrigger, colorLime,
IIf(thirdTrigger, colorYellow, colorOrange)));

Plot(Close, "Price", priceColors, styleBar);
PlotShapes((Buy > 0) * shapeUpArrow, buyColors, 0, L, -10);


--- In [email protected], "Mike" <sfclimb...@...> wrote:
>
> Allan,
> 
> Writing loops offers ultimate control. For the rare case that array 
> processing is unable to do the job, loops are the only alternative.
> 
> For developers accustomed to languages such as C, C++, Java, etc. loops are 
> also more familiar than working with arrays. However, AFL is built upon array 
> processing and choosing an array based solution will almost always be faster 
> than a looping version.
> 
> That being said, I believe that the looping example that you quote was 
> written by Tomasz. As such, there almost certainly is some subtlety of the 
> particular example that could not be done using arrays. Or perhaps an array 
> implementation would have involved too much indirection as to be overly 
> confusing.
> 
> Generally speaking, the vast majority of looping code can be replaced by use 
> of Flip, ExRem, ValueWhen. The one exception is when later elements of an 
> array are dependent upon previous elements of that same array. Even then, AMA 
> and AMA2 can often handle it.
> 
> In the end, what's most important is that you understand the code. So, go 
> with whichever approach that you find most natural, while still accomplishing 
> the task at hand.
> 
> Mike
> 
> --- In [email protected], "matrix10014" <allansn@> wrote:
> >
> > Thank you Mike..
> > 
> > I do have a couple of questions.Amibroker gives an example of scaling out 
> > of trades and uses code such as the following snippet.
> > 
> > -------------------------------------------
> > priceatbuy=0; 
> > highsincebuy = 0; 
> > 
> > exit = 0; 
> > 
> > for( i = 0; i < BarCount; i++ ) 
> > { 
> >    if( priceatbuy == 0 AND Buy[ i ] ) 
> >     { 
> >        priceatbuy = BuyPrice[ i ]; 
> >     } 
> > 
> >    if( priceatbuy > 0 ) 
> >     { 
> > -------------------------------------------
> > 
> > I have a better chance of running a 3 minute mile than coding something 
> > like that.I noticed in the examples you sent me,the code was more 
> > digestable..Here is a snippet of what you sent
> > 
> > ------------------------------------------------------------------
> > "Buy = firstTrigger + (secondTrigger * sigScaleIn) + (thirdTrigger * 
> > sigScaleIn)
> > + (fourthTrigger * sigScaleIn);
> > //SetPositionSize(IIf(firstTrigger, 100, IIf(secondTrigger, 200,
> > IIf(thirdTrigger, 300, 400))), spsShares);
> > SetPositionSize(IIf(firstTrigger, 1000, IIf(secondTrigger, 2000,
> > IIf(thirdTrigger, 3000, 4000))), spsValue);"
> > -----------------------------------------------------------------
> > 
> > What are the differences between the two approaches?
> > 
> > If I understand FLIP,EXREM,VALUEWHEN,SIGSCALEIN and other functions in your 
> > code,does that serve as a workoaround for the code at the top of the 
> > page??Are those functions intended for mere mortals such as myself??
> > 
> > Thanks for the help,
> > 
> > 
> > Allan
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > --- In [email protected], "Mike" <sfclimbers@> wrote:
> > >
> > > Hi,
> > > 
> > > There have been a couple of complete examples in the last week or so:
> > > 
> > > http://finance.groups.yahoo.com/group/amibroker/message/146956
> > > http://finance.groups.yahoo.com/group/amibroker/message/146976
> > > 
> > > Mike
> > > 
> > > --- In [email protected], "matrix10014" <allansn@> wrote:
> > > >
> > > > Would anyone be so kind to post code to scale in to a position.I have a 
> > > > bear of a time coding in AFL and would like to purchase 50% of my 
> > > > position on a signal,and the other 50% xATR's lower i.e 
> > > > entry price - optimized value x ATR..
> > > > 
> > > > 
> > > > Thanks in advance
> > > > 
> > > > Allan
> > > >
> > >
> >
>


Reply via email to