April 20, 2007
Plotting Trade-Lines
A useful application is to plot straight lines between entry- and exit-signals, giving you the ability to view at a glance the location and magnitude of profits and losses of your trading system. The LineArray() function enables you to draw straight lines from one event or condition to another. In the chart below, which shows a reversal trading system, note how the lines begin and end at the exact trade prices, green being long and red being short. This gives you a quick impression of the profitability and location of individual trades:
Because the LineArray() performs many calculations, it is preferred to restrict the plotting loop to the visible chart only.
Other applications would be plotting of custom ZigZag lines, price channels, trendlines, breakouts, etc.
// Dummy system to generate some signals Buy = Cross( MACD(), Signal() ); Sell = Cross( Signal(), MACD() ); PlotShapes(IIf(Buy, shapeUpTriangle, shapeNone),colorBrightGreen,0,BuyPrice,0); PlotShapes(IIf(Sell, shapeDownTriangle, shapeNone),colorRed,0,SellPrice,0); Plot(C,"",1,128); // Plot the Trade Lines Sig = Buy OR Sell; y0 = 0; y1 = C[0]; TPrice = C; FirstVisibleBar = Status( "FirstVisibleBar" ); Lastvisiblebar = Status( "LastVisibleBar" ); for( b = Firstvisiblebar; b <= Lastvisiblebar AND b < BarCount; b++) { if( Buy[b] ) Co = colorRed; if( Sell[b] ) Co = colorBrightGreen; if(Sig[b]) { x0 = y0; x1 = y1; y0 = b; y1 = TPrice[b]; Plot(LineArray(x0,x1,y0, y1),"",Co,1); } }
Edited by Al Venosa
Filed by Herman at 9:27 pm under AFL - Utilities and Functions


