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

RE: [amibroker] Real-Time Heat-Map



PureBytes Links

Trading Reference Links

Herman:
 
Related to your pasting in the code. Since it is color coded, can I assume
it is from the Formula Editor window?  If so, how do you paste it without a
space (line feed?) betweem each line?
 
One of my minor irritations in life....:)
 
Ken

  _____  

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of Herman
Sent: Sunday, January 07, 2007 10:23 AM
To: AmiBroker YahooGroups
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|st
yleNoLabel,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.6/617 - Release Date: 1/5/2007 11:11 AM