PureBytes Links
Trading Reference Links
|
Okay, I feel like I now understand looping and arrays (hopefully) as my NextBuyArray seems to be working as intended at least according to the graphical information.
However, I cannot seem to get the sigscalein part to work. Can someone point me in the right direction as to what adjustments I need to make with the pyramiding buy rule in order to buy additional shares? I have moved the buy rule around to different points in the loop without being able to have additional buys.
Thanks in advance
FastMALength = 50; //Set Fast Moving Average
SlowMALength = 200; //Set Slow Moving Average
FastMA = MA(Close, FastMALength); //Fast Moving Average
SlowMA = MA(Close, SlowMALength); //Slow Moving Average
Buy = Cross(FastMA, SlowMA); //Buy Rule #1 - Fast MA Crosses Above Slow MA
PlotShapes(Buy*shapeUpArrow, colorGreen, 0, Low);
Sell = Cross(SlowMA, FastMA); //Sell Rule #1 - Fast MA Crosses Below Slow MA
BuyInc = 5; //Incremental Buy Amount
NextBuyARRAY = Null; //Initial Value
priceatbuy = 0; //Initial Value
CounterARRAY = Null; //Initial Value
for ( i = 200; i < BarCount; i++ )
{
if(priceatbuy == 0 AND Buy[ i ] )
{
priceatbuy = BuyPrice[ i ]; //Set inital entry Price
}
if(priceatbuy > 0)
{
//Set next BuyPrice
if(Close[ i ] > priceatbuy)
{
counterARRAY[ i ] = Max( CounterARRAY[ i - 1], 1 + int( ( (Close[ i - 1 ] - priceatbuy) / priceatbuy) / (BuyInc/100) ) );
NextBuyARRAY[ i ] = Max( NextBuyARRAY[ i ], priceatbuy * (1 + ((BuyInc / 100) * counterARRAY[ i ])));
}
//This seems to be my point of confusion.
if(Close [ i ] > NextBuyArray [ i ])
{
Buy[ i ] = sigScaleIn;
BuyPrice[ i ] = Close[ i ];
}
}
}
Plot(Close, "Price", colorBlack, styleCandle);
Plot(priceatbuy, "Entry", colorGreen);
Plot(NextBuyARRAY, "NextBuy", colorRed);
Plot(CounterARRAY, "Counter", colorBlue);
SetPositionSize( 5, spsPercentOfEquity);
SetPositionSize( 1, IIf(Buy == sigScaleIn, spsPercentOfEquity, spsNoChange) );
--- In amibroker@xxxxxxxxxxxxxxx, "readshark" <readshark@xxx> wrote:
>
> Yes, I did. Thank you. I do need to use some of that for position sizing.
>
> My problem at the moment, is that my buys do not seem to be buying as I intended. Even my initial buy does not look like it is buying on MA crosses. My incremental scale-ins are not working at all.
>
> Any one see what I am doing wrong?
>
> --- In amibroker@xxxxxxxxxxxxxxx, reinsley <reinsley@> wrote:
> >
> >
> >
> > Hi,
> >
> > Did you see this help page and related formulas ?
> >
> > http://www.amibroker.com/guide/afl/afl_view.php?id=272
> >
> > Best regards
> >
> >
> >
> > Le 26/01/2010 02:21, readshark a écrit :
> > >
> > >
> > > I am trying to code a pyramiding trading system to Buy on a MA
> > > Crossover, and Buy more each time the price rises by 5%. For example if
> > > the MA crossover occurred at 100, the system would continue to buy at
> > > 105, 110, 115, 120, 125, etc.
> > >
> > > Here is my code thus far. It looks like it is buying and selling on the
> > > same day, but not pyramiding as I explained (or tried to) above.
> > >
> > > Thanks in advance.
> > >
> > > _______
> > >
> > > PositionSize = -5;
> > > FastMALength = 50;
> > > SlowMALength = 200;
> > >
> > > FastMA = MA(Close, FastMALength);
> > > SlowMA = MA(Close, SlowMALength);
> > > Vol = MA(Volume, 100);
> > >
> > > Buy = Cross(FastMA, SlowMA);
> > > Sell = Cross(SlowMA, FastMA);
> > >
> > > Buy = Buy + sigScaleIn;
> > >
> > > BuyInc = 5;
> > > NextBuy = 0;
> > >
> > > for ( i = 0; i < BarCount; i++ )
> > > {
> > > if( NextBuy > 0 && Close[ i ] > NextBuy[ i ])
> > > {
> > > Buy[ i ] = sigScaleIn;
> > > }
> > > if(Close[ i ] > BuyPrice[ i ])
> > > {
> > > counter = int((Close[ i ] - BuyPrice[ i ]) / BuyInc) + 1;
> > > NextBuy = ( (BuyInc / 100) * counter[ i ]) * BuyPrice[ i ];
> > >
> > > }
> > > }
> > >
> > >
> >
>
------------------------------------
**** 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/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
amibroker-digest@xxxxxxxxxxxxxxx
amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|