1.如果庫存已經有一張A股票60元,
例如:當A股票高於62(獲利設定值)以上則賣出,等回跌60元(獲利設定值)以下時再買進,再漲回62再賣出,
重複連續多次來回交易的語法?
2.無庫存有足夠的B股票資金10萬
例如:B股70一開盤就買進、當價格高於開盤價有(獲利設定值)時就賣出,再跌回有價差(獲利設定值)時再買進,
重複連續多次來回交易的語法?
        
        1.如果庫存已經有一張A股票60元,
例如:當A股票高於62(獲利設定值)以上則賣出,等回跌60元(獲利設定值)以下時再買進,再漲回62再賣出,
重複連續多次來回交易的語法?
2.無庫存有足夠的B股票資金10萬
例如:B股70一開盤就買進、當價格高於開盤價有(獲利設定值)時就賣出,再跌回有價差(獲利設定值)時再買進,
重複連續多次來回交易的語法?
Hello xqyi,
網站上有教學區,裡面有XS語法的基礎和應用可以閱覽。
您可以在腳本中設定一個上限跟下限,當價格跌到下限時買入,漲到上限時賣出。
舉例來說:
input: upLimit(62), lowLimit(60);
if close <= lowLimit and filled = 0 and position = 0 then setposition(1, market);
if close >= upLimit and filled = 1 and position = 1 then setposition(0, market);
上面的範例就會在價格小於等於 lowLimit 且部位庫存為0的時候買進1張,並在價格大於等於 upLimit 且部位庫存為1的時候平倉。
以下當沖用,S/B腳本的三種狀況,交易語法是否正確?
S腳本先賣1.2
//1.無庫存先融卷再回補
if condition2 or condition3 and filled = 0 and position = 0
then setposition(-1);//無庫存0時 低於設定價先賣1張
if q_Bid <=FILLedAvgPrice*0.99 and filled = -1 and position = -1
then setposition(0);//融卷庫存1時低於賣出價*0.99時平倉卷補
//2.有庫存先賣再買
if condition2 or condition3 and filled = 1 and position = 1
then setposition(0);//有庫存時低於設定價平倉先賣
if q_Bid <=FILLedAvgPrice*0.99 and filled = 0 and position = 0
then setposition(1);//庫存0時賣出價跌0.99時買進
B腳本先買3.
//3.現股先買在賣
if condition1 or condition3 and filled = 0 and position = 0
then setposition(1);//庫存是空的先買
if q_Ask >=FilledAvgPrice*1.01 and filled = 1 and position = 1
then setposition(0);//買入價漲1.01時平倉賣掉
4. 腳本交易設定如下,無安控, B腳本只有買進無賣出 、S腳本只有賣出無買進 ?

Hello xqyi,
if q_Bid <=FILLedAvgPrice*0.99 and filled = 0 and position = 0 then setposition(1);
需注意當沒有部位和庫存時,成本 (filledavgprice) 會是0,故這行腳本是不會觸發的。
所以S腳本實際上可能會觸發的只有這三行:
if condition2 or condition3 and filled = 0 and position = 0
then setposition(-1);//無庫存0時 低於設定價先賣1張
if q_Bid <=FILLedAvgPrice*0.99 and filled = -1 and position = -1
then setposition(0);//融卷庫存1時低於賣出價*0.99時平倉卷補
if condition2 or condition3 and filled = 1 and position = 1
then setposition(0);//有庫存時低於設定價平倉先賣
其中最後一行需要在商品啟動策略時策略有庫存才會執行,例如策略部位設定為依庫存,而策略啟動時執行商品就已經有1張庫存。
每個策略啟動後的部位庫存是獨立的,所以S和B腳本是不會互相影響的。
建議您可以將相關數值 print 出來,可以比較容易理解策略運作狀況。
Q//2.有庫存先賣再買
if condition2 or condition3 and filled = 1 and position = 1
then setposition(0);//有庫存時低於設定價平倉先賣
if q_Bid <=FILLedAvgPrice*0.99 and filled = 0 and position = 0
then setposition(1);//庫存0時賣出價跌0.99時買進
A.
if q_Bid <=FILLedAvgPrice*0.99 and filled = 0 and position = 0 then setposition(1);
需注意當沒有部位和庫存時,成本 (filledavgprice) 會是0,故這行腳本是不會觸發的。
那該如何修改,才能買進比賣出價格低的價位?
Hello xqyi,
如果您要先賣出後再以賣出價來當作進場條件判斷的話,可以使用 FilledRecordPrice、FilledRecordBS 搭配 FilledRecordCount。
舉例來說:
if FilledRecordCount <> 0 and FilledRecordBS(FilledRecordCount) = -1 and q_big <= FilledRecordPrice(FilledRecordCount) * 0.99 and filled = 0 and position = 0 then setposition(1);
這樣就可以在前一筆交易是賣出的且符合賣出價跌0.99時再買進。
5 評論