{"id":66,"date":"2007-10-11T18:34:43","date_gmt":"2007-10-11T23:34:43","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2007\/10\/11\/low-level-gfx-example-yearlymonthly-profit-chart\/"},"modified":"2014-12-04T08:25:08","modified_gmt":"2014-12-04T13:25:08","slug":"low-level-gfx-example-yearlymonthly-profit-chart","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2007\/10\/11\/low-level-gfx-example-yearlymonthly-profit-chart\/","title":{"rendered":"Low-level gfx example: Yearly\/monthly profit chart"},"content":{"rendered":"

The code below is an little bit more complex example of Low Level Graphics functions (see http:\/\/www.amibroker.com\/guide\/a_lowlevelgfx.html)<\/p>

It allows to display three kinds of charts:<\/p>

  1. yearly\/monthly profit table
  2. yearly profit bar chart
  3. average monthly profit bar chart<\/ol>

    The type of chart is switchable from Parameters dialog.<\/p>

    It should be applied to ~~~EQUITY – portfolio equity symbol (so it only produces output if you run backtest before using it). <\/p>
    SetBarsRequired<\/span>(<\/span>1000000<\/span>,<\/span>1000000<\/span>);
    <\/span>eq <\/span>= <\/span>Foreign<\/span>(<\/span>"~~~EQUITY"<\/span>, <\/span>"C" <\/span>);

    <\/span>yr <\/span>= <\/span>Year<\/span>();
    <\/span>mo <\/span>= <\/span>Month<\/span>();

    <\/span>YearChange <\/span>= <\/span>yr <\/span>!= <\/span>Ref<\/span>( <\/span>yr<\/span>, -<\/span>1 <\/span>);
    <\/span>MonChange <\/span>= <\/span>mo <\/span>!= <\/span>Ref<\/span>( <\/span>mo<\/span>, -<\/span>1 <\/span>);

    <\/span>FirstYr <\/span>= <\/span>0<\/span>;
    <\/span>LastYr <\/span>= <\/span>0<\/span>;

    <\/span>startbar <\/span>= <\/span>0<\/span>;

    <\/span>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    \/\/ SKIP non-trading bars
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    <\/span>for( <\/span>i <\/span>= <\/span>0<\/span>; <\/span>i <\/span>< <\/span>BarCount<\/span>; <\/span>i<\/span>++ )
    {
      if( <\/span>eq<\/span>[ <\/span>i <\/span>] )
      {
        <\/span>startbar <\/span>= <\/span>i<\/span>;
        break;
      } 
    }

    <\/span>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    \/\/ collect yearly \/ monthly changes in equity
    \/\/ into dynamic variables
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

    <\/span>LastYrValue <\/span>= <\/span>eq<\/span>[ <\/span>startbar  <\/span>];
    <\/span>LastMoValue <\/span>= <\/span>eq<\/span>[ <\/span>startbar  <\/span>];

    <\/span>MaxYrProfit <\/span>= <\/span>MinYrProfit <\/span>= <\/span>0<\/span>;
    <\/span>MaxMoProfit <\/span>= <\/span>MinMoProfit <\/span>= <\/span>0<\/span>;

    for( <\/span>i <\/span>= <\/span>startbar <\/span>+ <\/span>1<\/span>; <\/span>i <\/span>< <\/span>BarCount<\/span>; <\/span>i<\/span>++ )
    {
      if( <\/span>YearChange<\/span>[ <\/span>i <\/span>] || <\/span>i <\/span>== <\/span>BarCount <\/span>- <\/span>1 <\/span>)
      {
        <\/span>Chg <\/span>= <\/span>100 <\/span>* ( -<\/span>1 <\/span>+ <\/span>eq<\/span>[ <\/span>i <\/span>] \/ <\/span>LastYrValue <\/span>);
        <\/span>VarSet<\/span>(<\/span>"ChgYear"<\/span>+ <\/span>yr<\/span>[ <\/span>i <\/span>- <\/span>1 <\/span>], <\/span>Chg <\/span>);

        <\/span>MaxYrProfit <\/span>= <\/span>Max<\/span>( <\/span>MaxYrProfit<\/span>, <\/span>Chg <\/span>);
        <\/span>MinYrProfit <\/span>= <\/span>Min<\/span>( <\/span>MinYrProfit<\/span>, <\/span>Chg <\/span>);

        if( <\/span>FirstYr <\/span>== <\/span>0 <\/span>) <\/span>FirstYr <\/span>= <\/span>yr<\/span>[ <\/span>i <\/span>- <\/span>1 <\/span>];
        <\/span>LastYr <\/span>= <\/span>yr<\/span>[ <\/span>i <\/span>];

        <\/span>LastYrValue <\/span>= <\/span>eq<\/span>[ <\/span>i <\/span>];
      }

      if( <\/span>MonChange <\/span>[ <\/span>i <\/span>] || <\/span>i <\/span>== <\/span>BarCount <\/span>- <\/span>1 <\/span>)
      {
        <\/span>mon <\/span>= <\/span>mo<\/span>[ <\/span>i <\/span>- <\/span>1 <\/span>];

        <\/span>Chg <\/span>= <\/span>100 <\/span>* ( -<\/span>1 <\/span>+ <\/span>eq<\/span>[ <\/span>i <\/span>] \/ <\/span>LastMoValue <\/span>);

        <\/span>VarSet<\/span>(<\/span>"ChgMon" <\/span>+ <\/span>yr<\/span>[ <\/span>i <\/span>- <\/span>1 <\/span>] + <\/span>"-" <\/span>+ <\/span>mon<\/span>, <\/span>Chg <\/span>);
        <\/span>VarSet<\/span>(<\/span>"SumChgMon"<\/span>+ <\/span>mon<\/span>, <\/span>Chg <\/span>+ <\/span>Nz<\/span>( <\/span>VarGet<\/span>(<\/span>"SumChgMon"<\/span>+ <\/span>mon <\/span>) ) );
        <\/span>VarSet<\/span>(<\/span>"SumMon" <\/span>+ <\/span>mon<\/span>, <\/span>1 <\/span>+ <\/span>Nz<\/span>( <\/span>VarGet<\/span>(<\/span>"SumMon"<\/span>+ <\/span>mon <\/span>) ) );
     
        <\/span>MaxMoProfit <\/span>= <\/span>Max<\/span>( <\/span>MaxMoProfit<\/span>, <\/span>Chg <\/span>);
        <\/span>MinMoProfit <\/span>= <\/span>Min<\/span>( <\/span>MinMoProfit<\/span>, <\/span>Chg <\/span>);

        <\/span>LastMoValue <\/span>= <\/span>eq<\/span>[ <\/span>i <\/span>];
      }
    }

    <\/span>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    \/\/ Drawing code & helper functions
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

    <\/span>GfxSetOverlayMode<\/span>( <\/span>2 <\/span>);

    <\/span>CellHeight <\/span>= (<\/span>Status<\/span>(<\/span>"pxheight"<\/span>)-<\/span>1<\/span>)\/(<\/span>LastYr <\/span>- <\/span>FirstYr <\/span>+ <\/span>3 <\/span>); 
    <\/span>CellWidth <\/span>= (<\/span>Status<\/span>(<\/span>"pxwidth"<\/span>)-<\/span>1<\/span>)\/<\/span>14<\/span>
    <\/span>GfxSelectFont<\/span>( <\/span>"Tahoma"<\/span>, <\/span>8.5 <\/span>); 

    <\/span>GfxSetBkMode<\/span>( <\/span>1 <\/span>);

    function <\/span>PrintInCell<\/span>( <\/span>string<\/span>, <\/span>row<\/span>, <\/span>Col <\/span>
    {
     <\/span>Color <\/span>=  <\/span>ColorRGB<\/span>( <\/span>IIf<\/span>( <\/span>row <\/span>== <\/span>0 <\/span>|| <\/span>col <\/span>== <\/span>0 <\/span>|| <\/span>col <\/span>== <\/span>13<\/span>, <\/span>220<\/span>, <\/span>255 <\/span>), <\/span>255<\/span>, <\/span>IIf<\/span>( <\/span>row <\/span>% <\/span>2<\/span>, <\/span>255<\/span>, <\/span>220 <\/span>) );
     <\/span>GfxSelectSolidBrush<\/span>( <\/span>Color   <\/span>);
     <\/span>GfxRectangle<\/span>( <\/span>Col <\/span>* <\/span>CellWidth<\/span>
                        <\/span>row <\/span>* <\/span>CellHeight<\/span>, (<\/span>Col <\/span>+ <\/span>1 <\/span>) * <\/span>CellWidth <\/span>+ <\/span>1<\/span>
                        (<\/span>row <\/span>+ <\/span>1 <\/span>) * <\/span>CellHeight  <\/span>+ <\/span>1<\/span>); 
     <\/span>GfxDrawText<\/span>( <\/span>string<\/span>, <\/span>Col <\/span>* <\/span>CellWidth <\/span>+ <\/span>1<\/span>
                        <\/span>row <\/span>* <\/span>CellHeight <\/span>+ <\/span>1<\/span>
                        (<\/span>Col <\/span>+ <\/span>1 <\/span>) * <\/span>CellWidth<\/span>, (<\/span>row <\/span>+ <\/span>1 <\/span>) * <\/span>CellHeight<\/span>, <\/span>32<\/span>+<\/span>5 <\/span>); 



    <\/span>YOffset <\/span>= <\/span>25<\/span>;
    <\/span>XOffset <\/span>= <\/span>15<\/span>;

    function <\/span>DrawBar<\/span>( <\/span>text<\/span>, <\/span>bar<\/span>, <\/span>numbars<\/span>, <\/span>y<\/span>, <\/span>Miny<\/span>, <\/span>Maxy <\/span>)
    {
     <\/span>BarWidth <\/span>= (<\/span>Status<\/span>(<\/span>"pxwidth"<\/span>) - <\/span>4 <\/span>* <\/span>XOffset <\/span>)\/( <\/span>numbars <\/span>+ <\/span>1 <\/span>); 
     <\/span>BarHeight <\/span>= <\/span>Status<\/span>(<\/span>"pxheight"<\/span>) - <\/span>2 <\/span>* <\/span>YOffset<\/span>;
     <\/span>relpos <\/span>= ( <\/span>y <\/span>- <\/span>Miny <\/span>) \/ (<\/span>Maxy <\/span>- <\/span>Miny <\/span>);

     <\/span>xp <\/span>= <\/span>XOffset <\/span>+ ( <\/span>bar <\/span>+ <\/span>0.5 <\/span>) * <\/span>BarWidth<\/span>;
     <\/span>yp <\/span>= <\/span>YOffset <\/span>+ <\/span>BarHeight <\/span>* ( <\/span>1 <\/span>- <\/span>relpos <\/span>);
     <\/span>xe <\/span>= <\/span>XOffset <\/span>+ ( <\/span>bar <\/span>+ <\/span>1 <\/span>) * <\/span>BarWidth<\/span>;
     <\/span>ye <\/span>= <\/span>YOffset <\/span>+ <\/span>BarHeight <\/span>* ( <\/span>1 <\/span>- ( -<\/span>miny <\/span>)\/( <\/span>maxy <\/span>- <\/span>miny <\/span>) );
      
     if( <\/span>y <\/span>> <\/span>0 <\/span>)
     {
     <\/span>GfxGradientRect<\/span>( <\/span>xp<\/span>, <\/span>yp<\/span>,
                      <\/span>xe <\/span>, <\/span>ye<\/span>,
                      <\/span>ColorHSB<\/span>( <\/span>70<\/span>, <\/span>255 <\/span>* <\/span>relpos<\/span>, <\/span>255 <\/span>), <\/span>ColorHSB<\/span>( <\/span>70<\/span>, <\/span>20<\/span>, <\/span>255 <\/span>) );
     }
     else
     {
     <\/span>GfxGradientRect<\/span>( <\/span>xp<\/span>, <\/span>ye<\/span>,
                      <\/span>xe <\/span>, <\/span>yp<\/span>,
                      <\/span>ColorHSB<\/span>( <\/span>0<\/span>, <\/span>20<\/span>, <\/span>255 <\/span>), <\/span>ColorHSB<\/span>( <\/span>0<\/span>, <\/span>255 <\/span>* ( <\/span>1 <\/span>- <\/span>relpos <\/span>), <\/span>255 <\/span>) );
     }
     <\/span>GfxTextOut<\/span>( <\/span>text<\/span>, <\/span>xp<\/span>, <\/span>ye <\/span>);
     <\/span>GfxTextOut<\/span>( <\/span>StrFormat<\/span>(<\/span>"%.2f"<\/span>, <\/span>y <\/span>), <\/span>xp<\/span>, <\/span>yp <\/span>);
    }    

    function <\/span>DrawLevels<\/span>( <\/span>Miny<\/span>, <\/span>Maxy <\/span>)
    {
      <\/span>range <\/span>= <\/span>Maxy <\/span>- <\/span>Miny<\/span>;

      <\/span>grid <\/span>= <\/span>100<\/span>;
      if( <\/span>range <\/span>< <\/span>10 <\/span>) <\/span>grid <\/span>= <\/span>1<\/span>;
      else 
      if( <\/span>range <\/span>< <\/span>20 <\/span>) <\/span>grid <\/span>= <\/span>2<\/span>;
      else 
      if( <\/span>range <\/span>< <\/span>50 <\/span>) <\/span>grid <\/span>= <\/span>5<\/span>;
      else 
      if( <\/span>range <\/span>< <\/span>100 <\/span>) <\/span>grid <\/span>= <\/span>10<\/span>;
      else 
      if( <\/span>range <\/span>< <\/span>200 <\/span>) <\/span>grid <\/span>= <\/span>20<\/span>;
      else 
      if( <\/span>range <\/span>< <\/span>500 <\/span>) <\/span>grid <\/span>= <\/span>50<\/span>;

      <\/span>_TRACE<\/span>(<\/span>"grid = "<\/span>+<\/span>grid <\/span>+<\/span>" range "<\/span>+<\/span>range <\/span>);
      
      <\/span>width <\/span>= <\/span>Status<\/span>(<\/span>"pxwidth"<\/span>) - <\/span>4 <\/span>* <\/span>XOffset<\/span>;
      <\/span>height <\/span>= <\/span>Status<\/span>(<\/span>"pxheight"<\/span>) - <\/span>2 <\/span>* <\/span>YOffset<\/span>;

      <\/span>GfxSelectPen<\/span>( <\/span>colorBlack<\/span>, <\/span>1<\/span>, <\/span>2 <\/span>);
      for( <\/span>y <\/span>= <\/span>grid <\/span>* <\/span>ceil<\/span>( <\/span>Miny <\/span>\/ <\/span>grid <\/span>); <\/span>y <\/span><= <\/span>grid <\/span>* <\/span>floor<\/span>( <\/span>Maxy <\/span>\/ <\/span>grid <\/span>); <\/span>y <\/span>+= <\/span>grid <\/span>)
      {
        <\/span>yp <\/span>=  <\/span>YOffset <\/span>+ <\/span>Height <\/span>* ( <\/span>1 <\/span>-  ( <\/span>y <\/span>- <\/span>Miny <\/span>) \/ (<\/span>Maxy <\/span>- <\/span>Miny <\/span>) );

        <\/span>GfxMoveTo<\/span>( <\/span>XOffset<\/span>, <\/span>yp <\/span>);
        <\/span>GfxLineTo<\/span>( <\/span>XOffset <\/span>+ <\/span>width <\/span>, <\/span>yp <\/span>);
        <\/span>GfxTextOut<\/span>( <\/span>""<\/span>+ <\/span>y<\/span>, <\/span>XOffset <\/span>+ <\/span>2 <\/span>+ <\/span>width<\/span>, <\/span>yp <\/span>);
      }

      <\/span>GfxSelectPen<\/span>( <\/span>colorBlack<\/span>, <\/span>1<\/span>, <\/span>0 <\/span>);
      <\/span>GfxMoveTo<\/span>( <\/span>XOffset<\/span>, <\/span>YOffset <\/span>);
      <\/span>GfxLineTo<\/span>( <\/span>XOffset <\/span>+ <\/span>width<\/span>, <\/span>YOffset <\/span>);
      <\/span>GfxLineTo<\/span>( <\/span>XOffset <\/span>+ <\/span>width<\/span>, <\/span>YOffset <\/span>+ <\/span>Height <\/span>);
      <\/span>GfxLineTo<\/span>( <\/span>XOffset <\/span>, <\/span>YOffset <\/span>+ <\/span>Height <\/span>);
      <\/span>GfxLineTo<\/span>( <\/span>XOffset <\/span>, <\/span>YOffset <\/span>);
    }

    <\/span>MonthNames <\/span>= <\/span>"Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"<\/span>;

    function <\/span>DisplayProfitTable<\/span>( )
    {
     <\/span>Header <\/span>= <\/span>"Year,"<\/span>+<\/span>MonthNames<\/span>+<\/span>",Yr Profit%"<\/span>;
     for( <\/span>Col <\/span>= <\/span>0<\/span>; (<\/span>Colname <\/span>= <\/span>StrExtract<\/span>( <\/span>Header<\/span>, <\/span>Col <\/span>) ) != <\/span>""<\/span>; <\/span>Col<\/span>++ )
     {
      <\/span>PrintInCell<\/span>( <\/span>ColName<\/span>, <\/span>0<\/span>, <\/span>Col <\/span>);
     }

     <\/span>Row <\/span>= <\/span>1<\/span>;
     for( <\/span>y <\/span>= <\/span>FirstYr<\/span>; <\/span>y <\/span><= <\/span>LastYr<\/span>; <\/span>y<\/span>++ )
     {
      <\/span>PrintInCell<\/span>( <\/span>StrFormat<\/span>(<\/span>"%g"<\/span>, <\/span>y <\/span>), <\/span>Row<\/span>, <\/span>0 <\/span>); 
      <\/span>PrintInCell<\/span>( <\/span>StrFormat<\/span>(<\/span>"%.1f%%"<\/span>, <\/span>VarGet<\/span>(<\/span>"ChgYear" <\/span>+ <\/span>y <\/span>) ), <\/span>Row<\/span>, <\/span>13 <\/span>); 
      for( <\/span>m <\/span>= <\/span>1<\/span>; <\/span>m <\/span><= <\/span>12<\/span>; <\/span>m<\/span>++ )
      { 
       <\/span>Chg <\/span>= <\/span>VarGet<\/span>(<\/span>"ChgMon" <\/span>+ <\/span>y <\/span>+ <\/span>"-" <\/span>+ <\/span>m<\/span>);
       if( <\/span>Chg <\/span>
         <\/span>PrintInCell<\/span>( <\/span>StrFormat<\/span>(<\/span>"%.1f%%"<\/span>, <\/span>Chg <\/span>), <\/span>Row<\/span>, <\/span>m <\/span>);
       else
         <\/span>PrintInCell<\/span>( <\/span>"N\/A"<\/span>, <\/span>Row<\/span>, <\/span>m <\/span>);
      }
      <\/span>Row<\/span>++;
     } 

     <\/span>PrintInCell<\/span>(<\/span>"Mon. Avg"<\/span>, <\/span>Row<\/span>, <\/span>0 <\/span>);
     for( <\/span>m <\/span>= <\/span>1<\/span>; <\/span>m <\/span><= <\/span>12<\/span>; <\/span>m<\/span>++ )
     { 
       <\/span>PrintInCell<\/span>( <\/span>StrFormat<\/span>(<\/span>"%.1f%%"<\/span>,  <\/span>Nz<\/span>( <\/span>VarGet<\/span>(<\/span>"SumChgMon" <\/span>+ <\/span>m<\/span>)\/<\/span>VarGet<\/span>(<\/span>"SumMon" <\/span>+ <\/span>m <\/span>) ) ), <\/span>Row<\/span>, <\/span>m <\/span>);
     }

    }

    function <\/span>DisplayYearlyProfits<\/span>()
    {
     <\/span>Bar <\/span>= <\/span>0<\/span>;
     for( <\/span>y <\/span>= <\/span>FirstYr<\/span>; <\/span>y <\/span><= <\/span>LastYr<\/span>; <\/span>y<\/span>++ )
     {
       <\/span>Chg <\/span>= <\/span>VarGet<\/span>(<\/span>"ChgYear" <\/span>+ <\/span>y <\/span>);
       <\/span>DrawBar<\/span>( <\/span>""<\/span>+<\/span>y<\/span>, <\/span>Bar<\/span>++, ( <\/span>LastYr <\/span>- <\/span>FirstYr <\/span>+ <\/span>1 <\/span>), <\/span>Chg<\/span>, <\/span>MinYrProfit<\/span>, <\/span>MaxYrProfit <\/span>);
     }
     <\/span>GfxTextOut<\/span>(<\/span>"Yearly % Profit chart"<\/span>, <\/span>10<\/span>, <\/span>10 <\/span>);

     <\/span>DrawLevels<\/span>( <\/span>MinYrProfit<\/span>, <\/span>MaxYrProfit <\/span>); 
    }

    function <\/span>DisplayMonthlyProfits<\/span>()
    {
     <\/span>Bar <\/span>= <\/span>0<\/span>;
     
     <\/span>MinAvgProf <\/span>= <\/span>MaxAvgProf <\/span>= <\/span>0<\/span>;
     for( <\/span>y <\/span>= <\/span>1<\/span>; <\/span>y <\/span><= <\/span>12<\/span>; <\/span>y<\/span>++ )
     {
       <\/span>Chg <\/span>= <\/span>VarGet<\/span>(<\/span>"SumChgMon" <\/span>+ <\/span>y <\/span>) \/ <\/span>VarGet<\/span>(<\/span>"SumMon" <\/span>+ <\/span>y <\/span>);
       <\/span>MinAvgProf <\/span>= <\/span>Min<\/span>( <\/span>MinAvgProf<\/span>, <\/span>Chg <\/span>);
       <\/span>MaxAvgProf <\/span>= <\/span>Max<\/span>( <\/span>MaxAvgProf<\/span>, <\/span>Chg <\/span>);
     }

     for( <\/span>y <\/span>= <\/span>1<\/span>; <\/span>y <\/span><= <\/span>12<\/span>; <\/span>y<\/span>++ )
     {
       <\/span>Chg <\/span>= <\/span>VarGet<\/span>(<\/span>"SumChgMon" <\/span>+ <\/span>y <\/span>) \/ <\/span>VarGet<\/span>(<\/span>"SumMon" <\/span>+ <\/span>y <\/span>);
       <\/span>DrawBar<\/span>( <\/span>StrExtract<\/span>(<\/span>MonthNames<\/span>, <\/span>y<\/span>-<\/span>1 <\/span>), <\/span>Bar<\/span>++, <\/span>13<\/span>, <\/span>Chg<\/span>, <\/span>MinAvgProf <\/span>, <\/span>MaxAvgProf <\/span>);
     }
     <\/span>GfxTextOut<\/span>(<\/span>"Avg. Monthly % Profit chart"<\/span>, <\/span>10<\/span>, <\/span>10 <\/span>);

     <\/span>DrawLevels<\/span>( <\/span>MinAvgProf <\/span>, <\/span>MaxAvgProf <\/span>); 
    }

    <\/span>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    \/\/ This function checks if currently selected symbol
    \/\/ is portfolio equity
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    <\/span>function <\/span>CheckSymbol<\/span>()
    {
     if( <\/span>Name<\/span>() != <\/span>"~~~EQUITY" <\/span>)
     {
      <\/span>GfxSelectFont<\/span>( <\/span>"Tahoma"<\/span>, <\/span>20 <\/span>); 
      <\/span>GfxSetBkMode<\/span>( <\/span>2 <\/span>);
      <\/span>GfxTextOut<\/span>(<\/span>"For accurate results switch to ~~~EQUITY symbol"<\/span>, <\/span>10<\/span>, <\/span>10 <\/span>);
     }
    }

    <\/span>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    \/\/ Main program - chart type switch
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    <\/span>type <\/span>= <\/span>ParamList<\/span>(<\/span>"Chart Type"<\/span>, <\/span>"Profit Table|Yearly Profits|Avg. Monthly Profits"<\/span>, <\/span>0 <\/span>);

    switch( <\/span>type <\/span>)
    {
     case <\/span>"Profit Table"<\/span>
             <\/span>DisplayProfitTable<\/span>();  
             break;
     case <\/span>"Yearly Profits"<\/span>
             <\/span>DisplayYearlyProfits<\/span>();
             break;
     case <\/span>"Avg. Monthly Profits"<\/span>
             <\/span>DisplayMonthlyProfits<\/span>();
             break;
    }

    <\/span>CheckSymbol<\/span>()<\/code>

    Figure 1. Profit chart in table mode<\/p>

    Profit chart example 2<\/a><\/p>

    Figure 2. Profit chart in yearly mode<\/p>

    Profit chart example 3<\/a><\/p>

    Figure 3. Profit chart in monthly mode<\/p>

    Profit chart example 4<\/a><\/p>","protected":false},"excerpt":{"rendered":"

    The code below is an little bit more complex example of Low Level Graphics functions (see http:\/\/www.amibroker.com\/guide\/a_lowlevelgfx.html)It allows to display three kinds of charts:yearly\/monthly profit tableyearly profit bar chartaverage monthly profit bar chartThe type of chart is switchable from Parameters dialog.It should be applied to ~~~EQUITY – portfolio equity symbol (so it only produces output […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[53,15,55,16],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/66"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":828,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/66\/revisions\/828"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}