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

[amibroker] Re: help in writing a formula



PureBytes Links

Trading Reference Links

Thank you Mike. When I backtest, only one trade shows but on the chart
there are many "Buy" & "Sell" signals. Do I do backtest the system by
simply using the backtest button? 

Alan

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> 
> Grrr. Sorry, forgot that Yahoo's rich text editor doesn't work from
> Google's Chrome browser.
> 
> What I intended to say was that the formula looks fine. It is helpful to
> add Plot statements to see what is going on. For example; I have
> modified your formula a bit for clarity, added Plot statements for
> visual confirmation, and ran it against X=^DJI, A=JNJ, B=IP using the
> default AmiBroker database. These symbols were just selected at random.
> 
> The two EMA's are charted as lines, the close > Ref(close, -50) is
> charted as a ribbon at the bottom.
> 
> Mike
> 
> 
> 
> Buy = Sell = Short = Cover = 0;
> 
> x = Foreign( "^DJI","C" );
> Fast = EMA( x, 10 );
> Slow = EMA( x, 20 );
> AbovePrevious = x > Ref( x, -50 );
> 
> YourSystemEntrySignal = Cross( Fast, Slow ) AND AbovePrevious;
> YourSystemExitSignal = Cross( Slow, Fast ) AND NOT AbovePrevious;
> 
> if( Name() == "JNJ" )
> {
>     Buy = YourSystemEntrySignal;
>     Sell = YourSystemExitSignal;
> 
>     SetPositionSize( 500, spsShares );
> }
> 
> if( Name() == "IP" )
> {
>     Short = YourSystemEntrySignal;
>     Cover = YourSystemExitSignal;
> 
>     SetPositionSize( 500, spsShares );
> }
> 
> Plot(Fast, "Fast", colorDarkRed);
> Plot(Slow, "Slow", colorDarkGreen);
> Plot(x, "X", colorLightGrey);
> Plot(1, "AbovePrevious", IIF(AbovePrevious, colorBrightGreen, colorRed),
> styleOwnScale | styleNoLabel | styleNoTitle | styleArea);
> PlotShapes(Buy * shapeUpArrow, colorDarkGreen);
> PlotShapes(Sell * shapeDownArrow, colorDarkRed);
> PlotShapes(Short * shapeHollowDownArrow, colorDarkRed);
> PlotShapes(Cover * shapeHollowUpArrow, colorDarkGreen);
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Alan Nouray" alann@ wrote:
> > >
> > > Thank you Mike. This is what I wrote but when I do backtest, nothing
> > > shows up. Is this correct?
> > >
> > > x=Foreign("X","C");
> > > YourSystemEntrySignal = Cross( EMA(x, 10), EMA(x, 20 ) ) AND x >
> > > Ref(x,-50);
> > > YourSystemExitSignal= Cross(EMA(x, 20), EMA(x, 10)) AND x < Ref(x,
> > -50);
> > >
> > > if( Name() == "A" )
> > > {
> > > Buy = YourSystemEntrySignal;
> > > Sell = YourSystemExitSignal;
> > >
> > > SetPositionSize( 500, spsShares );
> > > }
> > >
> > > if( Name() == "B" )
> > > {
> > > Short = YourSystemEntrySignal;
> > > Cover = YourSystemExitSignal;
> > >
> > > SetPositionSize( 500, spsShares );
> > > }
> > >
> > > Alan
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" sfclimbers@ wrote:
> > > >
> > > > You were not specific enough in your description for anyone to
> write
> > > > the formula. Do you mean that the Cross happens in the EMA of "X",
> > or
> > > > of "A", or of "B"?
> > > >
> > > > In any event, the functions that you will need are as follows:
> > > >
> > > > 1a. Foreign http://www.amibroker.com/guide/afl/afl_view.php?
> > > > name=foreign
> > > > or
> > > > 1b. SetForeign http://www.amibroker.com/guide/afl/afl_view.php?
> > > > name=setFOREIGN
> > > > 2. EMA http://www.amibroker.com/guide/afl/afl_view.php?id=44
> > > > 3. Cross
> http://www.amibroker.com/guide/afl/afl_view.php?name=cross
> > > > 4. Ref http://www.amibroker.com/guide/afl/afl_view.php?name=ref
> > > > 4. How to trade pairs/spreads
> > > > http://finance.groups.yahoo.com/group/amibroker/message/134492
> > > >
> > > > Mike
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Alan Nouray" <alann@> wrote:
> > > > >
> > > > > Can anybody help me how to write and test the following formula:
> > > > >
> > > > > when 10 day ema crosses the 20 day ema and the close of "X" fund
> > is
> > > > > higher than the close 50 days ago, then buy fund "A" and sell
> > > > fund "B"
> > > > >
> > > > > when 20 day ema crosses the 10 day ema and the close of "C" fund
> > is
> > > > > lower than the close 50 days ago, then sell fund "A" and buy
> fund
> > "B"
> > > > >
> > > > > Thank you.
> > > > > Alan
> > > > >
> > > >
> > >
> >
>




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

**** 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:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto: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/