可以移動的欄位文字
純粹好玩//Button Text
#include <ControlPanelInclude-003c.afl>
SetChartOptions(0, chartShowDates,chartGridMiddle,0,0,0);
SetChartBkColor(colorBlack);
SetChartBkGradientFill(colorBlue,colorBlack);
_SECTION_BEGIN("K Bar");
pxW=Status("pxchartwidth");
pxH=Status("pxchartheight");
a=SelectedValue(BarIndex());
YesTH=TimeFrameGetPrice("H",inDaily,-1);
YesTL=TimeFrameGetPrice("L",inDaily,-1);
TodayH=TimeFrameGetPrice("H",inDaily,0);
TodayL=TimeFrameGetPrice("L",inDaily,0);
TodayO=TimeFrameGetPrice("O",inDaily,0);
Ticker = ParamStr("Symbol","TSEIDX");
TIckerO = Foreign(Ticker, "O");
TIckerH = Foreign(Ticker, "H");
TIckerL = Foreign(Ticker, "L");
TIckerC = Foreign(Ticker, "C");
TYesTH =TimeFrameGetPrice("TickerH",inDaily,-1);
TYesTL =TimeFrameGetPrice("TickerL",inDaily,-1);
TTodayH=TimeFrameGetPrice("TickerH",inDaily,0);
TTodayL=TimeFrameGetPrice("TickerL",inDaily,0);
TTodayO=TimeFrameGetPrice("TickerO",inDaily,0);
if (StaticVarGet("TXON"))
{
SetBarFillColor(IIf(C>O,colorRed,IIf(C<O,colorGreen,colorBlue)));
Plot(C,"Price",IIf(C>O,colorGold,colorTeal),styleCandle|styleNoTitle,0,0,0,0);
}
if (StaticVarGet("TIckerON"))
{
//TIcker = "TIckerIDX";PlotForeign( TIcker, "加權指數", colorGold, GetPriceStyle() );
SetBarFillColor(IIf(TIckerC>TIckerO,colorPink,IIf(TIckerC<TIckerO,colorPaleGreen,colorLightGrey)));
PlotOHLC(TIckerO,TIckerH,TIckerL,TIckerC,Ticker,IIf(TIckerC>TIckerO,colorRed,colorGreen),styleCandle|styleNoTitle,Null,Null,0,0);
}
_SECTION_END(); // End of Cell TEXT
//RequestTimedRefresh(1);
_SECTION_BEGIN("C1");
if (StaticVarGetText("TXON_Text")=="")
{
StaticVarSetText("TXON_Text",Name()+" K關 ");
}
if (StaticVarGetText("TIckerON_Text")=="")
{
StaticVarSetText("TIckerON_Text",Ticker+" K關 ") ;
}
ButtonHeight1 = Param("C1 Button Height",20,5,200,1);
ButtonWidth1 = Param("C1 Button Width",120,5,200,1);
FontRatio1 = Param("C1 Font: ButtonHeight ratio",2,0.5,5,0.1);
// Column Position Setting
PanelXoffset =pxW-20;
PanelYoffset =5;
PositionStr="@ "+NumToStr(GetCursorXPosition(1),1.0,False)+","+NumToStr(GetCursorYPosition(1),1.0,False);
ON_color=StaticVarGet("ON_color");
if (StaticVarGet("XON"))
{
Say( "C 1 Position");
if (ON_color == colorPaleGreen)
{
ON_color= colorPink;
}
else
{
ON_color= colorPaleGreen;
}
XLButtonDown = GetCursorMouseButtons() == 9;
//PositionStr="@ "+NumToStr(GetCursorXPosition(1),1.0,False)+","+NumToStr(GetCursorYPosition(1),1.0,False);
if( XLButtonDown )
{
StaticVarSet("C1_X", pxW-GetCursorXPosition(1));
StaticVarSet("C1_Y", pxH-GetCursorYPosition(1));
StaticVarSet("XON", 0);
Say( "C 1 Position Set");
ON_color= colorWhite;
//PositionStr="@ "+NumToStr(GetCursorXPosition(1),1.0,False)+","+NumToStr(GetCursorYPosition(1),1.0,False);
}
StaticVarSet("ON_color", ON_color);
}
if (IsNull(StaticVarGet("C1_X")))
{
PanelXoffset =5;
StaticVarSet("ON_color", colorGrey50);
}
else
{
PanelXoffset =pxW-StaticVarGet("C1_X");
if (PanelXoffset <10)
{
PanelXoffset =10;
}
}
if (IsNull(StaticVarGet("C1_Y")))
{
PanelYoffset =5;// Param("Button Row Offset (px)",60,0,600,1);
StaticVarSet("ON_color", colorGrey50);
}
else
{
PanelYoffset =pxH-StaticVarGet("C1_Y");
if (PanelYoffset<5)
{
PanelYoffset =5;
}
}
ButtonHeight=ButtonHeight1;
ButtonWidth=ButtonWidth1;
FontRatio=FontRatio1;
If(C>O)
{
colorTX_B=colorGold;
colorTX_T=colorDarkRed;
}
else
{
colorTX_B=colorTeal;
colorTX_T=colorDarkGreen;
}
If(TIckerC>TIckerO)
{
colorTicker_B=colorPink;
colorTicker_T=colorDarkRed;
}
else
{
colorTicker_B=colorPaleGreen;
colorTicker_T=colorDarkGreen;
}
If(C-TIckerC>0)
{
colorD=colorDarkRed;
}
else
{
colorD=colorDarkGreen;
}
ButtonColumnBegin("1", "微軟正黑體", FontRatio, ButtonHeight) ;
ButtonHeader( "游標價格", colorDarkGreen, colorBrown,colorYellow);
C102=ButtonTrigger("@ "+NumToStr(PanelXoffset,1.0,False)+","+NumToStr(PanelYoffset,1.0,False),ON_color, colorWhite , colorBlue);
TXONSwitch=ButtonTrigger(StaticVarGetText("TXON_Text"), colorTX_B,colorSkyblue ,colorTX_T);
TIckerONSwitch = ButtonTrigger( StaticVarGetText("TIckerON_Text"), colorTicker_B, colorSkyblue, colorTicker_T);
ButtonText( "價差="+NumToStr(C-TIckerC,1.0,False), colorLightYellow,colorD);
ButtonColumnEnd(ButtonWidth1);
ClickCoordinates = Nz(StaticVarGet("ClickCoordinates"));
switch( ClickCoordinates )
{
case 101:
Say( "Price at cursor");
//StaticVarSet("C2_X", pxW-(PanelXoffset+ButtonWidth1*2));
//StaticVarSet("C2_Y", pxH-PanelYoffset);
//
//StaticVarSet("C3_X", pxW-(PanelXoffset+ButtonWidth1*3));
//StaticVarSet("C3_Y", pxH-PanelYoffset);
break;
case 102:
if (C102)
{
if (StaticVarGet("XON"))
{
StaticVarSet("XON", 0);
Say( "C 1 Position Set");
}
else
{
StaticVarSet("XON", 1);
}
}
break;
case 103:
if (TXONSwitch && StaticVarGet("TXON"))
{
StaticVarSet("TXON", 0);
StaticVarSetText("TXON_Text",Name()+" K關 ") ;
}
else
{
StaticVarSet("TXON", 1);
StaticVarSetText("TXON_Text",Name()+"="+NumToStr(C,1.0,False));
}
Say(NumTostr(C,1.0,False));
break;
case 104:
if (TIckerONSwitch && StaticVarGet("TIckerON"))
{
StaticVarSet("TIckerON", 0);
StaticVarSetText("TIckerON_Text",Ticker+" K關 ") ;
}
else
{
StaticVarSet("TIckerON", 1);
StaticVarSetText("TIckerON_Text",Ticker+"="+NumToStr(TIckerC,1.1,false));
}
Say(NumTostr(TIckerC,1.0,False));
break;
}
_SECTION_END(); // End of C1
_SECTION_BEGIN("C2");
ButtonHeight2 = Param("C2 Button Height",20,5,200,1);
ButtonWidth2 = Param("C2 Button Width",120,5,200,1);
FontRatio2 = Param("C2 Font: ButtonHeight ratio",2,0.5,5,0.1);
// Column Position Setting
PanelXoffset =pxW-15;
PanelYoffset =5;
ON2_color=StaticVarGet("ON2_color");
if (StaticVarGet("XON2"))
{
Say( "C 2 Position");
if (ON2_color == colorPaleGreen)
{
ON2_color= colorPink;
}
else
{
ON2_color= colorPaleGreen;
}
XL2ButtonDown = GetCursorMouseButtons() == 9;
if( XL2ButtonDown )
{
StaticVarSet("C2_X", pxW-GetCursorXPosition(1));
StaticVarSet("C2_Y", pxH-GetCursorYPosition(1));
StaticVarSet("XON2", 0);
Say( "C 2 Position Set");
ON2_color= colorWhite;
//PositionStr="@ "+NumToStr(GetCursorXPosition(1),1.0,False)+","+NumToStr(GetCursorYPosition(1),1.0,False);
}
StaticVarSet("ON2_color", ON2_color);
}
if (IsNull(StaticVarGet("C2_X")))
{
PanelXoffset =ButtonWidth1;
StaticVarSet("ON2_color", colorGrey50);
}
else
{
PanelXoffset =pxW-StaticVarGet("C2_X")-ButtonWidth2;
if (PanelXoffset <10)
{
PanelXoffset =10;
}
}
if (IsNull(StaticVarGet("C2_Y")))
{
PanelYoffset =ButtonHeight1;// Param("Button Row Offset (px)",60,0,600,1);
StaticVarSet("ON2_color", colorGrey50);
}
else
{
PanelYoffset =pxH-StaticVarGet("C2_Y");
if (PanelYoffset<5)
{
PanelYoffset =5;
}
}
ButtonHeight=ButtonHeight2;
ButtonWidth=ButtonWidth2;
FontRatio=FontRatio2;
ButtonColumnBegin("2", "微軟正黑體", FontRatio, ButtonHeight) ;
ButtonHeader(Name()+" 高低價格", colorDarkGreen, colorBrown,colorYellow);
C202=ButtonTrigger("@ "+NumToStr(PanelXoffset+ButtonWidth2,1.0,False)+","+NumToStr(PanelYoffset,1.0,False),ON2_color, colorWhite , colorBlue);
ButtonText( "昨高 "+NumToStr(YesTH,1.0,False), colorPink, colorDarkRed);
ButtonText( "昨低 "+NumToStr(YesTL,1.0,False), colorPaleGreen, colorDarkGreen);
ButtonText( "今高 "+NumToStr(TodayH,1.0,False), colorPink, colorDarkRed);
ButtonText( "今低 "+NumToStr(TodayL,1.0,False), colorPaleGreen, colorDarkGreen);
ButtonColumnEnd(ButtonWidth2);
ClickCoordinates = Nz(StaticVarGet("ClickCoordinates"));
switch( ClickCoordinates )
{
case 201:
Say( "NAME");
break;
case 202:
if (C202)
{
if (StaticVarGet("XON2"))
{
StaticVarSet("XON2", 0);
Say( "C 2 Position Set");
}
else
{
StaticVarSet("XON2", 1);
}
}
break;
}
_SECTION_END(); // End of C2
_SECTION_BEGIN("C3");
ButtonHeight3 = Param("C3 Button Height",20,5,200,1);
ButtonWidth3 = Param("C3 Button Width",120,5,200,1);
FontRatio3 = Param("C3 Font: ButtonHeight ratio",2,0.5,5,0.1);
// Column Position Setting
PanelXoffset =pxW-10;
PanelYoffset =5;
ON3_color=StaticVarGet("ON3_color");
if (StaticVarGet("XON3"))
{
Say( "C 3 Position");
if (ON3_color == colorPaleGreen)
{
ON3_color= colorPink;
}
else
{
ON3_color= colorPaleGreen;
}
XL3ButtonDown = GetCursorMouseButtons() == 9;
if( XL3ButtonDown )
{
StaticVarSet("C3_X", pxW-GetCursorXPosition(1));
StaticVarSet("C3_Y", pxH-GetCursorYPosition(1));
StaticVarSet("XON3", 0);
Say( "C 3 Position Set");
ON3_color= colorWhite;
}
StaticVarSet("ON3_color", ON3_color);
}
if (IsNull(StaticVarGet("C3_X")))
{
PanelXoffset =ButtonWidth1+ButtonWidth2;
StaticVarSet("ON3_color", colorGrey50);
}
else
{
PanelXoffset =pxW-StaticVarGet("C3_X")-ButtonWidth3*2;
if (PanelXoffset <10)
{
PanelXoffset =10;
}
}
if (IsNull(StaticVarGet("C3_Y")))
{
PanelYoffset =ButtonHeight1+ButtonHeight2;// Param("Button Row Offset (px)",60,0,600,1);
StaticVarSet("ON3_color", colorGrey50);
}
else
{
PanelYoffset =pxH-StaticVarGet("C3_Y");
if (PanelYoffset<5)
{
PanelYoffset =5;
}
}
ButtonHeight=ButtonHeight3;
ButtonWidth=ButtonWidth3;
FontRatio=FontRatio3;
ButtonColumnBegin("3", "微軟正黑體", FontRatio, ButtonHeight) ;
ButtonHeader(Ticker+" 高低價格", colorDarkGreen, colorBrown,colorYellow);
C302=ButtonTrigger("@ "+NumToStr(PanelXoffset+ButtonWidth3*2,1.0,False)+","+NumToStr(PanelYoffset,1.0,False),ON3_color, colorWhite , colorBlue);
ButtonText( "昨高 "+NumToStr(TYesTH,1.0,False), colorPink, colorDarkRed);
ButtonText( "昨低 "+NumToStr(TYesTL,1.0,False), colorPaleGreen, colorDarkGreen);
ButtonText( "今高 "+NumToStr(TTodayH,1.0,False), colorPink, colorDarkRed);
ButtonText( "今低 "+NumToStr(TTodayL,1.0,False), colorPaleGreen, colorDarkGreen);
ButtonColumnEnd(ButtonWidth3);
ClickCoordinates = Nz(StaticVarGet("ClickCoordinates"));
switch(ClickCoordinates)
{
case 301:
Say( "Ticker");
break;
case 302:
if (C302)
{
if (StaticVarGet("XON3"))
{
StaticVarSet("XON3", 0);
Say( "C 3 Position Set");
}
else
{
StaticVarSet("XON3", 1);
}
}
break;
}
_SECTION_END(); // End of C3
//title=PositionStr;
ControlPanelInclude-003c.afl 要放置於\Formulas\Include 下
// ControlPanelInclude-003c.afl
procedure kStaticVarSet(SName,SValue)
{
ChartID = GetChartID();
InIndicator = Status("Action") == 1;
if( InIndicator ) StaticVarSet(Sname+ChartID, Svalue);
}
function kStaticVarGet(SName)
{
ChartID = GetChartID();
Var = StaticVarGet(Sname+ChartID);
return Var;
}
procedure kStaticVarSetText(SName,SValue)
{
ChartID = GetChartID();
InIndicator = Status("Action") == 1;
if( InIndicator ) StaticVarSetText(Sname+ChartID, Svalue);
}
function kStaticVarGetText(SName)
{
ChartID = GetChartID();
return StaticVarGetText(Sname+ChartID);
}
function NewColumn()
{
VarSet("ColNumber", 0);
}
function GetMouseClick(ColNumber, RowNumber)
{
global PanelYoffset, PanelXoffset, ButtonHeight, ButtonWidth;
LButtonDown = GetCursorMouseButtons() == 9;
Click = 0;
if( LButtonDown )
{
TotalW=0;
for(Col=0;Col<ColNumber;col++)
{
TotalW= Nz(kStaticVarGet("W"+Col))+TotalW;
}
W=Nz(kStaticVarGet("W"+ColNumber));
ULButtonX = PanelXoffset + TotalW;
LRButtonX = ULButtonX + W;
//ULButtonX = PanelXoffset + (ColNumber-1) * ButtonWidth;
//LRButtonX = ULButtonX + ButtonWidth;
ULButtonY = (RowNumber -1) * ButtonHeight + PanelYoffset;
LRButtonY = ULButtonY + ButtonHeight;
MouseCoord = Nz(StaticVarGet("ClickCoordinates"));
if( MouseCoord == 0 AND LButtonDown )
{
MousePx = GetCursorXPosition( 1 );
MousePy = GetCursorYPosition( 1 );
if( MousePx > ULButtonX AND MousePx < LRButtonX AND MousePy > ULButtonY AND MousePy < LRButtonY )
{
StaticVarSet("ClickCoordinates",ColNumber*100+RowNumber);
Click = 1;
}
}
}
return Click;
}
function ButtonColumnBegin(ColName, FoneType, FontRatio, ButtonHeight)
{
//global ;
global ColNumber,ColName;
ColNumber = VarGet("ColNumber");
if( IsEmpty(ColNumber) )
{
VarSet("ColNumber",1);
StaticVarSet("ClickCoordinates",0);
}
else VarSet("ColNumber", ++ColNumber);
ColName = ColName+GetChartID();
kStaticVarSet("RowNumber"+ColName, 0);
VarSetText("ColName",ColName);
GfxSetOverlayMode( 0 );
//GfxSelectFont( "Tahoma", ButtonHeight/FontRatio, 800 );
GfxSelectFont( FoneType, ButtonHeight/FontRatio,700 );
GfxSelectPen( colorBlack );
GfxSetBkMode( 1 );
}
function ButtonText( TextButton, backColor, TextColor)
{
global ColNumber, RowNumber, Colname;
ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
if( ColExpanded )
{
ColName = VarGetText("ColName");
RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
kStaticVarSet("RowNumber"+ColName, RowNumber);
kStaticVarSetText("TextButton"+ColName+RowNumber, TextButton);
kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
}
}
function ButtonHeader( Label, backColor1, BackColor2, TextColor)
{
global ColNumber, RowNumber, ColExpanded, Colname;
RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
kStaticVarSet("RowNumber"+ColName, RowNumber);
Trigger = GetMouseClick( ColNumber, RowNumber );
if( Trigger )
{
ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
if(ColExpanded)
{
BackColor = backColor2;
kStaticVarSet(ColName+"ColExpanded", False);
}
else
{
BackColor = backColor1;
kStaticVarSet(ColName+"ColExpanded", True);
}
}
else
{
if(Nz(kStaticVarGet(ColName+"ColExpanded")))
{
BackColor = backColor2;
}
else
{
BackColor = backColor1;
}
}
ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
kStaticVarSetText("TextButton"+ColName+RowNumber, Label);
kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
}
function ButtonTrigger(Label, backColor1, BackColor2, TextColor)
{
global ColNumber, RowNumber, ColName;
ColExpanded = Nz(kStaticVarGet(ColName+"ColExpanded"));
if( ColExpanded )
{
ColName = VarGetText("ColName");
RowNumber = Nz(kStaticVarGet("RowNumber"+ColName))+1;
kStaticVarSet("RowNumber"+ColName, RowNumber);
Trigger = GetMouseClick( ColNumber, RowNumber );
if( Trigger )
{
BackColor = backColor2;
}
else
{
BackColor = backColor1;
}
kStaticVarSetText("TextButton"+ColName+RowNumber, Label);
kStaticVarSet("TextColor"+ColName+RowNumber, TextColor);
kStaticVarSet("BackColor"+ColName+RowNumber, backColor);
}
else Trigger = 0;
return Trigger;
}
// Final drawing of the column
function ButtonColumnEnd(W)
{
global ButtonHeight, PanelYoffset, PanelXoffset, ColNumber, RowNumber, ColName;//, ButtonWidth
ChartIDStr = NumToStr(GetChartID(),1.0,False);
TotalW=0;
for(Col=0;Col<ColNumber;col++)
{
TotalW= Nz(kStaticVarGet("W"+Col))+TotalW;
}
ULButtonX = PanelXoffset + TotalW;
kStaticVarSet("W"+ColNumber, W);
LRButtonX = ULButtonX + W;
//ULButtonX = PanelXoffset + (ColNumber-1) * ButtonWidth;
//LRButtonX = ULButtonX + ButtonWidth;
for( Row = 1; Row <= RowNumber; Row++ )
{
ULButtonY = (Row-1) * ButtonHeight + PanelYoffset;
LRButtonY = ULButtonY + ButtonHeight;
Label = kStaticVarGetText("TextButton"+ColName+Row);
TextColor = Nz(kStaticVarGet("TextColor"+ColName+Row));
BackColor = Nz(kStaticVarGet("BackColor"+ColName+Row));
//GfxSelectSolidBrush( BackColor);
//GfxRectangle(ULButtonX, ULButtonY, LRButtonX, LRButtonY );
//GfxSetBkColor( BackColor);
GfxGradientRect(ULButtonX, ULButtonY, LRButtonX, LRButtonY,colorBlend(BackColor, colorWhite,0.1), colorBlend(BackColor, colorBlack,0.3));
GfxSetTextColor( TextColor );
//GfxSelectFont( "微軟正黑體", abs(ULButtonY-LRButtonY)/FontRatio,700 );
GfxDrawText( Label, ULButtonX, ULButtonY, LRButtonX, LRButtonY, 32 | 1 | 4);
}
}
欄位移動 要先按 @x,y 列
之後按要移動的位置
謝謝分享
請問要怎麼弄才不會亂碼? 大大寫 AFL 的功力真的是很讚~
有機會再多跟您請教一下 CalvinHornG
there is one error in your code
ReplaceTicker = ParamStr("Symbol","TSEIDX");
TIckerO = Foreign(Ticker, "O");
TIckerH = Foreign(Ticker, "H");
TIckerL = Foreign(Ticker, "L");
TIckerC = Foreign(Ticker, "C");
TYesTH =TimeFrameGetPrice("TickerH",inDaily,-1);
TYesTL =TimeFrameGetPrice("TickerL",inDaily,-1);
TTodayH=TimeFrameGetPrice("TickerH",inDaily,0);
TTodayL=TimeFrameGetPrice("TickerL",inDaily,0);
TTodayO=TimeFrameGetPrice("TickerO",inDaily,0);with Ticker = ParamStr( "Symbol", "TSEIDX" );
SetForeign(Ticker);
TIckerO = O;
TIckerH = H;
TIckerL = L;
TIckerC = C;
TYesTH = TimeFrameGetPrice( "H", inDaily, -1 );
TYesTL = TimeFrameGetPrice( "L", inDaily, -1 );
TTodayH = TimeFrameGetPrice( "H", inDaily, 0 );
TTodayL = TimeFrameGetPrice( "L", inDaily, 0 );
TTodayO = TimeFrameGetPrice( "O", inDaily, 0 );
RestorePriceArrays(); joshsmi 發表於 13-3-23 04:59 static/image/common/back.gif
CalvinHornG
there is one error in your code
THANK YOU VERY MUCH
YES YOU ARE RIGHT
I JUST FOCUS ON THE TEXT 非常不錯的程式,很實用,可以用來學習及看盤,版大的程式功力很強,以後要多向大版請益!! 感謝分享
盡力學習中 感謝版主的分享,謝謝{:4_113:}
頁:
[1]