Hi Steve --

I think this question goes to Tomasz, rather than to me.

Thanks,
Howard

On Mon, Feb 2, 2009 at 9:56 AM, Steve Dugas <[email protected]> wrote:

>   Hi Howard, thanks for the nice post. I have been doing things like this
> with
> Equity() for several years now, but I see one major problem ( bug? ) when
> doing it and I wonder if you might be able to comment or perhaps confirm
> the
> problem?
>
> It seems that, when we generate an equity line based on EOD trading it will
>
> calculate our equity based on the Close price, and when we generate the
> equity line based on NDO trading it calculates our equity based on the Open
>
> price. This is fine, except that ( only ) when trading NDO, the last value
> of the Equity array is apparently *not* calculated on the Open price like
> all the other bars, and so when today's data is downloaded, and the last
> bar
> becomes the next-to-last bar, the equity value for that bar will *change*.
> So if you are using the last value of Equity() as a condition for doing
> something, say for example generating your signals, you run into a *very
> real* problem of signals disappearing the next day, or signals coming a day
>
> late. As a practical matter, it seems that when trading NDO, the equity
> line
> really can't be used for anything other than just looking at it because it
> is not *reliable*. Would you agree that this is the case? I have mentioned
> this to TJ several times in the past but I don't think anything was ever
> done to correct it, I guess I will take this opportunity to bring it up it
> one more time and perhaps if you agree we could try to muster up some
> support for getting it fixed. What do you think? My apologies to TJ if
> there is something that I am not understanding correctly...
>
> Steve
>
>
> ----- Original Message -----
> From: "Howard Bandy" <[email protected] <howardbandy%40gmail.com>>
> To: <[email protected] <amibroker%40yahoogroups.com>>
> Sent: Sunday, February 01, 2009 1:05 PM
> Subject: [amibroker] Using the Equity Curve to control trading logic
>
> > Greetings all --
> >
> > I have received a couple of inquiries about using the equity curve to
> > control the logic of a trading system. Pasted into this posting is a
> > trading system that includes two examples. There are a lot of other
> > ways the equity curve can be used.
> >
> > Thanks,
> > Howard
> >
> >
> > // EquityCurveLogicSwitcher.afl
> > //
> > // Howard Bandy
> > // February 2009
> > //
> > // In response to an inquiry from the forums --
> > //
> > // This is an example of using the daily equity
> > // to control the logic of a trading system.
> > //
> > // Code two trading systems -- System 1 and System 2
> > // For this example, they are the reverse of each other.
> > //
> > // Compute a moving average of daily equity of System 1.
> > // Refer to either today's value, or yesterday's,
> > // depending on when you want to measure and when you
> > // want to act and are able to act.
> > // When the moving average of the equity curve of System 1 is
> > // higher than it was the previous day, trade System 1.
> > // When the moving average is lower, trade System 2.
> > //
> > // An alternative is to use only System 1.
> > // Take signals in the original direction
> > // when the equity curve is rising,
> > // take signals in the opposite
> > // direction when the equity curve is falling.
> > //
> > // ==========================================================
> > // Disclaimer
> > //
> > // This is only an EXAMPLE, it is NOT A FINISHED TRADING SYSTEM.
> > // There are a lot of subtleties to consider when coding
> > // and potentially trading this.
> > //
> > // For example:
> > // When do you enter and exit trades
> > // When do you calcaulate the original equity curve
> > // When do you measure the slope of the original equity curve
> > // Making certain that a signal to go Short causes a Long position to
> exit
> > // And so forth
> > //
> > //
> > // I have probably forgotten to do something important,
> > // and this code is probably incorrect in exactly the way that
> > // will cause you problems.
> > // ==========================================================
> > //
> > // System 1 is a moving average crossover -- replace this
> > // with whatever you want to use.
> >
> > // Code the two trading systems.
> >
> > MA1Len = Optimize("MA1Len",4,1,25,1);
> > MA2Len = Optimize("MA2Len",5,1,25,1);
> >
> > MA1 = MA(C,MA1Len);
> > MA2 = MA(C,MA2Len);
> >
> > System1Buy = Cross(MA1,MA2);
> > System1Sell = Cross(MA2,MA1);
> >
> > System2Buy = Cross(MA2,MA1);
> > System2Sell = Cross(MA1,MA2);
> >
> > // Compute the equity curve resulting from trading System 1.
> >
> > Buy = System1Buy;
> > Sell = System1Sell;
> >
> > eSystem1 = Equity();
> >
> > EquitySmoothLen = 252;
> > SmoothedEquity = EMA(eSystem1,EquitySmoothLen);
> > SmoothedEquityRising = SmoothedEquity > Ref(SmoothedEquity,-1);
> >
> > // The two options --
> > // TRUE == trade two systems
> > // FALSE == trade System 1 in the opposite direction
> >
> > LogicOption = False;
> >
> > if (LogicOption)
> > {
> > // Use the slope of the equity curve of System 1 to
> > // decide whether to trade System 1 or System 2.
> >
> > Buy = IIf(SmoothedEquityRising,System1Buy,System2Buy);
> > Sell = IIf(SmoothedEquityRising,System1Sell,System2Sell);
> > }
> > else
> > {
> > // Use the slope of the equity curve of System 1 to
> > // decide whether or Buy or Short when the System1Buy signal appears
> >
> > Buy = IIf(SmoothedEquityRising,System1Buy,0);
> > Sell = IIf(SmoothedEquityRising,System1Sell,0);
> > Short = IIf(NOT(SmoothedEquityRising),System1Buy,0);
> > Cover = IIf(NOT(SmoothedEquityRising),System1Sell,0);
> > Sell = Sell OR Short;
> > Cover = Cover OR Buy;
> > }
> >
> > e = Equity();
> >
> > // Plot
> >
> > Plot(C,"C",colorBlack,styleCandle);
> > Plot(MA1,"MA1",colorRed,styleLine);
> > Plot(MA2,"MA2",colorBlue,styleLine);
> >
> >
> Plot(SmoothedEquity,"SmoothedEquity",colorRed,styleLine|styleLeftAxisScale);
> > Plot(eSystem1,"eSystem1",colorBlue,styleLine|styleLeftAxisScale);
> > Plot(e,"eUsingSwitch",colorGreen,styleLine|styleLeftAxisScale);
> >
> > // The End
> > // ----------------------------------------------
> >
> >
> > ------------------------------------
> >
> > **** IMPORTANT ****
> > This group is for the discussion between users only.
> > This is *NOT* technical support channel.
> >
> > *********************
> > TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to
> > SUPPORT {at} amibroker.com
> > *********************
> >
> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> >
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> >
> > *********************************
> > Yahoo! Groups Links
> >
> >
> >
> >
>
>  
>

Reply via email to