PureBytes Links
Trading Reference Links
|
I also agree with your method, so much that I spent a lot of time figuring out how to do it better and make something I can quickly include along with every indicator. I include my TradeVisualizer.afl below. (I don't see a way to attach files in the web interface. )
But I do have many parameters that I need to optimize simultaneously, so I need a metric that I can use for automatic optimization using IO.
dan
---
// TradeVisualizer.afl -- Indicate trades and change in equity.
// Daniel LaLiberte liberte@xxxxxxxxxxxxx
/*
Features:
Show realized and unrealized net profit
Show trade signals.
Show trade arrows.
Bugs, limitations, and side effects:
Assumes GraphZOrder == 0 which is the default.
Assume only one open position.
Calls Equity(0, 0), which should not have side effects.
This visualizer should not affect your actual signals.
Instructions:
Save TradeVisualizer.afl in your Include folder.
Add the following at the end of your scripts, after your final Buy, Sell, Short, Cover assignments:
#include <TradeVisualizer.afl>
Remove your ExRem() calls to see regions of raw Buy, Sell, Short, Cover signals
Things to do:
Show stops/limits.
Deal with order delays - it assumes 1 bar delay.
Show pyramid trades, number of shares per trade.
Display text of profit/loss.
Optionally compute equity across stocks.
Parameterize all this.
Please send improvements or suggestions.
*/
_SECTION_BEGIN ("TradeVisualizer");
//========================================
backgroundColor = colorWhite;
// Colors of signal bars
buyColor = colorPaleGreen; // ColorRGB(230, 255, 230); // very pale
sellColor = colorRose;
shortColor = colorLavender;
coverColor = colorSkyBlue;
// Colors of arrows
buyArrowColor = colorLime;
sellArrowColor = colorRed;
shortArrowColor = colorViolet;
coverArrowColor = colorBlue;
// Colors of net profit
gainColor = colorLime; // unrealized gain relative to last trade
lossColor = colorOrange; // unrealized loss relative to last trade
netPositiveColor = colorGreen; // overall realized net profit is positive
netNegativeColor = colorRed; // overall realized net profit is negative
//========================================
// Only show stuff if this is running as an indicator
isIndicator = Status("action") == actionIndicator;
if (isIndicator)
{
rawBuy = Buy;
rawSell = Sell;
rawShort = Short;
rawCover = Cover;
// Assume only one open position.
buyExRem = ExRem(buy, sell);
sellExRem = ExRem(sell, buy);
shortExRem = ExRem(short, cover);
coverExRem = ExRem(cover, short);
// Show realized and unrealized gain or loss relative to last buy or short trade.
if (ParamToggle("Show net profit", "no|yes", 1))
{
// Last trade event: buy, sell, short or cover.
lastTrade = buyExRem + shortExRem + sellExRem + coverExRem;
closeTrade = sellExRem + coverExRem;
// Calculate equity change since initial equity, i.e. the unrealized net profit.
// Equity is what we might have at the beginning of each bar, if we were to sell all assets.
// Avoid calling Equity(1) which has side effects on trades.
netProfit = Nz( Equity(0, 0) - GetOption("InitialEquity"));
// Calculate realized net profit at beginning of last close trade event.
// Since trade happens at the beginning of the bar after the signal (i.e. a delay of 1),
// then we check whether there was a close trade in the previous bar.
realizedNetProfit = Nz( ValueWhen( Ref(closeTrade, -1), netProfit) );
realP = Ref(realizedNetProfit, 0);
// Move the unrealized profit back to when it was generated by looking forward 1 bar.
unrealP = Ref(netProfit, 1);
PlotOHLC( realP , realP , unrealP , unrealP , "net profit",
Iif (unrealP > realP , gainColor,
Iif (unrealP < realP , lossColor,
// no change, so height is zero. Use realized net profit color instead.
Iif (realizedNetProfit > 0, netPositiveColor, netNegativeColor))),
styleCandle | styleOwnScale ); // Use styleLeftAxisScale if also showing realizedNetProfit above.
}
//========================================
// Show buy, sell, short, or cover signals
if (ParamToggle("Show trade signals", "no|yes", 1))
{
GraphXSpace = 5; // adds 5% extra space above AND below.
Plot(Iif(buyExRem OR sellExRem, 95, 3), "",
Iif(rawBuy, buyColor, Iif(rawSell, sellColor, backgroundColor)),
styleHistogram | styleThick | styleOwnScale | styleNoLabel, 0, 100);
Plot(Iif(shortExRem OR coverExRem, -95, -3), "",
Iif(rawShort, shortColor, Iif(rawCover, coverColor, backgroundColor)),
styleHistogram | styleThick | styleOwnScale | styleNoLabel, - 100, 0);
}
//========================================
// Add up and down arrows. The vertical position will be your first plot, if any.
// Too noisy with many trades.
if (ParamToggle("Show trade arrows", "no|yes", 0))
{
PlotShapes(shapeUpArrow * buyExRem, buyArrowColor);
PlotShapes(shapeDownArrow * sellExRem, sellArrowColor);
// Bump the short and cover arrows out one if there is a sell or buy arrow
PlotShapes(shapeHollowDownArrow * shortExRem, shortArrowColor, 0, graph0, -24 * sellExRem);
PlotShapes(shapeHollowUpArrow * coverExRem, coverArrowColor, 0, graph0, -24 * buyExRem);
}
/*
sinceBuy = BarsSince (buyExRem);
sinceSell = BarsSince (sellExRem);
sinceShort = BarsSince (shortExRem);
sinceCover = BarsSince (coverExRem);
inLong = ref(sinceSell, -1) > sinceBuy;
inShort = ref(sinceCover, -1) > sinceShort;
lastBuyPrice = ref ( BuyPrice, - sinceBuy);
lastShortPrice = ref ( ShortPrice, - sinceShort);
percentBuy = inLong * 100 * (SellPrice - lastBuyPrice) / lastBuyPrice;
percentShort = inShort * 100 * (CoverPrice - lastShortPrice) / lastShortPrice;
*/
} // end if indicator
_SECTION_END ();
--- In amibroker@xxxxxxxxxxxxxxx, Dennis Brown <see3d@xxx> wrote: > > Herman, > > I agree with your method, and that is precisely how I do it. I > actually have a "gold" colored equity plot that I can turn on an off > on right on top of my main chart. > > It is also easy to see what the ideal curve would be, just use a look > ahead (ZigZag, centered MA, etc.) indicator for buy/sell and dream of > the day when you can look ahead one minute into the future. LOL > > Dennis > > On Jun 9, 2007, at 12:48 AM, Herman wrote: > > > this is jmo but if you have enough trades and you don't have too > > many Opt variables, by far the easiest way to optimize is to use > > visual optimizations. > > > > > > > > We do this by running the system in an Indicator and plot the > > equity. Substitute the Optimize() with a Param() and simply drag > > the Param slider left and right. This is a hundreds times faster > > than optimizing and you'll automatically reject over-optimization > > because these conditions don't last over many consecutive opt > > values. You can also immediately see how optimum values for one > > ticker apply to other tickers simply by clicking on the tickers in > > your work space. This, btw, gives you a real good impression on how > > robust (market wise) your system is. You can also immediately pick > > up on any system bias towards stock price, sectors, markets, time > > periods, Long vs Short, etc. And all that is minutes... > > > > > > > > I find the visual feedback is very effective, catches a lot more > > invalid/over-optimized results, and splits etc. Performance is > > immediately obvious from the equity chart. Not only that, if your > > equity jumps up/down you can immediately zoom in on the event and > > analyze that happened. > > > > > > > > I like it simple > > <smile.gif> > > less surprise that way. > > > > > > > > herman > > > > > > > > > > > > > > > > Saturday, June 9, 2007, 11:48:15 AM, you wrote: > > > > > > > > > The linearity of the equity curve is probably one of the best > > measures > > > > > of predictable future performance, if you have enough data > > samples. I > > > > > believe one way to check for the linearity of the equity curve is > > the > > > > > standard error provided in the optimization table and backtest > > > > > report. I'd like to know what the precise definition of this > > standard > > > > > error criteria is, by the way. > > > > > > > > > The data I am working with is 1-minute bars, but part of it was > > > > > collected some time ago when IB was not providing after-market data > > > > > (last fall?), so my bars per day is not uniform, and therefore > > > > > the equity line will have a lower slope in recent months, so my > > > > > standard error measure is higher than it would be with uniform data. > > > > > > > > > Consequently, I've been experimenting with a variation that > > allows the > > > > > trades to be less uniformly distributed over time, but I want the > > > > > profit per trade average to be consistent. I average the profits > > from > > > > > the last 50 trades, for example, and compute the linearity of that > > > > > instead of the equity curve. > > > > > > > > > For both of these, we don't just want a straight equity line - it > > > > > should be a straight line that rises, so we really want a > > combination > > > > > of the net profit and this linearity measure, and one way of > > computing > > > > > that is netProfit / stdErr. > > > > > > > > > There is a lot more to this. Some other factors to consider are how > > > > > much of your equity you are risking with each trade, how long it is > > > > > tied up not doing something else, and the magnitude of your > > potential > > > > > loss. > > > > > > > > > Daniel LaLiberte > > > > > liberte@xxx > > > > > > > > > On Monday 04 June 2007 03:00 pm, Dennis Brown wrote: > > > > >> Alex, > > > > > > > > >> What you might be looking for is how straight the equity curve > > is. I > > > > >> have not tried this yet in automatic mode, but when I plot the > > equity > > > > >> curve I look for the gain and how straight the curve is. As a > > single > > > > >> number, that would likely be the correlation to a straight line > > > > >> between the start and ending equity values. That way you are not > > > > >> fooled by a single rare event. > > > > > > > > >> Dennis > > > > > > > > >> On Jun 4, 2007, at 2:50 PM, dralexchambers wrote: > > > > >> > I am currently testing and optimising a trading system over 1 > > year of > > > > >> > data, and sorting the results by Gross Profit Made. > > > > >> > > > > > >> > What I am finding is that by sorting the results by Gross Profit > > > > >> > Made, the system has long periods of small losses then one big > > gain. > > > > >> > Although over a year this provides a good return, drawdowns in > > the > > > > >> > interim are bad - and I am looking for regular cashflow with > > lower > > > > >> > drawdowns rather than the largest gain made over a year. > > > > >> > > > > > >> > Can anyone think of a way to optimise results for maximal cash- > > flow > > > > >> > each month rather than Gross Profit Made in a year? Is there a > > > > >> > mathematical formula I can use? > > > > >> > > > > > >> > I tried using a average of x bars, but this still doesn't > > solve the > > > > >> > problem, eg: > > > > >> > > > > > >> > Week 1: -$40 > > > > >> > Week 2: -$40 > > > > >> > Week 3: $8000 > > > > >> > > > > > >> > whereas I would like more: > > > > >> > > > > > >> > Week 1: $900 > > > > >> > Week 2: $1500 > > > > >> > Week 3: $2000 > > > > >> > > > > > >> > (this is a very simplified example but illustrates what I am > > after). > > > > >> > > > > > >> > Many thanks, > > > > >> > Alex > > > > > > > > > > > > > > > > > > > > > Please note that this group is for discussion between users only. > > > > > > > > > To get 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 > > > > > > > > > http://groups.yahoo.com/group/amibroker/ > > > > > > > > > Individual Email | Traditional > > > > > > > > > http://groups.yahoo.com/group/amibroker/join > > > > > (Yahoo! ID required) > > > > > > > > > mailto:amibroker-digest@xxxxxxxxxxxxxxx > > > > > mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx > > > > > > > > > amibroker-unsubscribe@xxxxxxxxxxxxxxx > > > > > > > > > http://docs.yahoo.com/info/terms/ > > > > > > > > > > > <smile.gif> >
__._,_.___
Please note that this group is for discussion between users only.
To get 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
SPONSORED LINKS
__,_._,___
|