<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>AmiBroker Users' Knowledge Base</title>
	<atom:link href="http://www.amibroker.org/userkb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.amibroker.org/userkb</link>
	<description>Share your experience, code and everything with other AmiBroker Users'.</description>
	<pubDate>Fri, 13 Mar 2009 13:29:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Plotting trades on chart</title>
		<link>http://www.amibroker.org/userkb/2009/02/21/plotting-trades-on-chart/</link>
		<comments>http://www.amibroker.org/userkb/2009/02/21/plotting-trades-on-chart/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 19:57:09 +0000</pubDate>
		<dc:creator>suresh</dc:creator>
		
		<category><![CDATA[AmiBroker Tools and Features]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[AFL Trade Reviews]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/?p=1844</guid>
		<description><![CDATA[
the objective is to plot trades on chart so that it can be revieweed periodically to learn to trade better. the objective

is to produce a generic afl that will take in the symbol, trade dates and prices and plot on a chart.
support different timeframes so the plotting is still visible. daily, weekly, intraday, 5 minute/15 [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.amibroker.org/userkb/wp-content/uploads/2009/02/tradereview1.png"></p>
<p>the objective is to plot trades on chart so that it can be revieweed periodically to learn to trade better. the objective</p>
<ul>
<li>is to produce a generic afl that will take in the symbol, trade dates and prices and plot on a chart.</li>
<li>support different timeframes so the plotting is still visible. daily, weekly, intraday, 5 minute/15 minute</li>
<li>ability to support position scaling as there may be multiple trade entries /exits</li>
</ul>
<p> </p>
<p>this afl needs the input in term<a href="http://www.amibroker.org/userkb/wp-content/uploads/2009/02/2009-02-21_1253.png"></a>s of static variables as follows. so you may need an adapter that will take your trades and put it to afl.</p>
<div>

<div class="wp_syntax"><div class="code"><pre class="afl"><span style="color: #007f00; ">// defines if it is a stock or forex.</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;TradeType&quot;</span> , <span style="color: #7f007f;">&quot;Stocks&quot;</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">//Stocks|Forex</span>
<span style="color: #007f00; ">// defines the forex symbol</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;forexSymbol&quot;</span> , <span style="color: #7f007f;">&quot;SBUX&quot;</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">//&quot;EUR.USD-IDEALPRO-CASH|</span>
<span style="color: #007f00; ">// defines the stock symbol</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;StockSymbol&quot;</span>, <span style="color: #7f007f;">&quot;SBUX&quot;</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// &quot;YHOO&quot;</span>
<span style="color: #007f00; ">// long or short trade.</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ShortOrLong&quot;</span> , <span style="color: #7f007f;">&quot;Long&quot;</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">//&quot;Short|Long&quot;</span>
<span style="color: #007f00; ">// entry prices</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;EntryPrice&quot;</span> , <span style="color: #7f007f;">&quot;14.5,15.5&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// exit prices</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ExitPrice&quot;</span> , <span style="color: #7f007f;">&quot;14.3&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// entry date in date number comma delimited</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;EntryDate&quot;</span> , <span style="color: #7f007f;">&quot;1080717,1080723&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// exit date in date number. comma delimited</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ExitDate&quot;</span>, <span style="color: #7f007f;">&quot;1080725&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// entry time in time number comma delimited</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;EntryTime&quot;</span>, <span style="color: #7f007f;">&quot;142500,120000&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// exit time in time number comma delimited</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ExitTime&quot;</span> , <span style="color: #7f007f;">&quot;110500&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// trade id. its an internal key for me</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Tradeid&quot;</span> , <span style="color: #7f007f;">&quot;4&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// trade strategy.</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;TradeStrategy&quot;</span> , <span style="color: #7f007f;">&quot;fsdfdsfds&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// any comments on trade</span>
StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;TradeComments&quot;</span> , <span style="color: #7f007f;">&quot;this is the comment&quot;</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; font-style: italic;">/* sets no of entries so that the code loops when printing the number
of trdes.
if 1, then ther should be only 1 entry date/time
if there are more thatn 1 entry or exits, the number of comma delimited entries exits should match the static variable NoOfEntries and same applies for exits
*/</span>
StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;NoOfEntries&quot;</span> , <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">//same as above.</span>
StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;NoOfExits&quot;</span> , <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="afl"> </pre></div></div>

</div>
<p> </p>
<p><CODE><br />
SetChartOptions( 0, chartShowArrows | chartShowDates );<br />
_N( Title = StrFormat( &#8220;{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}&#8221;, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );<br />
Title = Title + &#8220;\n&#8221; + NumToStr( DateNum() );<br />
Title = Title + &#8220;\n&#8221; + NumToStr( TimeNum() );<br />
Plot( C, &#8220;Close&#8221;, ParamColor( &#8220;Color&#8221;, colorBlack ), styleNoTitle | ParamStyle( &#8220;Style&#8221; ) | GetPriceStyle() );<br />
//_TRACE(&#8221;ABTest: test trace1 &#8220;);</p>
<p>//#include &#8220;C:\Program Files\AmiBroker\sharedLibrary\DateTimeToNumber.afl&#8221;</p>
<p>/*<br />
#include &#8220;C:\Program Files\AmiBroker\sharedLibrary\DateTimeToNumber.afl&#8221;<br />
        StaticVarSetText( &#8220;TradeType&#8221; ,&#8221;Stocks&#8221;);  //Stocks|Forex<br />
        StaticVarSetText( &#8220;forexSymbol&#8221; ,&#8221;AAPL&#8221;); //&#8221;EUR.USD-IDEALPRO-CASH|<br />
        StaticVarSetText( &#8220;StockSymbol&#8221;,&#8221;AAPL&#8221;); //  &#8220;YHOO&#8221;<br />
        StaticVarSetText( &#8220;ShortOrLong&#8221; ,&#8221;Short&#8221;);  //&#8221;Short|Long&#8221;<br />
        StaticVarSet( &#8220;EntryPrice&#8221; ,163.52000);<br />
        StaticVarSet( &#8220;ExitPrice&#8221; ,148.18000);<br />
        StaticVarSet( &#8220;EntryDate&#8221; ,Date_To_Num(&#8221;20080721&#8243;));<br />
        StaticVarSet( &#8220;ExitDate&#8221; ,Date_To_Num(&#8221;20080721&#8243;));<br />
        StaticVarSet( &#8220;EntryTime&#8221;,Time_To_Num(&#8221;11:01:47&#8243;) );<br />
        StaticVarSet( &#8220;ExitTime&#8221; ,Time_To_Num(&#8221;17:52:17&#8243;));</p>
<p>StaticVarSetText( &#8220;TradeType&#8221; , &#8220;Stocks&#8221; );  //Stocks|Forex<br />
StaticVarSetText( &#8220;forexSymbol&#8221; , &#8220;SBUX&#8221; ); //&#8221;EUR.USD-IDEALPRO-CASH|<br />
StaticVarSetText( &#8220;StockSymbol&#8221;, &#8220;SBUX&#8221; ); //  &#8220;YHOO&#8221;<br />
StaticVarSetText( &#8220;ShortOrLong&#8221; , &#8220;Long&#8221; );  //&#8221;Short|Long&#8221;<br />
StaticVarSetText( &#8220;EntryPrice&#8221; , &#8220;14.5,15.5&#8243; );<br />
StaticVarSetText( &#8220;ExitPrice&#8221; , &#8220;14.3&#8243; );<br />
StaticVarSetText( &#8220;EntryDate&#8221; , &#8220;1080717,1080723&#8243; );<br />
StaticVarSetText( &#8220;ExitDate&#8221;, &#8220;1080725&#8243; );<br />
StaticVarSetText( &#8220;EntryTime&#8221;, &#8220;142500,120000&#8243; );<br />
StaticVarSetText( &#8220;ExitTime&#8221; , &#8220;110500&#8243; );<br />
StaticVarSetText( &#8220;Tradeid&#8221; , &#8220;4&#8243; );<br />
StaticVarSetText( &#8220;TradeStrategy&#8221; , &#8220;fsdfdsfds&#8221; );<br />
StaticVarSetText( &#8220;TradeComments&#8221; , &#8220;this is the comment&#8221; );</p>
<p>StaticVarSet( &#8220;NoOfEntries&#8221; , 2 );<br />
StaticVarSet( &#8220;NoOfExits&#8221; , 1 );</p>
<p>*/</p>
<p>function returnBarIndex( array )<br />
{<br />
    indx = -1;</p>
<p>    for ( i = 1; i &lt; BarCount;i++ )<br />
    {</p>
<p>        if ( array[i] == True )<br />
        {<br />
            indx = i;<br />
        }<br />
    }</p>
<p>    return indx;<br />
}</p>
<p>function returnShiftedArray( array, shift )<br />
{</p>
<p>    newArray = array;</p>
<p>    for ( i = 1; i = 0 ) &amp;&amp; ( ( shift + i ) &lt; BarCount ) )<br />
        {</p>
<p>            newArray[shift+i] = True;<br />
            newArray[i] = False;</p>
<p>        }<br />
    }</p>
<p>    return newArray;<br />
}</p>
<p>if (  StrToUpper( Name() ) == StrToUpper( StaticVarGetText( &#8220;forexSymbol&#8221; ) ) OR ( StrToUpper( Name() ) == StrToUpper( StaticVarGetText( &#8220;StockSymbol&#8221; ) ) ) )</p>
<p>{<br />
// get the static variables</p>
<p>    TradeType = StaticVarGetText( &#8220;TradeType&#8221; );<br />
    forexSymbol = StaticVarGetText( &#8220;forexSymbol&#8221; );<br />
    StockSymbol = StaticVarGetText( &#8220;StockSymbol&#8221; );<br />
    ShortOrLong = StaticVarGetText( &#8220;ShortOrLong&#8221; );</p>
<p>    if ( TradeType == &#8220;Stocks&#8221; )<br />
    {<br />
        stockname = stockSymbol;</p>
<p>        SetOption( &#8220;FuturesMode&#8221;, False );<br />
    }<br />
    else<br />
    {<br />
        stockname = forexSymbol;<br />
        SetOption( &#8220;FuturesMode&#8221;, True );</p>
<p>    }</p>
<p>    for ( i = 0 ;i &lt; StaticVarGet( &#8220;NoOfEntries&#8221; ) ;i++ )<br />
    {<br />
        VarSet( &#8220;EntryDate&#8221; + ( i ), StrToNum( StrExtract( StaticVarGetText( &#8220;EntryDate&#8221; ), ( i ) ) )  );<br />
        VarSet( &#8220;EntryPrice&#8221; + ( i ), StrToNum( StrExtract( StaticVarGetText( &#8220;EntryPrice&#8221; ), ( i ) ) )  );<br />
        VarSet( &#8220;EntryTime&#8221; + ( i ), StrToNum( StrExtract( StaticVarGetText( &#8220;EntryTime&#8221; ), ( i ) ) )  );</p>
<p>        _TRACE( &#8220;ABTest: test 182 &#8221; + &#8220;EntryDate&#8221; + ( i ) + NumToStr( VarGet( &#8220;EntryDate&#8221; + ( i ) ) ) );<br />
        _TRACE( &#8220;ABTest: test 182 &#8221; + &#8220;EntryDate&#8221; + ( i ) +  &#8220;string&#8221; + StrExtract( StaticVarGetText( &#8220;EntryDate&#8221; ), ( i ) ) );<br />
    }</p>
<p>// TESTING IF THE VARIABLES EXIST<br />
    for ( i = 0 ;i &lt; StaticVarGet( &#8220;NoOfEntries&#8221; ) ;i++ )<br />
    {<br />
        _TRACE( &#8220;ABTest: test 182 TESTING&#8221; + &#8220;EntryDate&#8221; + ( i ) + NumToStr( VarGet( &#8220;EntryDate&#8221; + ( i ) ) ) );<br />
        _TRACE( &#8220;ABTest: test 182 TESTING timeframe&#8221; + inWeekly );<br />
    }</p>
<p>    for ( j = 0 ;j &lt; StaticVarGet( &#8220;NoOfExits&#8221; ) ;j++ )<br />
    {<br />
        VarSet( &#8220;ExitDate&#8221; + ( j ), StrToNum( StrExtract( StaticVarGetText( &#8220;ExitDate&#8221; ), ( j ) ) )  );<br />
        VarSet( &#8220;ExitTime&#8221; + ( j ), StrToNum( StrExtract( StaticVarGetText( &#8220;ExitTime&#8221; ), ( j ) ) )  );</p>
<p>        VarSet( &#8220;ExitPrice&#8221; + ( j ), StrToNum( StrExtract( StaticVarGetText( &#8220;ExitPrice&#8221; ), ( j ) ) )  );<br />
        // _TRACE( &#8220;ABTest: test 182 &#8221; + &#8220;ExitDate&#8221; + ( j ) +  &#8220;string&#8221; + StrExtract( StaticVarGetText( &#8220;ExitDate&#8221; ), ( j ) ) );</p>
<p>    }</p>
<p>//Buy = Sell = Short = Cover = entryPrices = exitPrices = False;</p>
<p>    // if the symbol matches what i am looking for<br />
    dn = DateNum();</p>
<p>    tn = TimeNum();</p>
<p>    entryPrices = exitPrices = Buy = Sell = Short = Cover = False;</p>
<p>    range = H - L;</p>
<p>    switch ( Interval() )<br />
    {<br />
            // START OF SWITCH.</p>
<p>        case inDaily:</p>
<p>            for ( b = 0;b &lt; BarCount;b++ )<br />
            {<br />
                // START OF DAILY</p>
<p>                for ( i = 0 ;i 	dn[b] - 1 )  AND ( VarGet( &#8220;EntryDate&#8221; + i ) &lt; dn[b] + 1	 )  )<br />
                    {</p>
<p>                        entryPrices[b] = VarGet( &#8220;EntryPrice&#8221; + i );<br />
                        Buy[b] = Short[b] = True;<br />
                        //_TRACE( &#8220;ABTest: test 182 matching price &#8221; + NumToStr( VarGet( &#8220;EntryPrice&#8221; + i ) ) ) ;</p>
<p>                        PlotText( StaticVarGetText( &#8220;ShortOrLong&#8221; ) +  &#8221; entry &#8221; + i + &#8221; &#8221; + &#8220;:&#8221; + entryPrices[b]   , b, High[b] + range[b], colorBlue );<br />
                        // PlotText( &#8220;entry&#8221; + VarGet( &#8220;EntryPrice&#8221; + i )  , b, EntryPrice0, colorBlue );</p>
<p>                        //  _TRACE( &#8220;ABTest: test 182 MATCHED &#8221; + NumToStr( VarGet( &#8220;EntryDate&#8221; + i ) ) + NumToStr( dn[b] ) );</p>
<p>                    }</p>
<p>                    for ( j = 0 ;j  	dn[b] - 1 )  AND ( VarGet( &#8220;ExitDate&#8221; + j ) &lt; dn[b] + 1	 )  )</p>
<p>                        {</p>
<p>                            exitPrices[b] = VarGet( &#8220;ExitPrice&#8221; + j );<br />
                            Sell[b] = Cover[b] = True;</p>
<p>                            PlotText(  StaticVarGetText( &#8220;ShortOrLong&#8221; ) + &#8221; Exit &#8221;  +  j  + &#8220;:&#8221; + VarGet( &#8220;ExitPrice&#8221; + j )  , b, Low[b] - range[b], colorRed );<br />
                            // _TRACE( &#8220;ABTest: test 182 MATCHED &#8221; + NumToStr( VarGet( &#8220;ExitPrice&#8221; + j ) ) + NumToStr( dn[b] )  + NumToStr( VarGet( &#8220;ExitDate&#8221;  + j )));</p>
<p>                        }</p>
<p>                    }</p>
<p>                }</p>
<p>            } // START OF DAILY</p>
<p>            break;</p>
<p>        case inWeekly:</p>
<p>            for ( b = 1;b &lt; BarCount - 1;b++ )<br />
            {<br />
                // START OF weekly</p>
<p>                for ( i = 0 ;i 0)<br />
                    	PreviousBar=b-1;<br />
                    	NextBar=b;<br />
                    	if(b=	dn[b] )  AND ( VarGet( &#8220;EntryDate&#8221; + i ) &lt; dn[b+1]	)   )<br />
                    {</p>
<p>                        entryPrices[b] = VarGet( &#8220;EntryPrice&#8221; + i );<br />
                        Buy[b] = Short[b] = True;<br />
                        _TRACE( &#8220;ABTest: test 182 matching price entry &#8221; + NumToStr( VarGet( &#8220;EntryPrice&#8221; + i ) ) ) ;</p>
<p>                        PlotText(  StaticVarGetText( &#8220;ShortOrLong&#8221; ) + &#8221; entry&#8221; + i + &#8221; &#8221; + &#8220;:&#8221; + entryPrices[b]   , b, High[b] + range[b], colorBlue );<br />
                        // PlotText( &#8220;entry&#8221; + VarGet( &#8220;EntryPrice&#8221; + i )  , b, EntryPrice0, colorBlue );</p>
<p>                        //  //( &#8220;ABTest: test 182 MATCHED &#8221; + NumToStr( VarGet( &#8220;EntryDate&#8221; + i ) ) + NumToStr( dn[b] ) );</p>
<p>                    }</p>
<p>                    for ( j = 0 ;j =	dn[b-1] )  AND (VarGet( &#8220;EntryDate&#8221; + i )= 	dn[b] )  AND ( VarGet( &#8220;ExitDate&#8221; + j ) &lt; dn[b+1]	 )  )</p>
<p>                        {</p>
<p>                            exitPrices[b] = VarGet( &#8220;ExitPrice&#8221; + j );<br />
                            Sell[b] = Cover[b] = True;</p>
<p>                            PlotText(  StaticVarGetText( &#8220;ShortOrLong&#8221; ) + &#8221; Exit&#8221;  +  j  + &#8220;:&#8221; + VarGet( &#8220;ExitPrice&#8221; + j )  , b, Low[b] - range[b], colorRed );<br />
                            //  _TRACE( &#8220;ABTest: test 182 MATCHED &#8221; + NumToStr( VarGet( &#8220;ExitPrice&#8221; + j ) ) + NumToStr( dn[b] )  + NumToStr( VarGet( &#8220;ExitDate&#8221;  + j )));</p>
<p>                        }</p>
<p>                    }</p>
<p>                }</p>
<p>            } // START OF weekly</p>
<p>            break;</p>
<p>            //_TRACE(&#8221;ABTest: test 182 &#8221; +&#8221;getting to break&#8221;);</p>
<p>        case in1Minute:</p>
<p>        case in5Minute:</p>
<p>        case in15Minute:</p>
<p>        case inHourly:</p>
<p>            for ( b = 1;b &lt; BarCount - 1;b++ )<br />
            {<br />
                // START OF intraday</p>
<p>                for ( i = 0 ;i =	tn[b] )  AND ( VarGet( &#8220;EntryTime&#8221; + i ) &lt; tn[b+1]	)  )<br />
                    {</p>
<p>                        entryPrices[b] = VarGet( &#8220;EntryPrice&#8221; + i );<br />
                        Buy[b] = Short[b] = True;<br />
                        _TRACE( &#8220;ABTest: test 182 matching price entry &#8221; + NumToStr( VarGet( &#8220;EntryPrice&#8221; + i ) ) ) ;</p>
<p>                        PlotText(  StaticVarGetText( &#8220;ShortOrLong&#8221; ) + &#8221; entry&#8221; + i + &#8221; &#8221; + &#8220;:&#8221; + entryPrices[b]   , b, High[b] + range[b], colorBlue );<br />
                        // PlotText( &#8220;entry&#8221; + VarGet( &#8220;EntryPrice&#8221; + i )  , b, EntryPrice0, colorBlue );</p>
<p>                        //  //( &#8220;ABTest: test 182 MATCHED &#8221; + NumToStr( VarGet( &#8220;EntryDate&#8221; + i ) ) + NumToStr( dn[b] ) );</p>
<p>                    }</p>
<p>                    for ( j = 0 ;j =	dn[b-1] )  AND (VarGet( &#8220;EntryDate&#8221; + i )=	tn[b] )  AND ( VarGet( &#8220;ExitTime&#8221; + j ) &lt; tn[b+1]	)  )</p>
<p>                        {</p>
<p>                            exitPrices[b] = VarGet( &#8220;ExitPrice&#8221; + j );<br />
                            Sell[b] = Cover[b] = True;</p>
<p>                            PlotText(  StaticVarGetText( &#8220;ShortOrLong&#8221; ) + &#8221; Exit&#8221;  +  j  + &#8220;:&#8221; + VarGet( &#8220;ExitPrice&#8221; + j )  , b, Low[b] - range[b], colorRed );<br />
                            //  _TRACE( &#8220;ABTest: test 182 MATCHED &#8221; + NumToStr( VarGet( &#8220;ExitPrice&#8221; + j ) ) + NumToStr( dn[b] )  + NumToStr( VarGet( &#8220;ExitDate&#8221;  + j )));</p>
<p>                        }</p>
<p>                    }</p>
<p>                }</p>
<p>            } // end of intraday</p>
<p>            break;</p>
<p>            //_TRACE(&#8221;ABTest: test 182 &#8221; +&#8221;getting to break&#8221;);</p>
<p>    }// end of switch.</p>
<p>    PlotShapes( IIf( Buy OR Short, shapeSmallCircle, shapeNone ), colorBrightGreen, 0, EntryPrices, 0 );</p>
<p>    PlotShapes( IIf( Sell OR Cover, shapeSmallCircle, shapeNone ), colorRed, 0 , ExitPrices, 0 );</p>
<p>    Miny = Status( &#8220;axisminy&#8221; );</p>
<p>    Maxy = Status( &#8220;axismaxy&#8221; );</p>
<p>    pxheight = Status( &#8220;pxheight&#8221; );</p>
<p>    y = ( GetCursorYPosition() - Miny ) / ( Maxy - Miny );</p>
<p>    y = ( 1 - y ) * pxheight;</p>
<p>    y = y - 20;</p>
<p>    x = 10;</p>
<p>    GfxSelectPen( colorRed, 1 );</p>
<p>    GfxSelectSolidBrush( colorCustom1 );</p>
<p>//GfxRectangle( 2, y-100, 270, y ) ;</p>
<p>    GfxSelectFont( &#8220;Tahoma&#8221;, 8, 700 );</p>
<p>    GfxSetBkMode( 1 );</p>
<p>    GfxSetTextColor( colorGreen );</p>
<p>    GfxTextOut( Name()   + &#8221; Tradeid=  &#8221; + StaticVarGetText( &#8220;Tradeid&#8221;  )   , x, y ) ;</p>
<p>    GfxTextOut( &#8221; Strategy=  &#8221; + StaticVarGetText( &#8220;TradeStrategy&#8221;  )   , x, y + 10 ) ;</p>
<p>    GfxTextOut( &#8221; Comments=  &#8221; + StaticVarGetText( &#8220;TradeComments&#8221;  )   , x, y + 20 ) ;</p>
<p>} // // if the symbol matches what i am looking for</p>
<p></CODE></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2009/02/21/plotting-trades-on-chart/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Date and Time to Number Conversions</title>
		<link>http://www.amibroker.org/userkb/2009/02/20/date-and-time-to-number-conversions/</link>
		<comments>http://www.amibroker.org/userkb/2009/02/20/date-and-time-to-number-conversions/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 23:13:30 +0000</pubDate>
		<dc:creator>Herman</dc:creator>
		
		<category><![CDATA[AFL - Utilities and Functions]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/?p=1843</guid>
		<description><![CDATA[Code developed and kindly donated by Murthy Suresh.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function Date_To_Num&#40; aaaammdd &#41;
&#123;
    dd_ = StrToNum&#40; StrRight&#40; aaaammdd, 2 &#41; &#41;;	//printf(WriteVal(dd_) + &#34; &#34;  );
    mm_ = StrToNum&#40; StrMid&#40; aaaammdd, 4, 2 &#41; &#41;;	//printf(WriteVal(mm_) + &#34; &#34;  );
    aa_ = StrToNum&#40; StrLeft&#40; aaaammdd, 4 &#41; &#41;;	//printf(WriteVal(aa_) [...]]]></description>
			<content:encoded><![CDATA[<p>Code developed and kindly donated by Murthy Suresh.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="afl"><span style="color: #7f0000; ">function</span> Date_To_Num<span style="color: #003f00;">&#40;</span> aaaammdd <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    dd_ = StrToNum<span style="color: #003f00;">&#40;</span> StrRight<span style="color: #003f00;">&#40;</span> aaaammdd, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>;	<span style="color: #007f00; ">//printf(WriteVal(dd_) + &quot; &quot;  );</span>
    mm_ = StrToNum<span style="color: #003f00;">&#40;</span> StrMid<span style="color: #003f00;">&#40;</span> aaaammdd, <span style="color: #7f0000;">4</span>, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>;	<span style="color: #007f00; ">//printf(WriteVal(mm_) + &quot; &quot;  );</span>
    aa_ = StrToNum<span style="color: #003f00;">&#40;</span> StrLeft<span style="color: #003f00;">&#40;</span> aaaammdd, <span style="color: #7f0000;">4</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>;	<span style="color: #007f00; ">//printf(WriteVal(aa_) + &quot; &quot; + &quot;\n&quot; );</span>
    Date_Num = <span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">10000</span> * <span style="color: #003f00;">&#40;</span> aa_ - <span style="color: #7f0000;">1900</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span> + <span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">100</span> * mm_ <span style="color: #003f00;">&#41;</span> + dd_;
    RESULT = Date_Num;
    <span style="color: #7f0000; ">return</span> RESULT;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> Time_To_Num<span style="color: #003f00;">&#40;</span> strTime <span style="color: #003f00;">&#41;</span> <span style="color: #007f00; ">// format for time is hh:mm:ss</span>
<span style="color: #003f00;">&#123;</span>
    <span style="color: #007f00; font-style: italic;">/*
    //do something to raise alert  if length does not match
    ????PopupWindow(&quot;Current time is: &quot; + Now(),&quot;Alert&quot;, 2,
    640*mtRandom(), 480*mtRandom());
    */</span>
    hh_t = StrToNum<span style="color: #003f00;">&#40;</span> StrLeft<span style="color: #003f00;">&#40;</span> strTime, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>;	<span style="color: #007f00; ">//printf(WriteVal( hh_t ) + &quot; &quot;  );</span>
    mm_t = StrToNum<span style="color: #003f00;">&#40;</span> StrMid<span style="color: #003f00;">&#40;</span> strTime, <span style="color: #7f0000;">3</span>, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>;	<span style="color: #007f00; ">//printf(WriteVal( mm_t ) + &quot; &quot;  );</span>
    ss_t = StrToNum<span style="color: #003f00;">&#40;</span> StrRight<span style="color: #003f00;">&#40;</span> strTime, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>;	<span style="color: #007f00; ">//printf(WriteVal( ss_t ) + &quot; &quot;  + &quot;\n&quot;  );</span>
    Time_Num = <span style="color: #7f0000;">10000</span> * hh_t + <span style="color: #7f0000;">100</span> * mm_t + ss_t;
    RESULT = Time_Num;
    <span style="color: #7f0000; ">return</span> RESULT;
<span style="color: #003f00;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2009/02/20/date-and-time-to-number-conversions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Popup Window: Preventing pile-ups</title>
		<link>http://www.amibroker.org/userkb/2008/08/30/popup-window-preventing-pile-ups/</link>
		<comments>http://www.amibroker.org/userkb/2008/08/30/popup-window-preventing-pile-ups/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 13:03:50 +0000</pubDate>
		<dc:creator>Herman</dc:creator>
		
		<category><![CDATA[AFL - Utilities and Functions]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/?p=1842</guid>
		<description><![CDATA[By Dennis Brown
The popup window is a great tool in debugging and can help you to keep track of what your code is doing or it can be used to alert you to special situations in your normally running formula. A common problem is that if you call PopupWindow() from a loop or if one [...]]]></description>
			<content:encoded><![CDATA[<p>By Dennis Brown</p>
<p>The popup window is a great tool in debugging and can help you to keep track of what your code is doing or it can be used to alert you to special situations in your normally running formula. A common problem is that if you call PopupWindow() from a loop or if one gets generated on every AFL pass, you can get hundreds or even thousands of pop-ups piling up on your screen.  Tomasz posted a simple work-around on the AmiBroker Feedback Center that took care of the problem in some cases (<a href="http://www.amibroker.com/feedback/view_bug.php?bug_id=1528">Suggestion 1528</a>):</p>
<p>The following is a more complete version of this solution that adds a popupID to keep track of each individual popup window and re-enable the popup after its specified timeout period, or if any of the displayed text changes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="afl"><span style="color: #7f0000; ">function</span> GetSecondNum<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    Time = Now<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">4</span> <span style="color: #003f00;">&#41;</span>;
    Seconds = int<span style="color: #003f00;">&#40;</span> Time % <span style="color: #7f0000;">100</span> <span style="color: #003f00;">&#41;</span>;
    Minutes = int<span style="color: #003f00;">&#40;</span> Time / <span style="color: #7f0000;">100</span> % <span style="color: #7f0000;">100</span> <span style="color: #003f00;">&#41;</span>;
    Hours = int<span style="color: #003f00;">&#40;</span> Time / <span style="color: #7f0000;">10000</span> % <span style="color: #7f0000;">100</span> <span style="color: #003f00;">&#41;</span>;
    SecondNum = int<span style="color: #003f00;">&#40;</span> Hours * <span style="color: #7f0000;">60</span> * <span style="color: #7f0000;">60</span> + Minutes * <span style="color: #7f0000;">60</span> + Seconds <span style="color: #003f00;">&#41;</span>;
    <span style="color: #7f0000; ">return</span> SecondNum;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> PopupWindowEx<span style="color: #003f00;">&#40;</span> popupID, bodytext, captiontext, timeout, left, top <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    displayText = bodytext + captiontext;
    <span style="color: #7f0000; ">if</span> <span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#40;</span> StaticVarGetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;prevPopup&quot;</span> + popupID <span style="color: #003f00;">&#41;</span> != displayText<span style="color: #003f00;">&#41;</span> OR <span style="color: #003f00;">&#40;</span> StaticVarGet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;prevPopupTime&quot;</span> + popupID <span style="color: #003f00;">&#41;</span> &lt; GetSecondNum<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span> <span style="color: #003f00;">&#41;</span>
    <span style="color: #003f00;">&#123;</span>
        StaticVarSetText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;prevPopup&quot;</span> + popupID, displayText<span style="color: #003f00;">&#41;</span>;
        StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;prevPopupTime&quot;</span> + popupID, GetSecondNum<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span> + timeout <span style="color: #003f00;">&#41;</span>;
        PopupWindow<span style="color: #003f00;">&#40;</span> bodytext, Captiontext + popupID, timeout, Left, top <span style="color: #003f00;">&#41;</span>;
    <span style="color: #003f00;">&#125;</span>
<span style="color: #003f00;">&#125;</span>
&nbsp;
PopupWindowEx<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ID:1&quot;</span>, <span style="color: #7f007f;">&quot;testing&quot;</span>, <span style="color: #7f007f;">&quot;test alert &quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">-1</span>, <span style="color: #7f0000;">-1</span> <span style="color: #003f00;">&#41;</span>;
PopupWindowEx<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ID:2&quot;</span>, <span style="color: #7f007f;">&quot;testing&quot;</span>, <span style="color: #7f007f;">&quot;test alert &quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">0</span> <span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/08/30/popup-window-preventing-pile-ups/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wordpress upgrade</title>
		<link>http://www.amibroker.org/userkb/2008/04/15/wordpress-upgrade/</link>
		<comments>http://www.amibroker.org/userkb/2008/04/15/wordpress-upgrade/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 10:56:18 +0000</pubDate>
		<dc:creator>Tomasz Janeczko</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/?p=1774</guid>
		<description><![CDATA[Due to vulnerability found in previous version of Wordpress (2.2) and attack attempts this site experienced and the compatibility issues with Windows Live Writer that surfaced after quick security fix was applied, I was forced to perform upgrade to newest version of Wordpress.
This results in old Table-of-content plugin not working anymore and the need for [...]]]></description>
			<content:encoded><![CDATA[<p>Due to vulnerability found in previous version of Wordpress (2.2) and attack attempts this site experienced and the compatibility issues with Windows Live Writer that surfaced after quick security fix was applied, I was forced to perform upgrade to newest version of Wordpress.<br />
This results in old Table-of-content plugin not working anymore and the need for rewrite. The new version produces ill-formatted output. Please be patient when TOC plugin is under rewrite.</p>
<p>Also note that although read experience does not change (the site looks identical from reader perspective), the author control panel has changed and looks different. It requires some time to adjust to new design, but after a while I think it is better. I am sorry about this mess but it was not caused by me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/04/15/wordpress-upgrade/feed/</wfw:commentRss>
		</item>
		<item>
		<title>US-Stocks Database (v2)</title>
		<link>http://www.amibroker.org/userkb/2008/03/27/us-stocks-database/</link>
		<comments>http://www.amibroker.org/userkb/2008/03/27/us-stocks-database/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 22:03:03 +0000</pubDate>
		<dc:creator>brian_z</dc:creator>
		
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/2007/11/10/us-stocks-database/</guid>
		<description><![CDATA[Jim, who is a long term AmiBroker user, regularly provides an updated template that automatically sets up a database of all US stocks available from Yahoo!Finance.
The stocks are initially categorized by Market and then as Stocks, Indexes or Funds at the Group level. They are also organized into Sectors, using the Hemscott classification system.
A link [...]]]></description>
			<content:encoded><![CDATA[<p>Jim, who is a long term <em>AmiBroker</em> user, regularly provides an updated template that automatically sets up a database of all US stocks available from <em>Yahoo!Finance</em>.</p>
<p>The stocks are initially categorized by <em>Market</em> and then as <em>Stocks, Indexes</em> or <em>Funds</em> at the <em>Group</em> level. They are also organized into <em>Sectors</em>, using the <em>Hemscott </em>classification system.</p>
<p>A link to the latest message from Jim is available at AmiBrokerYahooGroup message # 119057 - &quot;AmiBroker/Yahoo Database File&quot;:&#160; <a title="http://finance.groups.yahoo.com/group/amibroker/message/119057" href="http://finance.groups.yahoo.com/group/amibroker/message/119057">http://finance.groups.yahoo.com/group/amibroker/message/119057</a></p>
<p>Or link directly to the site to obtain the download:</p>
<p><a href="http://www.icc-az.com">http://www.icc-az.com</a></p>
<p>Go to Links &gt;&gt; AmiBroker at that site (instructions are available at the download page).</p>
<p>After the database is setup, use AmiQuote to download data from the <em>Yahoo Historical</em> server (allow approximately 1/2 - 1 hour download time, using a mid speed broadband connection, per year of history).</p>
<p>The length of back history available varies with each symbol (the author has downloaded up to 10 years history using this template).</p>
<p>Typically the ticker list, as setup, will contain a couple of hundred redundant symbols (symbols that return an error message when attempting to download historical data for them). Most of the redundant symbols are .OB (over the counter stock) and are not relevant to the majority of traders. Users can elect to delete them from the database or go to the Yahoo site, or other sites, to find the cause of the &#8216;download error&#8217; e.g. the stock may have been de-listed or undergone a name change .</p>
<p>Instructions on how to find and delete the redundant (NoQuotes) symbols can be found in the UKB post &gt;&gt; <a href="http://www.amibroker.org/userkb/2007/11/09/setup-a-custom-database-nasdaq/">Setup A Custom Database - Nasdaq</a></p>
<p>Information, or discussion, on the pros and cons of using <em>Yahoo</em> data is included in articles in the <em>Yahoo</em> sub-category at the <em>Users&#8217; Knowledge Base:</em></p>
<p><a title="http://www.amibroker.org/userkb/?cat=99" href="http://www.amibroker.org/userkb/?cat=99">http://www.amibroker.org/userkb/?cat=99</a></p>
<p>Further information, about using the US-Stocks database, can be obtained by searching the <em>AmiBrokerYahooGroup</em> message board (use an <em>Advanced Search</em> and enter S<em>ubject contains &quot;US-Stocks&quot;</em> OR &quot;<em>AmiBroker/Yahoo Database</em>&quot; as the search criteria . </p>
<p>&#160;</p>
<p><sub>Version 2 - Feb 02/2008 - by Brian_z - written using Windows Live Writer - updated links to current message and new download site</sub></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/03/27/us-stocks-database/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASCII Import - Standard and Poor&#8217;s Global 1200</title>
		<link>http://www.amibroker.org/userkb/2008/03/25/ascii-import-standard-and-poors-global-1200/</link>
		<comments>http://www.amibroker.org/userkb/2008/03/25/ascii-import-standard-and-poors-global-1200/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 09:44:08 +0000</pubDate>
		<dc:creator>brian_z</dc:creator>
		
		<category><![CDATA[Database Management]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/2008/03/25/ascii-import-standard-and-poors-global-1200/</guid>
		<description><![CDATA[Objective&#160;
The objective, for this post, is to outline a basic method for setting up a custom database, using ASCII importation to install the categorized structure.
A Global 1200 database, suitable for use with Yahoo data, is used as the example.
Note: it is an outline only and the procedure is not taken to completion i.e. it is [...]]]></description>
			<content:encoded><![CDATA[<p><strong><u>Objective</u></strong>&#160;</p>
<p>The objective, for this post, is to outline a basic method for setting up a custom database, using ASCII importation to install the categorized structure.</p>
<p>A Global 1200 database, suitable for use with <em>Yahoo</em> data, is used as the example.</p>
<p>Note: it is an outline only and the procedure is not taken to completion i.e. it is not set-up as a working database (interested readers can complete that task for themselves).</p>
<p>&#160;<u><strong>Pre-Requisites</strong></u></p>
<p>It is assumed that readers are familiar with earlier posts in the <em>UKB &gt;&gt; Database Management</em> series (the basic skills introduced there are not recapped in this post) and also the <em>ASCII Importer Reference</em> (from the <em>Users Guide</em>).</p>
<p><a title="http://www.amibroker.com/guide/d_ascii.html" href="http://www.amibroker.com/guide/d_ascii.html">http://www.amibroker.com/guide/d_ascii.html</a></p>
<p>&#160;<strong><u>Introduction</u></strong></p>
<blockquote><p>&quot;American Standard Code for Information Interchange (ASCII)<strong> </strong>allows digital devices to communicate with each other and to process, store, and communicate character-oriented information&quot; <sup>1</sup>.</p>
</blockquote>
<p>It is the format used to import data into <em>AmiBroker</em>, via <em>AmiQuote</em>, or manually, via the <em>ASCII Import</em> function.</p>
<p>In this example, a list of the <em>Global 1200</em> constituents, including <em>Market</em> and <em>Sector</em> categorization, is downloaded from the <em>Standard and Poors</em> (US) site and pre-conditioned into an ASCII compliant format, before importing it into <em>AmiBroker</em>.</p>
<p>Note: the example is a basic one, but, users can easily extend the method to more complex databases.</p>
<p><strong><u>Preparation</u></strong></p>
<p><strong><u></u></strong></p>
<p><strong><u>Step1</u></strong></p>
<p>A constituent list, in Comma Separated Value (CSV) format, can be downloaded from the <em>Standard and Poors Homesite</em> (US):</p>
<p><a title="http://www2.standardandpoors.com/portal/site/sp/en/us/page.home/home/0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0.html" href="http://www2.standardandpoors.com/portal/site/sp/en/us/page.home/home/0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0.html">http://www2.standardandpoors.com/portal/site/sp/en/us/page.home/home/0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0.html</a></p>
<p>Go to <strong>Indices &gt;&gt;&#160; + Equity Indices &gt;&gt; S and P Global Indices &gt;&gt; S and P Global 1200</strong></p>
<p>OR follow the link below to go directly to the page:</p>
<p><a title="http://www2.standardandpoors.com/portal/site/sp/en/us/page.topic/indices_gbl1200/2,3,2,1,0,0,0,0,0,0,3,0,0,0,0,0.html" href="http://www2.standardandpoors.com/portal/site/sp/en/us/page.topic/indices_gbl1200/2,3,2,1,0,0,0,0,0,0,3,0,0,0,0,0.html">http://www2.standardandpoors.com/portal/site/sp/en/us/page.topic/indices_gbl1200/2,3,2,1,0,0,0,0,0,0,3,0,0,0,0,0.html</a></p>
<p>&#160;</p>
<p><strong><u>Step 2</u></strong></p>
<p>Click on <strong>Download Table, </strong>at the top of the page, to save a local copy of the <em>Constituent List</em> (save it in a spreadsheet compliant format)</p>
<p><a href="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc001.png"><img height="523" alt="ASC001" src="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc001-thumb.png" width="595" border="0" /></a></p>
<p>Note: not all of the Countries, with stocks in the <em>Global 1200</em>, are supported by <em>Yahoo!Finance</em> (refer to the following link for a list of <em>Yahoo&#8217;s</em> international exchanges&#160; - <a title="http://finance.yahoo.com/exchanges" href="http://finance.yahoo.com/exchanges">http://finance.yahoo.com/exchanges</a>)</p>
<p>&#160;</p>
<p><strong><u>Step 3</u></strong></p>
<p>Prepare the file for ASCII Import, using the spreadsheet functions:</p>
<p>a) Trim excess &#8216;whitespace&#8217; from the symbols, manually enter <em>Yahoo</em> exchange suffixes and append them to the symbols, sort by <strong>Market</strong> (Country) and manually add a column for the <strong>Market ID</strong> (0-23).</p>
<p>b) Delete symbols that are from unsupported exchanges, sort by <strong>Sector</strong> and manually add a column for the <strong>Sector ID&#8217;s</strong> (0-9).</p>
<p>c) Copy the <strong>Fullname</strong>, <strong>Ticker</strong>, <strong>Market ID</strong> and <strong>Sector ID</strong> columns to a separate <strong>Global1200.CSV</strong> file, ready for importing.</p>
<p>Note: Refer to the attached files <strong>24-March-2008_GBL1200.xls</strong> and <strong>Global1200.xls </strong>(the Global1200 file is attached in .xls format as the UKB does not permit uploading of .csv files).</p>
<p>&#160;</p>
<p><strong><u>Step 4</u></strong></p>
<p>Prepare a <strong>broker.industries</strong> and <strong>broker.sector file</strong>, using the template in the <strong>24-March-2008_GBL1200.xls</strong> file, and save them in the root of the <strong>Programs/AmiBroker</strong><em> </em>directory (overwrite the existing broker.industries and broker.sector files).</p>
<p>&#160;</p>
<p><strong><u>Step 5</u></strong></p>
<p>Prepare an ASCII formats file and save it in the <strong>Programs/AmiBroker/Formats</strong> folder.</p>
<p>The file, for this example, needs to be in the following format (the file can be written in a plain text editor, like <em>NotePad</em>, and saved as <strong>Global1200.format</strong>):</p>
<p><a href="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc002.png"><img height="445" alt="ASC002" src="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc002-thumb.png" width="736" border="0" /></a></p>
<p>Note: The file name will be automatically added to the <em>import.types</em> list, which is also in the <em>Programs/AmiBroker/Formats</em> folder.</p>
<p>&#160;</p>
<p><strong><u>Step 6</u></strong></p>
<p>Create a new EOD database, called <strong>Data_Global1200</strong></p>
<p>Go to <strong>File &gt;&gt; Import ASCII</strong> and elect to <strong>Open</strong> the <strong>Global1200.csv</strong> file as file type <strong>Global1200(*.*)</strong></p>
<p>Note: the <em>import.types</em> (formats file) list will be the default <em>Files of type</em> list in the file browser window that opens.</p>
<p><a href="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc003.png"><img height="478" alt="ASC003" src="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc003-thumb.png" width="563" border="0" /></a></p>
<p>The symbol list and database structure, as defined in the Global1200.csv file, will now be set-up in the current database.</p>
<p>Note: the Markets and Groups categories will remain as the default settings (they can only be renamed manually via <strong>Symbol &gt;&gt; Categories).</strong></p>
<p><a href="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc005.png"><img height="369" alt="ASC005" src="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/asc005-thumb.png" width="485" border="0" /></a></p>
<p><strong><u>Step 7</u></strong></p>
<p>Data can now be downloaded, for the database, from the Yahoo historical server.</p>
<p>On downloading some symbols will return a 404 error.</p>
<p>In some cases the errors can be repaired by &#8216;researching&#8217; via the Yahoo sites e.g. Hong Kong stocks use four digits and require leading zeros, which are not included in the symbols used by Standard and Poors.</p>
<p>In other cases there are multiple exchanges, supported by Yahoo, for a given country, so the ticker may need an alternative suffix (for this example the author assumed all tickers included in the Global 1200 were listed on the constituent countries major exchange).</p>
<p>&#160;</p>
<p>ATTACHED FILES:</p>
<p><a title="24-mar-2008_gbl1200.xls" href="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/24-mar-2008_gbl1200.xls">24-mar-2008_gbl1200.xls</a>     <br /><a title="global1200.xls" href="http://www.amibroker.org/userkb/wp-content/uploads/2008/03/global1200.xls">global1200.xls</a></p>
<p><em><sub>Browse the spreadsheet files on line, or, right click and select </sub><sub>Save As </sub><sub>to download them as an editable version.</sub></em></p>
<p>REFERENCES:</p>
<p>1 - <a title="http://en.wikipedia.org/wiki/ASCII" href="http://en.wikipedia.org/wiki/ASCII">http://en.wikipedia.org/wiki/ASCII</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/03/25/ascii-import-standard-and-poors-global-1200/feed/</wfw:commentRss>
		</item>
		<item>
		<title>AmiBroker Supported Sites</title>
		<link>http://www.amibroker.org/userkb/2008/03/23/amibroker-supported-sites/</link>
		<comments>http://www.amibroker.org/userkb/2008/03/23/amibroker-supported-sites/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 06:44:40 +0000</pubDate>
		<dc:creator>brian_z</dc:creator>
		
		<category><![CDATA[Blogroll]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/2008/03/23/amibroker-supported-sites/</guid>
		<description><![CDATA[&#160;
This post contains a list of AmiBroker &#8217;supported&#8217; sites (most of the sites are officially supported by AmiBroker but some are not).
Search the main sites by using Google&#8217;s &#34;Advanced Search&#34; feature at http://www.google.com (search within a site, or domain, by using the URL address).

AmiBroker&#8217;s Homesite - http://www.amibroker.com/ 
AmiBrokers third party site - http://www.amibroker.org 

Alternatively visit [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>This post contains a list of <em>AmiBroker</em> &#8217;supported&#8217; sites (most of the sites are officially supported by <em>AmiBroker</em> but some are not).</p>
<p>Search the main sites by using <em>Google&#8217;s</em> &quot;<em>Advanced Search&quot;</em> feature at <a title="http://www.google.com" href="http://www.google.com">http://www.google.com</a> (search within a site, or domain, by using the URL address).</p>
<ul>
<li><em>AmiBroker&#8217;s</em> Homesite - <a title="http://www.amibroker.com/" href="http://www.amibroker.com/">http://www.amibroker.com/</a> </li>
<li><em>AmiBrokers</em> third party site - <a href="http://www.amibroker.org">http://www.amibroker.org</a> </li>
</ul>
<p>Alternatively visit any of the &#8217;supported&#8217; sites for categorized information on <em>AmiBroker</em> features, purchase, installation, testimonials, news, FAQ&#8217;s, downloads, documents, knowledge bases, tips, code and mailing lists.</p>
<p>For personal support please email - support [at] AmiBroker.com</p>
<p><strong>1) <u>AmiBroker&#8217;s Homesite</u></strong></p>
<p><strong><u></u></strong></p>
<p>This site is searchable using the &quot;<em>Search</em>&quot; box in the top left corner of the <strong>&quot;</strong><em>Welcome</em><strong>&quot;</strong> page.</p>
<ul>
<li>Welcome - <a title="http://www.amibroker.com/index.html" href="http://www.amibroker.com/index.html">http://www.amibroker.com/index.html</a> </li>
<li>Features - <a title="http://www.amibroker.com/features.html" href="http://www.amibroker.com/features.html">http://www.amibroker.com/features.html</a> </li>
<li>News - <a title="http://www.amibroker.com/news.html" href="http://www.amibroker.com/news.html">http://www.amibroker.com/news.html</a> </li>
<li>Download - <a title="http://www.amibroker.com/download.html" href="http://www.amibroker.com/download.html">http://www.amibroker.com/download.html</a> </li>
<li>Order - <a title="http://www.amibroker.com/order.php" href="http://www.amibroker.com/order.php">http://www.amibroker.com/order.php</a> </li>
<li>Support - <a title="http://www.amibroker.com/support.html" href="http://www.amibroker.com/support.html">http://www.amibroker.com/support.html</a> </li>
<li>FAQ - <a title="http://www.amibroker.com/faq.html" href="http://www.amibroker.com/faq.html">http://www.amibroker.com/faq.html</a> </li>
<li>Wishlist - <a title="http://www.amibroker.com/todo.html" href="http://www.amibroker.com/todo.html">http://www.amibroker.com/todo.html</a> </li>
<li>Links - <a title="http://www.amibroker.com/links.html" href="http://www.amibroker.com/links.html">http://www.amibroker.com/links.html</a> </li>
</ul>
<p>&#160;</p>
<p><strong><u>Links to specific pages at the AmiBroker Homesite</u></strong></p>
<p><strong></strong></p>
<p><strong>a) A downloadable PDF version of the <em>Users&#8217; Guide</em> (Help Manual).</strong></p>
<p>Note: the PDF version has superior search features compared to the other available versions.</p>
<p><a title="http://www.amibroker.com/" href="http://www.amibroker.com/bin/UsersGuide.pdf">http://www.amibroker.com/bin/UsersGuide.pdf</a></p>
<p><strong>b) An online version of the <em>Users&#8217; Guide</em> (Help Manual).</strong></p>
<p><a title="http://www.amibroker.com/guide/" href="http://www.amibroker.com/guide/">http://www.amibroker.com/guide/</a></p>
<p><strong>c) FAQ&#8217;s.</strong></p>
<p><a title="http://www.amibroker.com/faq.html" href="http://www.amibroker.com/faq.html">http://www.amibroker.com/faq.html</a></p>
<p><strong>d) AmiBroker Knowledge Base (KB).</strong></p>
<p>The &#8216;official&#8217; Knowledge Base site with tips &amp; usage hints from AmiBroker.com</p>
<p><a title="http://www.amibroker.com/kb/" href="http://www.amibroker.com/kb/">http://www.amibroker.com/kb/</a></p>
<p><strong>e) AmiBroker Tips Newsletter.</strong></p>
<p><a title="http://www.amibroker.com/newsletter/" href="http://www.amibroker.com/newsletter/">http://www.amibroker.com/newsletter/</a></p>
<p>NOTE: The Newsletter has been now replaced by the <em>AmiBroker Knowledge Base</em> at:<b>&#160;<a href="http://www.amibroker.com/kb/">http://www.amibroker.com/kb/</a></b></p>
<p><strong>f) AmiBroker support page.</strong></p>
<p>The support page features additional documentation and videos.</p>
<p><strong><a title="http://www.amibroker.com/support.html" href="http://www.amibroker.com/support.html">http://www.amibroker.com/support.html</a></strong></p>
<p><strong>g) AFL Library.</strong></p>
<p>The AFL on-line library provides a very convenient way to share formulas, including descriptions and comments, between AmiBroker users. You will not only&#160; be able to get the formula you need here but also contribute your own ideas.</p>
<p><a title="http://www.amibroker.com/library/" href="http://www.amibroker.com/library/">http://www.amibroker.com/library/</a></p>
<p><strong>h) Members Area.</strong></p>
<p>This provides additional material for registered <em>AmiBroker</em> users, including the newest issues of <em>Stocks &amp; Commodities Traders</em> tips for <em>AmiBroker</em> </p>
<p><a title="http://www.amibroker.com/login.html" href="http://www.amibroker.com/login.html">http://www.amibroker.com/login.html</a></p>
<p><strong>i) The online version of the <em>AFL Function Reference</em> (searchable).</strong></p>
<p><a title="http://www.amibroker.com/guide/afl/" href="http://www.amibroker.com/guide/afl/">http://www.amibroker.com/guide/afl/</a></p>
<p><strong>j) AmiBroker Development Log.</strong></p>
<p><a title="http://www.amibroker.com/devlog/" href="http://www.amibroker.com/devlog/">http://www.amibroker.com/devlog/</a></p>
<p><strong>k) Feedback Centre.</strong></p>
<p>You can submit your ideas and suggestions and see the list of features planned for the next few releases (registered users only).</p>
<p><a title="http://www.amibroker.com/todo.html" href="http://www.amibroker.com/todo.html">http://www.amibroker.com/todo.html</a></p>
<p>&#160;</p>
<p><strong>2) <u>AmiBroker User&#8217;s Knowledge Base (UKB)</u></strong></p>
<p><strong><u></u></strong></p>
<p>This site is owned and operated by <em>AmiBroker</em> but its contents are entirely contributed by users.</p>
<p>It was was created to save you time, raise your productivity, aid you in your <em>Amibroker Formula Language</em> (AFL) learning experience, and help you become a more successful trader.</p>
<p><a title="http://www.amibroker.org/userkb/" href="http://www.amibroker.org/userkb/">http://www.amibroker.org/userkb/</a></p>
<p>UKB features:</p>
<p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="#0080ff"></font></em><font color="#0080ff"><a href="http://www.amibroker.org/userkb/?cat=135">Automated Trading, by Herman van den Bergen</a></font></p>
<p><font color="#0080ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </font><a href="http://www.amibroker.org/userkb/?cat=115">Intelligent Optimization, by Fred Tonetti.</a></p>
<p>&#160;</p>
<p><strong>3) <u>AmiBroker third party site</u></strong></p>
<p>An unstructured FTP site, sponsored by AmiBroker.com, to facilitate&#160; file sharing between Amibroker users.</p>
<p><a title="http://www.amibroker.org/3rdparty/" href="http://www.amibroker.org/3rdparty/">http://www.amibroker.org/3rdparty/</a></p>
<p>&#160;</p>
<p><strong>4) <u>The AmiBroker mailing list</u></strong></p>
<p><strong><u></u></strong></p>
<p>The list is provided to help <em>Amibroker</em> users to share ideas, tips and other related information. This is the place where you can meet other <em>AmiBroker</em> users, ask questions and share ideas (searchable archive and file uploading).</p>
<p><a title="http://finance.groups.yahoo.com/group/amibroker/" href="http://finance.groups.yahoo.com/group/amibroker/">http://finance.groups.yahoo.com/group/amibroker/</a></p>
<p>&#160;</p>
<p><strong>5) <u>The AmiBroker Trading Systems mailing list.</u></strong></p>
<p><strong><u></u></strong></p>
<p>This group is for discussion on developing and testing trading systems, using <em>AmiBroker</em> (searchable archive and file uploading).</p>
<p><a title="http://finance.groups.yahoo.com/group/amibroker-ts/" href="http://finance.groups.yahoo.com/group/amibroker-ts/">http://finance.groups.yahoo.com/group/amibroker-ts/</a></p>
<p>&#160;</p>
<p><strong>6)</strong> <u><strong>The AmiBroker Automated Trading mailing list.</strong></u></p>
<p><strong><u></u></strong></p>
<p>This group is for discussion on Automated Trading, using <em>AmiBroker</em> (searchable archive and file uploading).</p>
<p><a title="http://finance.groups.yahoo.com/group/AmiBroker-at/" href="http://finance.groups.yahoo.com/group/AmiBroker-at/">http://finance.groups.yahoo.com/group/AmiBroker-at/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/03/23/amibroker-supported-sites/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using a GFX Include file</title>
		<link>http://www.amibroker.org/userkb/2008/03/21/using-a-gfx-include-file/</link>
		<comments>http://www.amibroker.org/userkb/2008/03/21/using-a-gfx-include-file/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 13:07:03 +0000</pubDate>
		<dc:creator>Herman</dc:creator>
		
		<category><![CDATA[GFX Programming]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/2008/03/21/using-a-gfx-include-file/</guid>
		<description><![CDATA[Important note: The AmiBroker 5.09.0 Beta introduced the following new GFX functions:
Status(&#8221;pxchartleft&#8221;) - returns x-coordinate of top-left corner of chart area
Status(&#8221;pxcharttop&#8221;) - returns y-coordinate of top-left corner of chart area
Status(&#8221;pxchartright&#8221;) - returns x-coordinate of bottom-right corner of chart area
Status(&#8221;pxchartbottom&#8221;) - returns y-coordinate of bottom-right corner of chart area
Status(&#8221;pxchartwidth&#8221;) - returns width chart area (right-left)
Status(&#8221;pxchartheight&#8221;) - [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Important note</strong>: The <a href="http://www.amibroker.com/members/bin/ab5090beta.exe">AmiBroker 5.09.0 Beta</a> introduced the following new GFX functions:</p>
<p>Status(&#8221;pxchartleft&#8221;) - returns x-coordinate of top-left corner of chart area<br />
Status(&#8221;pxcharttop&#8221;) - returns y-coordinate of top-left corner of chart area<br />
Status(&#8221;pxchartright&#8221;) - returns x-coordinate of bottom-right corner of chart area<br />
Status(&#8221;pxchartbottom&#8221;) - returns y-coordinate of bottom-right corner of chart area<br />
Status(&#8221;pxchartwidth&#8221;) - returns width chart area (right-left)<br />
Status(&#8221;pxchartheight&#8221;) - returns width chart area (bottom-top)</p>
<p>Since this release appeared after this post was published these functions are not used in the examples below. This post has been left unchanged for educational purposes. For examples using the new functions please see the <a href="http://www.amibroker.com/devlog/wp-content/uploads/2008/04/readme5090.html">5.09.0 Read Me</a> file.</p>
<p align="center"> =====</p>
<p>While the post <a href="http://www.amibroker.org/userkb/2008/03/20/creating-gfx-chart-overlays/">Creating GFX Chart-Overlays (v2)</a> may have clarified a few of the more important aspects of using GFX functions, it doesn’t really give you a “quick Start” template to get started. Using a GFXInclude file can remove some of the burden of having to define pixel and charting parameters. The Include file at the bottom of this post contains most definitions as well as these common functions that you may want to call from your GFX application:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="afl">GetVisualBarIndex<span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Returns array containing index for visible bars</span>
gfxPlotHLine<span style="color: #003f00;">&#40;</span> YPixels, Color <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Plots horizontal line at level YPixels</span>
gfxPlotVLine<span style="color: #003f00;">&#40;</span> XPixels, Color <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// plots vertical line at level XPixels</span>
GetYPixels<span style="color: #003f00;">&#40;</span> Y <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Convert a vertical price number to the pixel equivalent</span>
GetXPixels<span style="color: #003f00;">&#40;</span> X <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Convert a horizontal DateTime number value to the pixel equivalent</span></pre></td></tr></table></div>

<p>Of course you can, and should, add additional functions of your own. Here is an example of how to call the above functions to draw a GFX cross-hair cursor (Red in the capture):</p>
<p align="center">
<a href='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/gfxcrosshair.jpg' title='gfxcrosshair.jpg'><img src='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/gfxcrosshair.jpg' alt='gfxcrosshair.jpg' /></a></p>
<p>Here is the code that produced the above image:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="afl">GraphXSpace = <span style="color: #7f0000;">5</span>; <span style="color: #007f00; ">// See the AmiBroker help on how to init these variables</span>
GfxSetBkMode<span style="color: #003f00;">&#40;</span> bkmode = <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span>;
GfxSetOverlayMode<span style="color: #003f00;">&#40;</span> mode = <span style="color: #7f0000;">0</span> <span style="color: #003f00;">&#41;</span>;
GfxSelectPen<span style="color: #003f00;">&#40;</span> colorRed <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">Plot</span><span style="color: #003f00;">&#40;</span> C, <span style="color: #7f007f;">&quot;&quot;</span>, colorBlack, styleLine <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// To define miny and maxy</span>
<span style="color: #007f00;">#include &lt;GFXInclude-001.afl&gt; // Located in your default Include folder</span>
&nbsp;
<span style="color: #007f00; ">// Example to draw cross-hair cursor</span>
Yprice = GetCursorYPosition<span style="color: #003f00;">&#40;</span><span style="color: #7f0000;">0</span><span style="color: #003f00;">&#41;</span>;
XIndex = SelectedValue<span style="color: #003f00;">&#40;</span>GetVisualBarIndex<span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#41;</span><span style="color: #003f00;">&#41;</span>;
gfxPlotHLine<span style="color: #003f00;">&#40;</span> GetYPixels<span style="color: #003f00;">&#40;</span> YPrice <span style="color: #003f00;">&#41;</span>, colorRed <span style="color: #003f00;">&#41;</span>;
gfxPlotVLine<span style="color: #003f00;">&#40;</span> GetXPixels<span style="color: #003f00;">&#40;</span> XIndex <span style="color: #003f00;">&#41;</span>, colorRed <span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

<p>The include file listed below defines the following variables:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="afl"><span style="color: #007f00; ">// pxwidth, pxheight, Miny, MinX, YRange, VisBarIndex, NumBarsVisible, pxPaneWidth, pxPaneheight, PixelsPerBar, PixelsPerPrice</span></pre></td></tr></table></div>

<p>You may want to copy the above comment line below the #include statement in your code to refresh your memory. You should copy the Include file to your default AmiBroker Include folder.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
</pre></td><td class="code"><pre class="afl"><span style="color: #007f00; ">// GFXInclude-001.afl copy to default include folder</span>
&nbsp;
<span style="color: #7f0000; ">function</span> gfxPlotHLine<span style="color: #003f00;">&#40;</span> YPixels, Color <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    <span style="color: #7f0000;">global</span> pxwidth;
    GfxSelectPen<span style="color: #003f00;">&#40;</span> Color <span style="color: #003f00;">&#41;</span> ;
    GfxMoveTo<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">0</span>, YPixels <span style="color: #003f00;">&#41;</span>;
    GfxLineTo<span style="color: #003f00;">&#40;</span> pxwidth, YPixels <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> gfxPlotVLine<span style="color: #003f00;">&#40;</span> XPixels, Color <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    <span style="color: #7f0000;">global</span> pxheight;
    GfxSelectPen<span style="color: #003f00;">&#40;</span> Color <span style="color: #003f00;">&#41;</span> ;
    GfxMoveTo<span style="color: #003f00;">&#40;</span> XPixels, <span style="color: #7f0000;">0</span> <span style="color: #003f00;">&#41;</span>;
    GfxLineTo<span style="color: #003f00;">&#40;</span> XPixels, pxheight <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> GetVisualBarIndex<span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    lvb = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;lastvisiblebar&quot;</span> <span style="color: #003f00;">&#41;</span>;
    fvb = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;firstvisiblebar&quot;</span> <span style="color: #003f00;">&#41;</span>;
    bi = BarIndex<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span>;
    StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;NumberbarsVisible&quot;</span>, Lvb - fvb + <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;
    <span style="color: #7f0000; ">return</span> bi - bi<span style="color: #003f00;">&#91;</span> <span style="color: #7f0000;">0</span> <span style="color: #003f00;">&#93;</span> - fvb;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> GetYPixels<span style="color: #003f00;">&#40;</span> Y <span style="color: #003f00;">&#41;</span>
	<span style="color: #003f00;">&#123;</span>
	<span style="color: #7f0000;">global</span> PixelsPerPrice, pxTopArea, MaxY; 
	<span style="color: #7f0000; ">return</span> <span style="color: #003f00;">&#40;</span>MaxY - Y<span style="color: #003f00;">&#41;</span> * PixelsPerPrice + pxTopArea;
	<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> GetXPixels<span style="color: #003f00;">&#40;</span> X <span style="color: #003f00;">&#41;</span>
	<span style="color: #003f00;">&#123;</span>
	<span style="color: #7f0000;">global</span> PixelsPerBar, pxLeftArea;
	<span style="color: #7f0000; ">return</span> X * PixelsPerBar + pxLeftArea;
	<span style="color: #003f00;">&#125;</span>
&nbsp;
_SECTION_BEGIN<span style="color: #003f00;">&#40;</span><span style="color: #7f007f;">&quot;GFX INITIALIZATION&quot;</span><span style="color: #003f00;">&#41;</span>;
<span style="color: #007f00; ">// These Parameters will change depending on screen layout/fonts</span>
pxRightArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Right Axis Area&quot;</span>, <span style="color: #7f0000;">93</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">200</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Depends on font</span>
pxDateArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Date Axis Area&quot;</span>, <span style="color: #7f0000;">11</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Depends on font</span>
DateaxisOn = ParamToggle<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Date Axis&quot;</span>, <span style="color: #7f007f;">&quot;HIDE|SHOW&quot;</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
pxLeftArea = <span style="color: #7f0000;">5</span>; 
pxTopArea = <span style="color: #7f0000;">5</span>; 
pxBottomArea = <span style="color: #7f0000;">5</span>; 
<span style="color: #7f0000; ">if</span> <span style="color: #003f00;">&#40;</span> DateaxisOn <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    pxBottomArea = pxDateArea + pxBottomArea;
    SetChartOptions<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">2</span>, chartShowDates <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
<span style="color: #7f0000; ">else</span>
    SetChartOptions<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">3</span>, chartShowDates <span style="color: #003f00;">&#41;</span>;
&nbsp;
pxwidth = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;pxwidth&quot;</span> <span style="color: #003f00;">&#41;</span>;
pxheight = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;pxheight&quot;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// clalculate charting area width and height</span>
Miny = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;axisminy&quot;</span> <span style="color: #003f00;">&#41;</span>;
Maxy = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;axismaxy&quot;</span> <span style="color: #003f00;">&#41;</span>;
YRange = MaxY - MinY;
VisBarIndex =  GetVisualBarIndex<span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#41;</span>;
NumBarsVisible = StaticVarGet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;NumberbarsVisible&quot;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// Calculate Pane width and height</span>
pxPaneWidth = pxwidth - pxLeftArea - pxRightArea;
pxPaneHeight = pxHeight - pxTopArea - pxBottomArea;
&nbsp;
<span style="color: #007f00; ">// calculate conversion factors</span>
PixelsPerBar 	= pxPaneWidth / NumBarsVisible;
PixelsPerPrice = pxPaneHeight / YRange;
_SECTION_END<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

<p>Edited by Al Venosa.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/03/21/using-a-gfx-include-file/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating GFX Chart-Overlays (v3)</title>
		<link>http://www.amibroker.org/userkb/2008/03/20/creating-gfx-chart-overlays/</link>
		<comments>http://www.amibroker.org/userkb/2008/03/20/creating-gfx-chart-overlays/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 20:10:00 +0000</pubDate>
		<dc:creator>Herman</dc:creator>
		
		<category><![CDATA[GFX Programming]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/2008/03/20/creating-gfx-chart-overlays/</guid>
		<description><![CDATA[Important note: The AmiBroker 5.09.0 Beta introduced the following new GFX functions:
Status(&#8221;pxchartleft&#8221;) - returns x-coordinate of top-left corner of chart area
Status(&#8221;pxcharttop&#8221;) - returns y-coordinate of top-left corner of chart area
Status(&#8221;pxchartright&#8221;) - returns x-coordinate of bottom-right corner of chart area
Status(&#8221;pxchartbottom&#8221;) - returns y-coordinate of bottom-right corner of chart area
Status(&#8221;pxchartwidth&#8221;) - returns width chart area (right-left)
Status(&#8221;pxchartheight&#8221;) - [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Important note</strong>: The <a href="http://www.amibroker.com/members/bin/ab5090beta.exe">AmiBroker 5.09.0 Beta</a> introduced the following new GFX functions:</p>
<p>Status(&#8221;pxchartleft&#8221;) - returns x-coordinate of top-left corner of chart area<br />
Status(&#8221;pxcharttop&#8221;) - returns y-coordinate of top-left corner of chart area<br />
Status(&#8221;pxchartright&#8221;) - returns x-coordinate of bottom-right corner of chart area<br />
Status(&#8221;pxchartbottom&#8221;) - returns y-coordinate of bottom-right corner of chart area<br />
Status(&#8221;pxchartwidth&#8221;) - returns width chart area (right-left)<br />
Status(&#8221;pxchartheight&#8221;) - returns width chart area (bottom-top)</p>
<p>Since this release appeared after this post was published these functions are not used in the examples below. This post has been left unchanged for educational purposes. For examples using the new functions please see the <a href="http://www.amibroker.com/devlog/wp-content/uploads/2008/04/readme5090.html">5.09.0 Read Me</a> file.</p>
<p align="center"> =====</p>
<p>Creating an exact chart overlay using GFX functions can be a daunting task for the non-professional programmer. The solutions presented here were derived through experimentation; if there is a better way, please make a comment. Once the pixel layout is fully understood, GFX becomes an extremely powerful tool and may just give you an additional trading edge. The first and most important step in using GFX functions is to understand how pixels make up your display. In AmiBroker the width and height of your charting pane can be retrieved using the following two functions:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="afl">pxwidth = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span><span style="color: #7f007f;">&quot;pxwidth&quot;</span><span style="color: #003f00;">&#41;</span>;
pxheight = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span><span style="color: #7f007f;">&quot;pxheight&quot;</span><span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

<p>Horizontal pixels count left to right, 1 to pxwidth; vertical pixels count top to bottom, 1 to pxheight. The area covered by these two numbers is shown in Yellow below. For a high resolution monitor this area may cover about 2000 (H) x 1000 (V) pixels. This pixel area includes the areas used by the X and Y axis, and the blank top and bottom margins.</p>
<p align="center">
<a href='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/pixelarea.png' title='pixelarea.png'><img src='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/pixelarea.png' alt='pixelarea.png' /></a></p>
<p>Next is the standard charting area, which is the area where your price charts are located. This area excludes the surrounding blank margins and the areas used for axis labeling. If you want to keep your overlay within the standard chart boundaries, you have to place your images within the above boundaries. This area is highlighted in Blue in the image below:</p>
<p align="center">
<a href='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/chartingarea.png' title='chartingarea.png'><img src='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/chartingarea.png' alt='chartingarea.png' /></a></p>
<p>The boundaries for this area can be determined by running the example code listed in <a href="http://www.amibroker.org/userkb/2008/03/14/finding-pixel-boundaries/">Finding Pixel Boundaries</a>. Eight parameters must be known to create pixel overlays:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="afl">pxwidth = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;pxwidth&quot;</span> <span style="color: #003f00;">&#41;</span>;
pxheight = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;pxheight&quot;</span> <span style="color: #003f00;">&#41;</span>;
pxLeftArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Left Blank Margin&quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Constant</span>
pxRightArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Right Axis Area&quot;</span>, <span style="color: #7f0000;">93</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">200</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Depends on font</span>
pxTopArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Top Blank Margin&quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Constant</span>
pxDateArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Date Axis Area&quot;</span>, <span style="color: #7f0000;">11</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Depends on font</span>
pxBottomArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Bottom Blank Margin&quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Constant</span>
DateaxisOn = ParamToggle<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Date Axis&quot;</span>, <span style="color: #7f007f;">&quot;HIDE|SHOW&quot;</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

<p>Since adding date labels to your DateTime axis changes the size of your pixel plotting area, you need to compensate for this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="afl"><span style="color: #7f0000; ">if</span><span style="color: #003f00;">&#40;</span> DateaxisOn <span style="color: #003f00;">&#41;</span> 
	<span style="color: #003f00;">&#123;</span>
	pxBottomArea = pxDateArea + pxBottomArea;
	SetChartOptions<span style="color: #003f00;">&#40;</span><span style="color: #7f0000;">2</span>,chartShowDates<span style="color: #003f00;">&#41;</span>;
	<span style="color: #003f00;">&#125;</span>
<span style="color: #7f0000; ">else</span> 
	<span style="color: #003f00;">&#123;</span>
	SetChartOptions<span style="color: #003f00;">&#40;</span><span style="color: #7f0000;">3</span>,chartShowDates<span style="color: #003f00;">&#41;</span>;
	<span style="color: #003f00;">&#125;</span></pre></td></tr></table></div>

<p>The pixel plotting area&#8217;s width and height can now be calculated:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="afl">pxPaneWidth = pxwidth - pxLeftArea- pxRightArea;
pxPaneHeight = pxHeight - pxTopArea- pxBottomArea;</pre></td></tr></table></div>

<p>The dimension of the Blue area shown earlier changes when you resize AmiBroker, open additional windows or panes, change the fonts in your axis, or turn On/Off date labels. When this happens you will have to recalibrate the boundaries. To convert prices to pixels, so that you can create an exact overlay, you also need to define the width and height of your regular chart pane. These are expressed in DateTime and Price units. They will change when you zoom your chart. When you have at least one price plot displayed, so that the values for miny and maxy are defined, you can calculate these boundaries as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="afl">Miny = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span><span style="color: #7f007f;">&quot;axisminy&quot;</span><span style="color: #003f00;">&#41;</span>;
Maxy = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span><span style="color: #7f007f;">&quot;axismaxy&quot;</span><span style="color: #003f00;">&#41;</span>;
YRange = MaxY - MinY
BarsVisible = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span><span style="color: #7f007f;">&quot;BarVisible&quot;</span><span style="color: #003f00;">&#41;</span>;
NumBarsVisible = Cum<span style="color: #003f00;">&#40;</span>BarsVisible<span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

<p>You now have all the information needed to calculate the Pixels/Price and Pixels/Bar conversion factors:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="afl">PixelsPerBar 	= pxPaneWidth / NumBarsVisible;
PixelsPerPrice = pxPaneHeight / YRange;</pre></td></tr></table></div>

<p>Putting it all together in a demo program (listed at the end of this post) produces the price-chart overlay shown below. The regular price plot is plotted using dots, so that the overlay is clearly visible. When you plot both traces in lines, you will see minor deviations that are probably due to rounding to the nearest pixel. The pixel price plot is shown in Red. The purpose of this exercise is to learn to work with pixels and be able to produce an exact overlay on the price chart. The Param window below the charts shows typical parameters; they will likely be different for your screen layout.</p>
<p align="center">
<a href='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/pricechartoverlay1.png' title='pricechartoverlay1.png'><img src='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/pricechartoverlay1.png' alt='pricechartoverlay1.png' /></a></p>
<p align="center">
<a href='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/pricechartoverlayparam.png' title='pricechartoverlayparam.png'><img src='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/pricechartoverlayparam.png' alt='pricechartoverlayparam.png' /></a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
</pre></td><td class="code"><pre class="afl"><span style="color: #7f0000; ">function</span> gfxPlotHLine<span style="color: #003f00;">&#40;</span> YPixels, Color <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    <span style="color: #7f0000;">global</span> pxwidth;
    GfxSelectPen<span style="color: #003f00;">&#40;</span> Color <span style="color: #003f00;">&#41;</span> ;
    GfxMoveTo<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">0</span>, YPixels <span style="color: #003f00;">&#41;</span>;
    GfxLineTo<span style="color: #003f00;">&#40;</span> pxwidth, YPixels <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> gfxPlotVLine<span style="color: #003f00;">&#40;</span> XPixels, Color <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    <span style="color: #7f0000;">global</span> pxheight;
    GfxSelectPen<span style="color: #003f00;">&#40;</span> Color <span style="color: #003f00;">&#41;</span> ;
    GfxMoveTo<span style="color: #003f00;">&#40;</span> XPixels, <span style="color: #7f0000;">0</span> <span style="color: #003f00;">&#41;</span>;
    GfxLineTo<span style="color: #003f00;">&#40;</span> XPixels, pxheight <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> GetVisualBarIndex<span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    lvb = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;lastvisiblebar&quot;</span> <span style="color: #003f00;">&#41;</span>;
    fvb = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;firstvisiblebar&quot;</span> <span style="color: #003f00;">&#41;</span>;
    bi = BarIndex<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span>;
    StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;NumberbarsVisible&quot;</span>, Lvb - fvb + <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;
    <span style="color: #7f0000; ">return</span> bi - bi<span style="color: #003f00;">&#91;</span> <span style="color: #7f0000;">0</span> <span style="color: #003f00;">&#93;</span> - fvb;
<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> GetYPixels<span style="color: #003f00;">&#40;</span> Y <span style="color: #003f00;">&#41;</span>
	<span style="color: #003f00;">&#123;</span>
	<span style="color: #7f0000;">global</span> PixelsPerPrice, pxTopArea, MaxY; 
	<span style="color: #7f0000; ">return</span> <span style="color: #003f00;">&#40;</span>MaxY - Y<span style="color: #003f00;">&#41;</span> * PixelsPerPrice + pxTopArea;
	<span style="color: #003f00;">&#125;</span>
&nbsp;
<span style="color: #7f0000; ">function</span> GetXPixels<span style="color: #003f00;">&#40;</span> X <span style="color: #003f00;">&#41;</span>
	<span style="color: #003f00;">&#123;</span>
	<span style="color: #7f0000;">global</span> PixelsPerBar, pxLeftArea;
	<span style="color: #7f0000; ">return</span> X * PixelsPerBar + pxLeftArea;
	<span style="color: #003f00;">&#125;</span>
&nbsp;
GraphXSpace = <span style="color: #7f0000;">5</span>;
SetChartOptions<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">0</span>, chartHideQuoteMarker <span style="color: #003f00;">&#41;</span>;
&nbsp;
pxwidth = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;pxwidth&quot;</span> <span style="color: #003f00;">&#41;</span>;
pxheight = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;pxheight&quot;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// These Parameters will change depending on screen layout/fonts</span>
pxRightArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Right Axis Area&quot;</span>, <span style="color: #7f0000;">93</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">200</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Depends on font</span>
pxDateArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Date Axis Area&quot;</span>, <span style="color: #7f0000;">11</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Depends on font</span>
DateaxisOn = ParamToggle<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Date Axis&quot;</span>, <span style="color: #7f007f;">&quot;HIDE|SHOW&quot;</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// These Parameters appear constant and can probably be hardcoded</span>
pxLeftArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Left Blank Margin&quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Constant</span>
pxTopArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Top Blank Margin&quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Constant</span>
pxBottomArea = Param<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Bottom Blank Margin&quot;</span>, <span style="color: #7f0000;">5</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">100</span>, <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>; <span style="color: #007f00; ">// Constant</span>
&nbsp;
<span style="color: #7f0000; ">if</span> <span style="color: #003f00;">&#40;</span> DateaxisOn <span style="color: #003f00;">&#41;</span> <span style="color: #007f00; ">// Size of bottom boundary depends on whether dates are shown</span>
<span style="color: #003f00;">&#123;</span>
    pxBottomArea = pxDateArea + pxBottomArea;
    SetChartOptions<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">2</span>, chartShowDates <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
<span style="color: #7f0000; ">else</span>
    SetChartOptions<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">3</span>, chartShowDates <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// Test Plots to help line up boundary lines</span>
Color = colorWhite;
gfxPlotVLine<span style="color: #003f00;">&#40;</span> pxLeftArea, color <span style="color: #003f00;">&#41;</span>;
gfxPlotVLine<span style="color: #003f00;">&#40;</span> pxwidth - pxRightArea, color <span style="color: #003f00;">&#41;</span>;
gfxPlotHLine<span style="color: #003f00;">&#40;</span> pxTopArea, color <span style="color: #003f00;">&#41;</span>;
gfxPlotHLine<span style="color: #003f00;">&#40;</span> pxHeight - pxBottomArea, color <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// Calculate Pane width and height</span>
pxPaneWidth = pxwidth - pxLeftArea - pxRightArea;
pxPaneHeight = pxHeight - pxTopArea - pxBottomArea;
&nbsp;
<span style="color: #007f00; ">// clalculate charting area width and height</span>
<span style="color: #0000ff;">Plot</span><span style="color: #003f00;">&#40;</span> C, <span style="color: #7f007f;">&quot;&quot;</span>, <span style="color: #7f0000;">1</span>, styleDots <span style="color: #003f00;">&#41;</span>;
Miny = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;axisminy&quot;</span> <span style="color: #003f00;">&#41;</span>;
Maxy = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;axismaxy&quot;</span> <span style="color: #003f00;">&#41;</span>;
YRange = MaxY - MinY;
VisBarIndex =  GetVisualBarIndex<span style="color: #003f00;">&#40;</span> <span style="color: #003f00;">&#41;</span>;
NumBarsVisible = StaticVarGet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;NumberbarsVisible&quot;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #007f00; ">// calculate conversion factors</span>
PixelsPerBar 	= pxPaneWidth / NumBarsVisible;
PixelsPerPrice = pxPaneHeight / YRange;
&nbsp;
<span style="color: #007f00; ">// For verification: Overlay pixel on price plot</span>
FVB = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;firstvisiblebar&quot;</span> <span style="color: #003f00;">&#41;</span>;
LVB = <span style="color: #0000ff;">Status</span><span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;lastvisiblebar&quot;</span> <span style="color: #003f00;">&#41;</span>;
GfxSelectPen<span style="color: #003f00;">&#40;</span> colorRed <span style="color: #003f00;">&#41;</span>;
<span style="color: #7f0000; ">for</span> <span style="color: #003f00;">&#40;</span> b = FVB + <span style="color: #7f0000;">1</span>; b &lt;= LVB AND b &lt; BarCount; b++ <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    PrevPixelY = GetYPixels<span style="color: #003f00;">&#40;</span> C<span style="color: #003f00;">&#91;</span>b<span style="color: #7f0000;">-1</span><span style="color: #003f00;">&#93;</span> <span style="color: #003f00;">&#41;</span>;
    PixelY = GetYPixels<span style="color: #003f00;">&#40;</span> C<span style="color: #003f00;">&#91;</span>b<span style="color: #003f00;">&#93;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
    PrevPixelX = GetXPixels<span style="color: #003f00;">&#40;</span> VisBarIndex<span style="color: #003f00;">&#91;</span>b<span style="color: #7f0000;">-1</span><span style="color: #003f00;">&#93;</span> <span style="color: #003f00;">&#41;</span>;
    PixelX = GetXPixels<span style="color: #003f00;">&#40;</span> VisBarIndex<span style="color: #003f00;">&#91;</span>b<span style="color: #003f00;">&#93;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
    GfxMoveTo<span style="color: #003f00;">&#40;</span> PrevPixelX, PrevPixelY <span style="color: #003f00;">&#41;</span>;
    GfxLineTo<span style="color: #003f00;">&#40;</span> PixelX, PixelY <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span></pre></td></tr></table></div>

<p>Edited by Al Venosa.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/03/20/creating-gfx-chart-overlays/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting prices with your cursor</title>
		<link>http://www.amibroker.org/userkb/2008/03/16/setting-prices-with-your-cursor/</link>
		<comments>http://www.amibroker.org/userkb/2008/03/16/setting-prices-with-your-cursor/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 23:20:52 +0000</pubDate>
		<dc:creator>Herman</dc:creator>
		
		<category><![CDATA[Real-Time Chart-Trading]]></category>

		<guid isPermaLink="false">http://www.amibroker.org/userkb/2008/03/16/setting-prices-with-your-cursor/</guid>
		<description><![CDATA[To place LMT or STP orders quickly is easiest done by moving the horizontal cursor-line over the desired price and making a left mouse click. The demo code below shows how you can lock in prices this way. To Chart-Trade additional code must be added to make the click perform one task of many, and [...]]]></description>
			<content:encoded><![CDATA[<p>To place LMT or STP orders quickly is easiest done by moving the horizontal cursor-line over the desired price and making a left mouse click. The demo code below shows how you can lock in prices this way. To Chart-Trade additional code must be added to make the click perform one task of many, and only do so when required. When you Apply the code below to an indicator you will see a dashed line at the cursor price. This dashed line refreshes only once per second with a local database, however, it will speed up when your chart is refreshed more frequently when working with live data. </p>
<p>Suppose you want to place a LMT order at $60.00 on the chart below. To do this you move the dashed line over the $60.00 price and click the Left mouse button. This will place a stationary solid line. You can now move your cursor to another price and click again, the solid line will move to this new location.  In actual trading you can follow the price in real time and adjust your Limit prices so that they stay exactly where you want them. The chart produced by this demo code looks like this:</p>
<p align="center"><a href='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/placingline.png' title='placingline.png'><img src='http://www.amibroker.org/userkb/wp-content/uploads/2008/03/placingline.png' alt='placingline.png' /></a></p>
<p>In Chart-Trading the first click that places the solid line would also place your order on the TWS. Each subsequent click would modify the order to the new price. This way you can adjust several prices on your chart, setting and moving around Entries, Targets, Stops, etc.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="afl">RequestTimedRefresh<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">1</span> <span style="color: #003f00;">&#41;</span>;
SetChartOptions<span style="color: #003f00;">&#40;</span> <span style="color: #7f0000;">2</span>, chartHideQuoteMarker <span style="color: #003f00;">&#41;</span>;
LButtonDown = GetCursorMouseButtons<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span> == <span style="color: #7f0000;">9</span>;
MousePrice = GetCursorYPosition<span style="color: #003f00;">&#40;</span><span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #7f0000; ">if</span> <span style="color: #003f00;">&#40;</span> MousePrice <span style="color: #003f00;">&#41;</span>
<span style="color: #003f00;">&#123;</span>
    StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;MousePrice&quot;</span>, MousePrice <span style="color: #003f00;">&#41;</span>;
    <span style="color: #7f0000; ">if</span> <span style="color: #003f00;">&#40;</span> LButtonDown <span style="color: #003f00;">&#41;</span>
        StaticVarSet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ClickedMousePrice&quot;</span>, MousePrice <span style="color: #003f00;">&#41;</span>;
<span style="color: #003f00;">&#125;</span>
&nbsp;
LB = BarCount - <span style="color: #7f0000;">1</span>;
MousePrice = Nz<span style="color: #003f00;">&#40;</span> StaticVarGet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;Mouseprice&quot;</span> <span style="color: #003f00;">&#41;</span>, <span style="color: #000000; font-weight: bold;">Null</span> <span style="color: #003f00;">&#41;</span>;
ClickedMousePrice = StaticVarGet<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ClickedMousePrice&quot;</span> <span style="color: #003f00;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">Plot</span><span style="color: #003f00;">&#40;</span> C, <span style="color: #7f007f;">&quot;&quot;</span>, <span style="color: #7f0000;">1</span>, <span style="color: #7f0000;">128</span> <span style="color: #003f00;">&#41;</span>;
<span style="color: #0000ff;">Plot</span><span style="color: #003f00;">&#40;</span> MousePrice, <span style="color: #7f007f;">&quot;&quot;</span>, colorWhite, <span style="color: #7f0000;">1</span> | styleNoRescale | styleDashed | styleNoLabel, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span>;
PlotText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;CURSOR &quot;</span> + NumToStr<span style="color: #003f00;">&#40;</span> MousePrice<span style="color: #003f00;">&#91;</span>LB<span style="color: #003f00;">&#93;</span>, <span style="color: #7f0000;">1.2</span> <span style="color: #003f00;">&#41;</span>, LB - <span style="color: #7f0000;">5</span>, MousePrice<span style="color: #003f00;">&#91;</span>LB<span style="color: #003f00;">&#93;</span>, colorBlack, colorWhite <span style="color: #003f00;">&#41;</span>;
<span style="color: #0000ff;">Plot</span><span style="color: #003f00;">&#40;</span> ClickedMousePrice, <span style="color: #7f007f;">&quot;&quot;</span>, colorBlack, <span style="color: #7f0000;">1</span> | styleNoLabel | styleNoRescale, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">0</span>, <span style="color: #7f0000;">2</span> <span style="color: #003f00;">&#41;</span>;
PlotText<span style="color: #003f00;">&#40;</span> <span style="color: #7f007f;">&quot;ORDER PLACED $&quot;</span> + NumToStr<span style="color: #003f00;">&#40;</span> ClickedMousePrice<span style="color: #003f00;">&#91;</span>LB<span style="color: #003f00;">&#93;</span>, <span style="color: #7f0000;">1.2</span> <span style="color: #003f00;">&#41;</span>, LB - <span style="color: #7f0000;">5</span>, ClickedMousePrice<span style="color: #003f00;">&#91;</span>LB<span style="color: #003f00;">&#93;</span>, colorBlack, colorWhite <span style="color: #003f00;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.amibroker.org/userkb/2008/03/16/setting-prices-with-your-cursor/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
