[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Real-Time Heat-Map



PureBytes Links

Trading Reference Links

BlankThanks Herman.

As I played around, I realized that this is actually much easier to code (at least for me) in vb.net than in AFL.  I did a heatmap of the NAS100 -- which was easy.  It does use up your allowed TWS symbols pretty fast, though!  

The idea of using the heatmap in the ways you suggested is pretty interesting:

"You can use it to map correlation between stocks, fastest moving stocks, liquidity, compliance to qualifying indicators, open portfolio positions, profits status of open positions, order status, etc. It is very effective to display a multitude of conditions, you can even expand it to several status maps in a separate windows. "


  ----- Original Message ----- 
  From: Herman 
  To: AmiBroker YahooGroups 
  Sent: Sunday, January 07, 2007 10:23 AM
  Subject: [amibroker] Real-Time Heat-Map


  Hello Chuck,

  Try the code below, I changed it to a function call and rewrote it for traditional use. But no Sorting yet...and it still needs some tuning here and there. However I have to do some other work...hopefully this will work better for you, let me know if it doesn't.

  best regards,

  herman

  SetBarsRequired(1000000,1000000);

  GraphXSpace = 0;

  GraphZOrder = False;

  SetChartOptions( 3, chartShowDates);

  WLNumber       = Param("WatchList Number",0,0,64,1);

  NumTickersToMap= Param("Num. Tickers to Map",10,1,100,1);

  MapPeriod      = Param("Mapping Period", 5,2,500,1); 

  MaxHue         = Param("Max. Hue",150,0,255,1);

  MinHue         = Param("Min. Hue",0,0,255,1);

  Test           = ParamToggle("Test Data","OFF|ON",0);

  MApRefreshPd   = Param("Map-Refresh Period (Sec)",1,1,60,1);

  RequestTimedRefresh( MApRefreshPd );

   

  function GetVarToMap( Ticker, Period )

     {

     local R;

     CloseArray = Foreign(Ticker,"C");

     R = LastValue(ROC( CloseArray, Period ));

     return R;

     }

   

  function DrawHeatMap( WLNumber, NumTickersToMap, Test )

     {

     global MaxHue, MinHue; 

   

     // Pre-Process Data

     List = CategoryGetSymbols( categoryWatchlist, WLNumber);

     StaticVarSetText("MappingList",List);

     MaxVarToMap = 0;

     MinVarToMap = 10^10;

     for( T=0; (Ticker=StrExtract( List, T))!= "" AND T < NumTickersToMap; T++)

        {

        VarToMap = GetVarToMap( Ticker, MapPeriod );

        StaticVarSet(Ticker+"-VarToMap",VarToMap);

        if( VarToMap > MaxVarToMap ) MaxVarToMap = VarToMap;

        if( VarToMap < MinVarToMap ) MinVarToMap = VarToMap;

        }

     NumTickersToMap = Min(T,NumTickersToMap);

   

     // Normalize Values

     Range    = MaxVarToMap - MinVarToMap;

     Offset   = MinVarToMap;

     NormUnit = 255/Range;

     for( T=0; T < NumTickersToMap; T++)

        {

        Ticker=StrExtract( List, T);

        VarToMap = StaticVarGet(Ticker+"-VarToMap");

        NormVarToMap = NormUnit * (VarToMap - Offset);

        StaticVarSet(Ticker+"-NormVarToMap",NormVarToMap);

        }

   

     // Draw Heat Map

     DIM            = int(sqrt(NumTickersToMap-1));

     NumCells       = DIM^2;

     if( NumCells < NumTickersToMap ) { DIM++; NumCells = DIM^2; }

     MinXBarindex   = BarCount-DIM;

     MaxXBarindex   = BarCount-1;

     Plot(0,"",1,styleNoLine|styleNoLabel);

     Plot(DIM,"",1,styleNoLine|styleNoLabel);

     for( N=X=0, Y=1; N<NumTickersToMap; N++ )

        {

        if( N%DIM== 0 ) X=0; else X++; 

        Ticker=StrExtract( List, N);

        VarToMap = StaticVarGet(Ticker+"-VarToMap");

        NormVarToMap = StaticVarGet(Ticker+"-NormVarToMap");

        HueStep   = (MaxHue - MinHue)/255;

        Co = ColorHSB(Min(255,int((NormVarToMap)*HueStep)),255,255);

        if( Test ) PlotText(Ticker+"\n"+NumToStr(VarToMap ,1.2)+"r\nHSB"+NumToStr(NormVarToMap ,1.0)+"\n"+NumToStr(N ,1.0),MinXBarindex+X,Y-0.5,1);

        else PlotText(Ticker+"\n"+NumToStr(VarToMap ,1.2)+"%",MinXBarindex+X,Y-0.5,1);

   

        Plot(IIf(MinXBarindex+X==BarIndex(),Y,Null),"",Co,styleArea|styleOwnScale|styleNoLabel,0,DIM*1.03);

        if( (N+1)%DIM == 0 ) Y++;

        }

     VarSetText("Title","\n"+ 

     "MaxValue: "+NumToStr(MaxVarToMap,1.2)+"\n"+

     "MinValue: "+NumToStr(MinVarToMap,1.2)+"\n"+

     "   Range: "+NumToStr(Range,1.2)+"\n"+

     "  OffSet: "+NumToStr(OffSet,1.2)+"\n");

     } 

   

  DrawHeatMap( WLNumber, NumTickersToMap, Test );

   

  Title;

   

   





   


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.7/618 - Release Date: 1/6/2007 7:47 PM