求高手..幫忙

  •   147 
  • 最後發表   wei lon  2022 十一月 01
wei lon 發文於   2022/10/25

有沒有高手可以幫忙把這個自動交易(多單)邏輯改(空單)呢?

//下單數量

input: _quantity(1,"單次下單數量");

 

 

 

//--------------------------------------------

//規則

//--------------------------------------------

 

 

if close[3] > open[3] and close[2] > open[2] and close[1] < open[1] 

then begin

  condition1= true;

end;

 

 

 

//--------------------------------------------

//進出場

//--------------------------------------------

var: red_low(0); //進場紅K開盤價

var:red_low_time(0);

//多單

if position = 0 and Filled = 0 //and GetInfo("IsRealTime") = 1 

and condition1 = true

and close > open       

then begin

SetPosition( _quantity*1, MARKET,label:="多單進場") ;

red_low = open ;

red_low_time = time;

Print(file("C:\SysJust\XQLite\XS\Print\"),NumToStr(date,0),NumToStr(time,0),"《",SymbolName,"》","多單進場","成本",NumToStr(FilledAvgPrice,0),"部位",NumToStr(position,0),"filledfilled",filled);

print(file("C:\SysJust\XQLite\XS\Print\"),"時間:",NumToStr(time,0),"《",SymbolName,"》","進場紅K開盤價",red_low,"red_low_time",red_low_time);

end;

 

 

 

 

//--------------------------------------------

//停損

//--------------------------------------------

input: loss_out(1, "是否啟動自動停損", inputkind:= Dict(["是",1], ["否",0]));

 

//多單停損

if red_low > 0 

and position > 0  and  filled > 0

and close < red_low 

and  loss_out = 1

then begin

SetPosition( 0, market,label:="多單市價停損") ;

Print(file("C:\SysJust\XQLite\XS\Print\"),NumToStr(date,0),NumToStr(time,0),"《",SymbolName,"》","多單市價停損","成本",NumToStr(FilledAvgPrice,0),"filledfilled",filled);

//condition1= false ;

end;

 

//-------------------------------------------------

//變數歸0

//-------------------------------------------------

if filledAvgPrice = 0

then begin

condition1= false ;

//red_low = 0;

//red_low_time = 0;

end;

 

//-------------------------------------------------

//測試LOG

//-------------------------------------------------

 

{

print(date,time,condition1,"部位",NumToStr(position,0),"Filled",Filled,"red_low",red_low);

 

排序方式: 標準 | 最新
XQ小幫手 發文於   2022/10/26

 Hello wei lon,

 

if close[3] > open[3] and close[2] > open[2] and close[1] < open[1] 

then begin

  condition1= true;

end;

 

您這種寫法會讓條件符合後 condition1 就一直 True,如果不希望這樣的話可以寫為 condition1 = ...條件...;

 

另外您沒有提到空單邏輯該怎麼做,那麼最簡單的調整就是把條件相反過來。

condition1 = close[3] < open[3] and close[2] < open[2] and close[1] > open[1];

接著把進場的部分改為空方。

SetPosition( _quantity*-1, MARKET,label:="多單進場") ;

並將停損的部分作修改。

if red_low > 0 

and position < 0  and  filled < 0

and close > red_low 

and  loss_out = 1

then begin

 

網站上有教學區,裡面有XS語法的基礎和應用可以閱覽。

wei lon 發文於   2022/10/27

小幫手你好....我看了一下目前的規則

close[3] > open[3] and close[2] > open[2] and close[1] < open[1] 

如圖

 

請問一下規則那邊可以怎麼修改

另外我有附上空單邏輯了

XQ小幫手 發文於   2022/10/28

Hello wei lon,

 

如果您是要 紅K => N根綠K => 紅K 當作條件的話,那麼可以用變數來記錄。

舉例來說:

if value1 = 0 and close[1] > open[1] then value1 = 1;  //如果有紅棒 value1 就等於1

if value1 = 1 and close < open then value1 = 2;  //在value1 為1的狀況下,出現綠棒 value1 就等於2 

condition1 = close > open and value1 = 2;   //如果綠棒後出現紅棒,conditin1就為True

if condition1 then value1 = 0;  //當condition1 為 True時,重置value1。

這種寫法就會確保只要經過 紅 => 綠 => 紅 就會符合條件。

wei lon 發文於   2022/10/28

謝謝小幫手...我終於解決 紅 => 綠 => 紅的問題了...空單我也反向的改成 綠 => 紅 => 綠了

請問我上面程式進出場部分

我照你說得改成

SetPosition( _quantity*-1, MARKET,label:="多單進場") ;程式就先賣再買了..

解決所有問題了..謝謝你

XQ小幫手 發文於   2022/11/01

 Hello wei lon,

 

小幫手補充,您可以參考 setposition 的說明。

裡面有部位庫存是如何變化的,以及該函數是如何運作。

 

發表回覆
Close