2015年12月9日 星期三

MultiCharts : 在K線圖上顯示文字及數字

想在MultiCharts的K線上顯示數字或文字,可以參考下面做法,筆者這裡先介紹MultiCharts內建顯示函數text_new、numtostr,後續再介紹其他設定文字的函數,各位讀者可以參考看看。
text_new的用法。
text_new([日期], [時間], [價格], [文字內容]);
第一個參數:日期。
第二個參數:時間或想成是X軸的位置。
第三個參數:價格或想成是Y軸的位置。
第四個參數:文字內容。

numtostr的用法。
numtostr([數字], [小數位數]);
第一個參數:數字。
第二個參數:小數位數。

結合上面兩個函數。
variables:vNo(0), vMP(0), vDis(13);
vMP = marketposition;
if vMP[1] = -1 and vMP = 0 then
 vNo = text_new(D, T, l-vDis, numtostr(exitprice(1), 0))
else if vMP[1] = 1 and vMP = 0 then
 vNo = text_new(D, T, l-vDis, numtostr(exitprice(1), 0))
else if vMP[1] = 0 and vMP = -1 then
 vNo = text_new(D, T, h+vDis, numtostr(Entryprice, 0))
else if vMP[1] = 0 and vMP = 1 then
 vNo = text_new(D, T, h+vDis, numtostr(Entryprice, 0));

將程式碼改為精簡一點。
variables:vNo(0), vMP(0), vDis(13);
vMP = marketposition;
if (vMP[1] = -1 or vMP[1] = 1 ) and vMP = 0 then
 vNo = text_new(D, T, l-vDis, numtostr(exitprice(1), 0))
else if vMP[1] = 0 and (vMP = -1 or vMP = 1) then
 vNo = text_new(D, T, h+vDis, numtostr(Entryprice, 0));

換個寫法。
variables:vNo(0), vMP(0), vDis(13);
vMP = marketposition;
if (vMP[1] = -1 or vMP[1] = 1 ) and vMP = 0 then begin
 vNo = text_new(D, T, l-vDis, numtostr(exitprice(1), 0));
end
else if vMP[1] = 0 and (vMP = -1 or vMP = 1) then begin
 vNo = text_new(D, T, h+vDis, numtostr(Entryprice, 0));
end;

執行畫面

參考資料