int OnInit()
{
EventSetTimer(1);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
EventKillTimer();
ObjectsDeleteAll();
}
double X1=200;
double A1=90;
double V360=1440;
int GGXG=-1;
int GGYG=-1;
string A[]={"M","O","H","A","M","M","E","D"," ","S","A","F","A","R"," ","A","L","O","T","A","I","B","I"," ","W","E","L","C","O","M","E","S"," ","A","L","L"};
void OnTimer()
{ GGXG++;
if(GGXG>300)GGXG=0;
for(int i=0;i<160;i++)
{
double XX1=500+1.5*X1*MathCos(double(i*A1*M_PI/V360));
double YY1=300+X1*MathSin(double(i*A1*M_PI/V360));
if(i>=GGXG && i<ArraySize(A)+GGXG && A[i-GGXG]!=" ")
{
string ran1=(string)MathMod(MathRand(),256);
string ran2=(string)MathMod(MathRand(),256);
string ran3=(string)MathMod(MathRand(),256);
string a="C"+"'"+ran1+","+ran2+","+ran3+"'";
color ran=StringToColor(a);
Create_Button("IND_SIN_"+i,A[i-GGXG], XX1-5,YY1-5, 35,35, 12,ran, C'255,255,0', C'255,255,0', "FOURIER_2");
}
else
{
ObjectDelete("IND_SIN_"+i);
}
}
}
void Create_Button(string Inpname,string text, int X, int Y, int W, int H, int width, color BackColor, color TextColor, color borderColor, string TOOL)
{
ObjectDelete(0,Inpname);
ObjectCreate(0,Inpname,OBJ_BUTTON,0,0,0);
ObjectSetInteger(0,Inpname,OBJPROP_XSIZE,W);
ObjectSetInteger(0,Inpname,OBJPROP_YSIZE,H);
ObjectSetInteger(0,Inpname,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,Inpname,OBJPROP_XDISTANCE,X);
ObjectSetInteger(0,Inpname,OBJPROP_YDISTANCE,Y);
ObjectSetInteger(0,Inpname,OBJPROP_FONTSIZE,width);
ObjectSetInteger(0,Inpname,OBJPROP_HIDDEN,true);
ObjectSetString(0,Inpname,OBJPROP_TOOLTIP,TOOL);
ObjectSetInteger(0,Inpname,OBJPROP_BORDER_TYPE,BORDER_RAISED);
ObjectSetInteger(0, Inpname,OBJPROP_BACK,FALSE);
ObjectSetInteger(0, Inpname,OBJPROP_SELECTABLE,FALSE);
ObjectSetInteger(0, Inpname,OBJPROP_SELECTED,FALSE);
ObjectSetInteger(0, Inpname,OBJPROP_HIDDEN,FALSE);
ObjectSetInteger(0, Inpname,OBJPROP_ZORDER,1);
ObjectSetInteger(0, Inpname,OBJPROP_BGCOLOR,BackColor);
ObjectSetInteger(0, Inpname,OBJPROP_ALIGN,ALIGN_LEFT);
ObjectSetInteger(0, Inpname,OBJPROP_BORDER_COLOR,borderColor);
ObjectSetInteger(0, Inpname,OBJPROP_COLOR,TextColor);
ObjectSetString(0, Inpname,OBJPROP_FONT,"TAHOMA");
ObjectSetString(0, Inpname,OBJPROP_TEXT,text);
}



//--- locals
double scaleMax,scaleMin,scaleEdge;
//---
int arrayMax,arrayMin;
int j,xoffset;
//--- Color 1 parameters
int r_1 = 0;
int g_1 = 255;
int b_1 = 0;
//--- Color 2 parameters
int r_2 = 255;
int g_2 = 255;
int b_2 = 255;
//--- Color 3 parameters
int r_3 = 255;
int g_3 = 0;
int b_3 = 0;
int midValue=(symbolsTotal%2==0 ? symbolsTotal/2 :(symbolsTotal-1)/2)-1;
//--- Build an array of colors and calculate percentage price's change
for(int i=0;i<symbolsTotal;i++)
{
//--- Local variables
int r_value = r_2;
int g_value = g_2;
int b_value = b_2;
//--- Calculates the percent change of each symbol
if(CopyRates(marketWatchSymbolsList[i],periodsel,0,2,DailyBar)==2)
{
percentChange[i]=((DailyBar[0].close/DailyBar[1].close)-1)*100;
if(i<=midValue) // Positive values
{
//--- Positive interpolation function
r_value = r_1-i*(r_1-r_2)/midValue;
g_value = g_1-i*(g_1-g_2)/midValue;
b_value = b_1-i*(b_1-b_2)/midValue;
}
else
{
//--- Negative interpolation function
r_value = r_2-(i-midValue-1)*(r_2-r_3)/midValue;
g_value = g_2-(i-midValue-1)*(g_2-g_3)/midValue;
b_value = b_2-(i-midValue-1)*(b_2-b_3)/midValue;
}
}
//--- Sets all possible colors to the array colorArray[]
string rgbColor=IntegerToString(r_value)+","+IntegerToString(g_value)+","+IntegerToString(b_value);
colorArray[i]=StringToColor(rgbColor);
}
//--- Determine maximum/minimum and the scale value
arrayMax=ArrayMaximum(percentChange); arrayMin=ArrayMinimum(percentChange);
if(arrayMax==-1 || arrayMin==-1) return;
//--- Determine the scale
scaleEdge=MathMax(MathAbs(percentChange[arrayMax]),MathAbs(percentChange[arrayMin]));
//---
scaleMax=scaleEdge; scaleMin=-scaleEdge;
midValue=(symbolsTotal%2==0 ? symbolsTotal/2 :(symbolsTotal-1)/2);
//--- Sets colors to the heatmap
for(int i=0;i<symbolsTotal;i++)
{
//--- Local variable
int heatmapColor=0;
//--- Sets the color position (gradientColor) inside the colorArray
if(percentChange[i]>0)
{
//--- color index between 0 and (symbolsTotal/2)-1
heatmapColor=(int)MathFloor((1-percentChange[i]/scaleMax)*midValue);
}
else if(percentChange[i]<0)
{
//--- color index between symbolsTotal/2 and symbolsTotal-1
heatmapColor=(int)MathCeil((percentChange[i]/scaleMin)*midValue)+midValue-1;
}
else
{
heatmapColor=midValue; // Mid position
}
if(heatmapColor<0) Print("Array out of range, heatmapcolor=",heatmapColor);
if(heatmapColor>=ArraySize(colorArray)) Print("Array out of range, heatmapcolor=",heatmapColor," colorArray size=",ArraySize(colorArray));
displaylist[i][0] = percentChange[i];
displaylist[i][1] = heatmapColor;
displaylist[i][2] = i;
}
if (sort == true) {
if (sortmode == 0)
ArraySort(displaylist,WHOLE_ARRAY,0,MODE_ASCEND);
else
ArraySort(displaylist,WHOLE_ARRAY,0,MODE_DESCEND);
}