請協助我寫出這個盤中指標,

  •   407 
  • 最後發表   neverdie62  2025 三月 06
neverdie62 發文於   2025/02/27

settotalBar(100);

variable:BBI(0),intrabarPersist _entry(0),intrabarPersist _priceentry(0),intrabarPersist _pricequitw(0),intrabarPersist _pricequitl(0);

BBI=(average(close,3)+average(close,6)+average(close,12)+average(close,24))/4;

 

condition1=getfield("close","tick")<=BBI+3 and getfield("close","tick")>=BBI-3;//多單進場

condition2=_entry=1 and getfield("close","tick")>=_pricequitw;//多單賺出場

condition3=_entry=1 and getfield("close","tick")<=_pricequitl;//多單賠出場

 

_entry=0;

_priceentry=0;

_pricequitw=0;

_pricequitl=0;

 

plot1(BBI,"BBI",checkbox:=1);

 

  if condition1 and _entry=0 then begin

  _entry=1;

  _priceentry=getfield("close","tick");

  _pricequitw=_priceentry+3;

  _pricequitl=_priceentry-3;

  plot2(_priceentry,"B",checkbox:=1); 

 

  if condition2 then begin 

    _entry=0;

    plot3(_pricequitw,"W",checkbox:=1);noplot(4);noplot(5);

    end;

  if condition3 then begin 

    _entry=0;

    plot4(_pricequitl,"L",checkbox:=1);noplot(3);noplot(5);

    end;

  if not condition2 and not condition3 then begin 

    _entry=1;

    plot5(_priceentry,"K",checkbox:=1);noplot(3);noplot(4);

    end;

  end; 

    我想寫一個盤中觀察的指標,BBI均線附近3點以內買進一口,買進時在k棒下方出現”B”符號,當盤中tick價格往上達3點獲利離場就在K棒上方出現”$”符號,當盤中tick價格往下達3點停損離場就在K棒上方出現”X”符號,而如果此根K棒時間過去沒觸及獲利停損,k棒上方出現閃電符號,然後在往後的k棒若能獲利出場就在上方出現”$”符號,若停損出場就在上方出現”X”符號,過程中一律是一口出場後才進下一口,請問如何寫才能達成這樣的盤中觀察指標?附上影片可見程式跑得不如預期

 

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/02/27

(1)若你能提供正確的圖長得怎麼樣(可在你微型台指近月的分析圖表上手動繪製),對於解決問題可能會比較有幫助。

(2)請確認,condition1成立的情況下,condition2及condition3有沒有可能也成立?若沒辦法3個condition都成立,則你的if結構需要修改。

 

 

neverdie62 發文於   2025/02/28

我有影片說明想傳改您,可以加我的賴嗎?我的ID: neverdie0704,謝謝

虎科大許教授 發文於   2025/02/28

請寄到 phsu@gs.nfu.edu.tw

neverdie62 發文於   2025/02/28

有發 mail了,請指教,謝謝

 

虎科大許教授 發文於   2025/02/28

你的程式問題蠻多的,第一個很明顯的問題就是在每個Tick洗價時,你讓_entry、_priceentry、_pricequitw、_pricequitl這些變數都歸零。這造成你原本打算用這些變數控制流程的目的無法達成。建議在每天第一次洗價才歸零。例如:

if isFirstCall("Date") then

begin 

_entry=0;

_priceentry=0;

_pricequitw=0;

_pricequitl=0;

 

end;

後續就在每個IF裡面控制這些變數。

condition2及condition3應該寫在B繪製完成且下一個IF之前。

neverdie62 發文於   2025/03/03

改成這樣對嗎?跑起來完全任何訊號都沒有....?

settotalBar(100);

variable:BBI(0),intrabarPersist _entry(0),intrabarPersist _priceentry(0),intrabarPersist _pricequitw(0),intrabarPersist _pricequitl(0);

BBI=(average(close,3)+average(close,6)+average(close,12)+average(close,24))/4;

 condition1=getfield("close","tick")<=BBI+3 and getfield("close","tick")>=BBI-3;//多單進場

 if isFirstCall("Date") then begin

_entry=0;

_priceentry=0;

_pricequitw=0;

_pricequitl=0;

end;

 

plot1(BBI,"BBI",checkbox:=1);

 

 

  if condition1 and _entry=0 then begin

  _entry=1;

  _priceentry=getfield("close","tick");

  _pricequitw=_priceentry+3;

  _pricequitl=_priceentry-3;

  plot2(_priceentry,"B",checkbox:=1);

 condition2=_entry=1 and getfield("close","tick")>=_pricequitw;//多單賺出場

 condition3=_entry=1 and getfield("close","tick")<=_pricequitl;//多單賠出場

  if condition2 then begin

    _entry=0;

    plot3(_pricequitw,"W",checkbox:=1);noplot(4);noplot(5);

    end;

  if condition3 then begin

    _entry=0;

    plot4(_pricequitl,"L",checkbox:=1);noplot(3);noplot(5);

    end;

  if not condition2 and not condition3 and _entry=1 then begin

    plot5(_priceentry,"K",checkbox:=1);noplot(3);noplot(4);

    end;

  end;

虎科大許教授 發文於   2025/03/03

若要同時解決即時的問題(B會一下子出現一下子消失),還需要用其他變數控制,這部份你自己琢磨。就以下面的程式當作基礎去修改。

variable:BBI(0),intrabarPersist _entry(0),intrabarPersist _priceentry(0),intrabarPersist _pricequitw(0),intrabarPersist _pricequitl(0);
BBI=(average(close,3)+average(close,6)+average(close,12)+average(close,24))/4;
condition1=getfield("close","tick")<=BBI+3 and getfield("close","tick")>=BBI-3;//多單進場
if isFirstCall("Date") then 
    begin
        _entry=0;
        _priceentry=0;
        _pricequitw=0;
        _pricequitl=0;
    end;
plot1(BBI,"BBI",checkbox:=1);
if _entry=0 then
    begin
        if condition1 then 
            begin
                _entry=1;
                _priceentry=getfield("close","tick");
                _pricequitw=_priceentry+3;
                _pricequitl=_priceentry-3;
                plot2(_priceentry,"B",checkbox:=1);
            end;
    end
else
    begin
        condition2=getfield("close","tick")>=_pricequitw;//多單賺出場
        condition3=getfield("close","tick")<=_pricequitl;//多單賠出場
        if condition2 then 
            begin
                _entry=0;
                plot3(_pricequitw,"W",checkbox:=1);noplot(4);noplot(5);
            end;
        if condition3 then 
            begin
                _entry=0;
                plot4(_pricequitl,"L",checkbox:=1);noplot(3);noplot(5);
            end;
        if not condition2 and not condition3 then 
            begin
                plot5(_priceentry,"K",checkbox:=1);noplot(3);noplot(4);
            end;
    end;

XS小編 發文於   2025/03/06

Hello neverdie62,

 

小編補充,請注意在指標腳本上使用 SetTotalBar 會限制能夠畫出的範圍。

SetTotalBar(100); 代表該腳本在初始運作時只會計算近100根K棒 (後來增加的K棒不在此內)。

發表回覆
Close