請問,編譯沒問題,為何主圖疊圖上,沒辦法顯示出進場訊號
是不是有哪邊沒注意到
input: FastLength(12), SlowLength(26), MACDLength(9); //定義MACD指標變數
input: BBandLength(20), UpperBand(2), LowerBand(2); //定義布林通道
input: KDLength(9), RSVt(3), Kt(3); //定義KD指標
variable: price(0);
variable: rsv(0), k(0), _d(0); //定義KD變數
variable: intrabarpersist position(0); // 目前位置
variable: intrabarpersist entry_price(0); // 最後一次進場的價格
SetInputName(1, "DIF短天數");
SetInputName(2, "DIF長天數");
SetInputName(3, "MACD天數");
SetInputName(4, "布林天數");
SetInputName(5, "上軌倍數");
SetInputName(6, "下軌倍數");
SetInputName(7, "KD天數");
SetInputName(8, "RSVt權數");
SetInputName(9, "Kt權數");
price = WeightedClose();
Value1 = XAverage(price, FastLength) - XAverage(price, SlowLength); //DIF線
Value2 = XAverage(Value1, MACDLength) ; //MACD線
Value3 = Value1 - Value2 ; //Osc柱狀體
if CurrentBar <= SlowLength then
begin
Value1 = 0;
Value2 = 0;
Value3 = 0;
end;
//計算布林上下通道的帶寬大小,帶寬小於20的不考慮
Value4 = bollingerband(Close, BBandLength, UpperBand) - bollingerband(Close, BBandLength, LowerBand);
//計算KD
Stochastic(KDLength, RSVt, Kt, rsv, k, _d);
condition1 = Value3 > 0 and Value3[1] < 0; //MACD出現第一根紅兵
condition2 = k > k[1]; //K線持續向上
if position = 0 then
begin
if condition1 and condition2 and Value4 > 20 then //進場邏輯,MACD出現第一根紅兵,K線持續向上,布林上下通道帶寬>20
begin
position = 1;
entry_price = close;
print("(ENTRY) Date:", Date, " EntryPrice:", entry_price);
plot1(low * 0.98, "entry");
end;
end;

1 評論