MC如何套用另一種K線
把原本k線收盤,最高,最低,開盤價做一改寫如下: xClose = (Open+High+Low+Close)/4 o Average price of the current bar xOpen = [xOpen(Previous Bar) + Close(Previous Bar)]/2 o Midpoint of the previous bar xHigh = Max(High, xOpen, xClose) o Highest value in the set xLow = Min(Low, xOpen, xClose) o Lowest value in the set
所以新的K線就以:xClose,xOpen,xHigh,xLow 這四個值就畫出
方式如下:
加入以下判斷,比較前幾根k線(這裡是6根)的open,close 做出顏色區分. upval=1; downval=2; if XClose > XOpen then Return = UpVal else Return = DownVal; for Index = 1 to 6 begin if XOpen <= MaxList(XOpen[Index],XClose[Index]) and XOpen >= MinList(XOpen[Index],XClose[Index]) and XClose <= MaxList(XOpen[Index],XClose[Index]) and XClose >= MinList(XOpen[Index],XClose[Index]) then Return = Return[Index]; end; 以前6根K線和目前OPEN ,CLOSE價格做比較,簡單來說就是看這6根一直往下還是一直向上, 介由return值去判斷現在是上升還是下降趨勢, 並標出顏色. if return = 1 and retur[1]= 1 then begin Color = red; end; if return = 2 and retur[1]= 2 then begin Color = green; end; if return <> retur[1] then begin Color = blue; end; 紅色代表上升,綠色為下降,藍色是轉變的開始.
以下貼上KAHUNA的ModHA2 Paint Bar的code和兩個內含的function......有TS2000的同好可以運用.有誰改寫成STRATEGY的記得分享一下
{ ModHA2 Paint Bar Study 4/10/04
Determines HA Colors for two (Min/Max) number of Compare bars and displays the Up Color (UpColor) if they aggree in the Up direction,displays the Down Color (DnColor) if they aggree in the Down direction, and displays the Warning Color if they do not agree. ............KAHUNA }
Inputs: UpColor(green), DnColor(red), WarnColor(yellow), MinCompBars(6), MaxCompBars(20), nPlotWidth(2);
Vars: haClose(0),haOpen(0),haMinDir(0),haMaxDir(0),Color(0);
{ Get HA Direction for Min/Max Compare Bars } haMinDir = fModHAKahuna(MinCompBars, haOpen, haClose); haMaxDir = fModHAKahuna(MaxCompBars, haOpen, haClose); { Load Display Color } if haMinDir = 1 and haMaxDir = 1 then begin Color = UpColor; end;
if haMinDir = 2 and haMaxDir = 2 then begin Color = DnColor;
end; if haMinDir <> haMaxDir then begin Color = WarnColor; end;
{ Paint Bar } PlotPB(haOpen,haClose, "ModHA2", Color); SetPlotWidth(1,nPlotWidth); SetPlotColor(1,color); -------------------------------------------------------------------------------------
FUNCTION:fModHAKahuna
{ ModHAValue Function - 4/10/04
compares current bar open to close range with prior bars...if current is within prior then Up/Down value remains the same}
Inputs: CompBars(numericsimple), oOpenVal(numericref), {Output: HA Open Price} oCloseVal(numericref) {Output: HA Close Price};
Vars: haClose(0), haOpen(0), haHigh(0), haLow(0), Index(0), UpVal(1), {Constant: Up haDir value} DownVal(2), {Constant: Down haDir value} Return(0);
if BarNumber = 1 then begin haOpen = open; haClose = (O+H+L+C)/4; haHigh = MaxList( high, haOpen, haClose); haLow = MinList( low, haOpen, haClose); end else {BarNumber > 1 } begin haClose = (O+H+L+C)/4; haOpen = (haOpen[1] + haClose[1])/2 ; haHigh = MaxList(High, haOpen, haClose) ; haLow = MinList(Low, haOpen, haClose) ; if haClose > haOpen then Return = UpVal else Return = DownVal; for Index = 1 to CompBars begin if haOpen <= MaxList(haOpen[Index],haClose[Index]) and haOpen >= MinList(haOpen[Index],haClose[Index]) and haClose <= MaxList(haOpen[Index],haClose[Index]) and haClose >= MinList(haOpen[Index],haClose[Index]) then Return = Return[Index]; end;
end;
{Load Output Values} oOpenVal = haOpen; oCloseVal = haClose; fModHAKahuna = Return; ----------------------------------------------------------------------------------