Volume 函數問題

  •   200 
  • 最後發表   Tommy9205  2024 四月 03
Tommy9205 發文於   2024/03/24

你好:

//MA5 五日均線以及//OBV雙線指標 兩個語法單獨使用 都顯示正常,設置的條件顯示的圖示都符合語法結果。

但是只要把兩個程式合併一起使用,設置的條件顯示出來的結果與語法結果不符,似乎是共用volume函數造成的。

請幫忙指正謝謝

 

//MA5 五日均線

value1 = average(getfield("Volume", "D"), 5);

 

plot1(value1, "5日平均成交量");

//OBV雙線指標

 

input: obvMALen(30, "OBV平均線期數");

 

variable: obvolume(0), obvSMA(0), obvSMA_Str(""), obvMMA(0), obvMMA_Str("");

 

 

if CurrentBar = 1 then

obvolume = 0

else

  begin

if close > close[1] then

obvolume = obvolume[1] + volume

else

  begin

if close < close[1] then

obvolume = obvolume[1] - volume

else

obvolume = obvolume[1];

  end;

  end;

obvMMA = average(obvolume,obvMALen);

condition1= obvolume-obvMMA>0;

if condition1 and condition50 then plot1(low,"OBV");

condition50= volume >value1;

XQ小幫手 發文於   2024/04/03

Hello, Tommy9205.

小幫手發現您的CODE有兩個問題,1. 共用了plot1(...),2. condition50賦值的位置,在判斷是之後,

 

所以小幫手將您的程式修改如下:

//MA5 五日均線
value1 = average(getfield("Volume", "D"), 5);

plot1(value1, "5日平均成交量");


//OBV雙線指標
input: obvMALen(30, "OBV平均線期數");

variable: obvolume(0), obvSMA(0), obvSMA_Str(""), obvMMA(0), obvMMA_Str("");


if 
    CurrentBar = 1 
then
    obvolume = 0
else begin
    if 
        close > close[1] 
    then
        obvolume = obvolume[1] + volume
    else begin
        if 
            close < close[1] 
        then
            obvolume = obvolume[1] - volume
        else
            obvolume = obvolume[1];
    end;
end;

obvMMA = average(obvolume,obvMALen);

condition1 = obvolume - obvMMA > 0;

condition50 = volume > value1;

if 
    condition1 
    and condition50 
then 
    plot2(low,"OBV");

1712132024408

再麻煩您確認下是不是您想要呈現的,

 

謝謝。

發表回覆
Close