<\/a><\/p>\nOther applications would be plotting of custom ZigZag lines, price channels, trendlines, breakouts, etc.<\/p>\n
There are two afl versions listed below, since I believe many of us use the first method, I decided to show them both for educational purposes.<\/p>\n
The first one shows how you should NOT<\/strong> plot LineArrays. This method calls Plot() repeatedly and plots each LineArray segment as it is calculated. This is very resource consuming (executes slow) and may trigger a Warning 502 when you display a lot of data. Do not use this version.<\/p>\nThe second version shows how Tomasz (Thanks TJ!) combined the individual LineArray segments inside the loop and then plots them with a single Plot() statement outside the loop. This code executes much faster and will never trigger Warning 502. The technique is simple but shows a clever way to combine array segments. Study it :-) it will come in handy one day!<\/p>\n
<\/span>\/\/ This version is only listed to show you how it should NOT be programmed\r\/\/ Dummy system to generate some signals\r<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );\r<\/span>BuyPrice <\/span>= <\/span>Open<\/span>; <\/span>\/\/ Substitute your own prices\r<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() );\r<\/span>SellPrice <\/span>= <\/span>Close<\/span>; <\/span>\/\/ Substitute your own prices\r<\/span>PlotShapes<\/span>( <\/span>IIf<\/span>( <\/span>Buy<\/span>, <\/span>shapeSmallUpTriangle<\/span>, <\/span>shapeNone <\/span>), <\/span>colorBrightGreen<\/span>, <\/span>0<\/span>, <\/span>BuyPrice<\/span>, <\/span>0 <\/span>);\r<\/span>PlotShapes<\/span>( <\/span>IIf<\/span>( <\/span>Sell<\/span>, <\/span>shapeSmallDownTriangle<\/span>, <\/span>shapeNone <\/span>), <\/span>colorRed<\/span>, <\/span>0<\/span>, <\/span>SellPrice<\/span>, <\/span>0 <\/span>);\r<\/span>Plot<\/span>( <\/span>C<\/span>, <\/span>""<\/span>, <\/span>1<\/span>, <\/span>128 <\/span>);\r<\/span>\/\/ Plot the Trade Lines\r<\/span>Sig <\/span>= <\/span>Buy <\/span>OR <\/span>Sell<\/span>;\r<\/span>y0 <\/span>= <\/span>0<\/span>;\r<\/span>y1 <\/span>= <\/span>C<\/span>[<\/span>0<\/span>];\r<\/span>TPrice <\/span>= <\/span>C<\/span>;\r<\/span>FirstVisibleBar <\/span>= <\/span>Status<\/span>( <\/span>"FirstVisibleBar" <\/span>);\r<\/span>Lastvisiblebar <\/span>= <\/span>Status<\/span>( <\/span>"LastVisibleBar" <\/span>);\r\rfor ( <\/span>b <\/span>= <\/span>Firstvisiblebar<\/span>; <\/span>b <\/span><= <\/span>Lastvisiblebar <\/span>AND <\/span>b <\/span>< <\/span>BarCount<\/span>; <\/span>b<\/span>++ )\r{\r if ( <\/span>Buy<\/span>[<\/span>b<\/span>] )\r {\r <\/span>Co <\/span>= <\/span>colorRed<\/span>;\r <\/span>TPrice<\/span>[<\/span>b<\/span>] = <\/span>BuyPrice<\/span>[<\/span>b<\/span>];\r }\r\r if ( <\/span>Sell<\/span>[<\/span>b<\/span>] )\r {\r <\/span>Co <\/span>= <\/span>colorBrightGreen<\/span>;\r <\/span>TPrice<\/span>[<\/span>b<\/span>] = <\/span>SellPrice<\/span>[<\/span>b<\/span>];\r }\r\r if ( <\/span>Sig<\/span>[<\/span>b<\/span>] )\r {\r <\/span>x0 <\/span>= <\/span>y0<\/span>;\r <\/span>x1 <\/span>= <\/span>y1<\/span>;\r <\/span>y0 <\/span>= <\/span>b<\/span>;\r <\/span>y1 <\/span>= <\/span>TPrice<\/span>[<\/span>b<\/span>];\r <\/span>Plot<\/span>( <\/span>LineArray<\/span>( <\/span>x0<\/span>, <\/span>x1<\/span>, <\/span>y0<\/span>, <\/span>y1 <\/span>), <\/span>""<\/span>, <\/span>Co<\/span>, <\/span>1 <\/span>);\r }\r}<\/span><\/pre>\n<\/span>\/\/ Improved version\r\/\/ Dummy system to generate some signals\r<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );\r<\/span>BuyPrice <\/span>= <\/span>O<\/span>; <\/span>\/\/ Substitute your own prices\r<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() );\r<\/span>SellPrice <\/span>= <\/span>C<\/span>; <\/span>\/\/ Substitute your own prices\r<\/span>PlotShapes<\/span>( <\/span>IIf<\/span>( <\/span>Buy<\/span>, <\/span>shapeUpTriangle<\/span>, <\/span>shapeNone <\/span>), <\/span>colorBrightGreen<\/span>, <\/span>0<\/span>, <\/span>BuyPrice<\/span>, <\/span>0 <\/span>);\r<\/span>PlotShapes<\/span>( <\/span>IIf<\/span>( <\/span>Sell<\/span>, <\/span>shapeDownTriangle<\/span>, <\/span>