請選擇 進入手機版 | 繼續訪問電腦版

程式交易,系統交易資源討論區~Beta

 找回密碼
 立即註冊
搜索
查看: 392|回復: 1

SQX策略導入multicharts上的bug,提供原廠修正參考

[複製鏈接]

1

主題

0

好友

17

積分

新手上路

Rank: 1

發表於 2019-1-28 06:17:05 |顯示全部樓層
本帖最後由 orville0203 於 2019-1-28 06:16 編輯

狀況說明:使用同條件產出的兩個策略,(strategy type 選項設為 : Multi_TF or multi_symbol strategy)
              在multicharts上相同環境設定作運行~

問題1:程式碼導出,data1和data2有對應上的問題~
         SQX 副圖的資料,程式導出用的是 xxx of data1.... ,在multicharts上會有對應上的問題~
問題2:同期產出的大多數程式編譯可通過,但圖表執行時發生錯誤:{例外}浮點運算除以0~
         這部份user在debug上很花時間,挖出SQ_的函數程式碼,找到有"/"的不多,
         兩策略用的函數大同小異,圖表資料環境又相同,修正起來蠻頭痛~
問題3:產出的策略移到multicharts運行,績效差異還是頗大~
         原本透過拉高滑價,來找出堪用的策略,但往往又造成交易次數過低,
         這部份期待原廠能加快修正的腳步,不然在multicharts用戶上,真是很大的瓶頸~
         
         

提供兩個同環境測試的例子(第一個通過,第二個運行時發生浮點運算除以0~)
資料源:data1 由multicharts匯出的5分K小台指
           data2 由multicharts匯出的1小時k小台指

策略一(已將 ...of data1 修改為  ...of data2,其他不動,可運行):

//==========================================================================
inputs:
    MagicNumber(11111),
    ExitAtEndOfDay(false),   
    ExitOnFriday(false),
    LimitSignalsTimeRange(false),
    SignalTimeRangeFrom(0850),
    SignalTimeRangeTo(1325),
    ExitAtEndOfRange(false),
    MaxTradesPerDay(10),
    MinimumSLPT(15),  // Minimum SL/PT in ticks/pips, 0 means unlimited
    MaximumSLPT(60),  // Maximum SL/PT in ticks/pips, 0 means unlimited
    mmLots(1.0),
    InitialCapital(30000000),
    CreatedBy("StrategyQuant X");  
vars:
     LongEntrySignal(false),
    ShortEntrySignal(false),
    LongExitSignal(false),
    ShortExitSignal(false),
    NumberOfShares(0),
    tickSize(MinMove/PriceScale),
    OpenOrdersAllowed(true),
    PriceLevel(0),SL(0), PT(0);
    Array: bool cond[100](false);
// =================================================================
OpenOrdersAllowed = true;
if(ExitAtEndOfDay) then
    SetExitOnClose;
if ExitOnFriday and DayOfWeek(Date) = 5 then
    SetExitOnClose;
// Limit time range
if(OpenOrdersAllowed = True and LimitSignalsTimeRange = True and (Time < SignalTimeRangeFrom or Time >= SignalTimeRangeTo)) then
    OpenOrdersAllowed = False;
// Max trades per day
if(OpenOrdersAllowed = True and MaxTradesPerDay <> 0 and EntriesToday(Date) >= MaxTradesPerDay) then
    OpenOrdersAllowed = False;   

LongEntrySignal = (SQ_IsRising(SQ_Lowest(Open, 111)[0], 4, true)[0] = 1)
    and ((SQ_Highest(TypicalPrice, 25)[1] of data2 < Close[1] of data2) and (SQ_Highest(TypicalPrice, 25)[0] of data2 > Close[0] of data2));
ShortEntrySignal = (SQ_IsFalling(SQ_Pivots(5, 54, 2)[0], 4, false)[0] = 1)
    and (SQ_ATR(50)[0] < SQ_ATR(127)[0])
    and (SQ_IsRising(Close[0], 3, true)[0] = 1)
    and (SQ_IsRising(SQ_ATR(23)[0] of data2, 3, true)[0] = 1)
    and (SQ_IsFalling(SQ_Lowest(WeightedClose of data2, 5)[0], 4, true)[0] = 1);

LongExitSignal = (SQ_Lowest(Close, 14)[0] < SQ_Pivots(0, 0, 2)[0])
    and (SQ_ATR(146)[0]>4.01)
    and (SQ_ATR(14)[0]>8.01)
    and (SQ_IsRising(SQ_Highest(WeightedClose, 3)[0] of data2, 4, true)[0] = 1)
    and (SQ_ATR(13)[1] of data2<SQ_ATR(13)[0] of data2)
    and (SQ_ATR(50)[0] of data2 > SQ_ATR(20)[0] of data2);
ShortExitSignal = false;

if LongEntrySignal
then begin
    // Action #1
    if(OpenOrdersAllowed) then begin
        NumberOfShares = mmLots;
        PriceLevel = Round2Fraction(SQ_Pivots(12, 37, 6)[0] + (1.80 * SQ_ATR(30)[0]));
        Buy("LongStop") NumberOfShares shares next bar at PriceLevel stop;
    end;
end;

if(MarketPosition > 0) then begin
    // StopLoss
    SL = EntryPrice - 25.0;
    SL = SQ_CorrectMinMaxSLPT(SL, MinimumSLPT, MaximumSLPT, true);
    Sell("LongSL") next bar at SL stop;
end;

if ShortEntrySignal
    and (not(LongEntrySignal))
then begin
    // Action #1
    if(OpenOrdersAllowed) then begin
        NumberOfShares = mmLots;
        SellShort("ShortMarket") NumberOfShares shares next bar at market;
    end;
end;

if(MarketPosition < 0) then begin
    // StopLoss
    SL = EntryPrice + 25.0;
    SL = SQ_CorrectMinMaxSLPT(SL, MinimumSLPT, MaximumSLPT, true);
    BuyToCover("ShortSL") next bar at SL stop;
end;

if LongExitSignal
    and (not(LongEntrySignal))
    and (MarketPosition > 0)
then begin
    // Action #1
    Sell("ClosePositionLong") next bar at market;
end;

if ShortExitSignal
    and (not(ShortEntrySignal))
    and (MarketPosition < 0)
then begin
    // Action #1
    BuyToCover("ClosePositionShort") next bar at market;
end;



策略二(發生錯誤,浮點運算除以0):
//====================================================================================

inputs:
    // Strategy variables
    MagicNumber(11111),
    // Trading Options
    ExitAtEndOfDay(false),   
    ExitOnFriday(false),
    LimitSignalsTimeRange(false),
    SignalTimeRangeFrom(0850),
    SignalTimeRangeTo(1325),
    ExitAtEndOfRange(false),
    MaxTradesPerDay(10),
    MinimumSLPT(15),  // Minimum SL/PT in ticks/pips, 0 means unlimited
    MaximumSLPT(60),  // Maximum SL/PT in ticks/pips, 0 means unlimited
    // Money Management - Fixed size
    mmLots(1.0),
    InitialCapital(30000000),
    CreatedBy("StrategyQuant X");  
vars:
    // Internal variables
    LongEntrySignal(false),
    ShortEntrySignal(false),
    LongExitSignal(false),
    ShortExitSignal(false),
    NumberOfShares(0),
    tickSize(MinMove/PriceScale),
    OpenOrdersAllowed(true),
    PriceLevel(0),SL(0), PT(0);
    Array: bool cond[100](false);
// =================================================================
OpenOrdersAllowed = true;
// Exit on close (end of day)
if(ExitAtEndOfDay) then
    SetExitOnClose;
// Exit on Friday
if ExitOnFriday and DayOfWeek(Date) = 5 then
    SetExitOnClose;
// Limit time range
if(OpenOrdersAllowed = True and LimitSignalsTimeRange = True and (Time < SignalTimeRangeFrom or Time >= SignalTimeRangeTo)) then
    OpenOrdersAllowed = False;
// Max trades per day
if(OpenOrdersAllowed = True and MaxTradesPerDay <> 0 and EntriesToday(Date) >= MaxTradesPerDay) then
    OpenOrdersAllowed = False;   
// =================================================================
// TRADING RULES LOGIC
// =================================================================
LongEntrySignal = (SQ_IsFalling(Close[0], 4, true)[0] = 1)
    and (SQ_IsFalling(SQ_Pivots(0, 0, 4)[0] of data1, 3, true)[0] = 1);
ShortEntrySignal = ((SQ_ATR(25)[1] > 85) and (SQ_ATR(25)[0] < 85))
    and (SQ_IsRising(SQ_Pivots(21, 22, 0)[0] of data1, 2, false)[0] = 1);
LongExitSignal = (SQ_IsFalling(SQ_Highest(Open, 14)[0], 2, false)[0] = 1)
    and (SQ_IsFalling(SQ_Pivots(10, 27, 1)[0] of data1, 2, true)[0] = 1);
ShortExitSignal = false;
//------------------------------------------------------------------
// Rule: Long entry
//------------------------------------------------------------------
if LongEntrySignal
then begin
    // Action #1
    if(OpenOrdersAllowed) then begin
        NumberOfShares = mmLots;
        PriceLevel = Round2Fraction((SQ_Lowest(MedianPrice, 181)[0] - (0.40 * SQ_ATR(20)[0])));
        Buy("LongStop") NumberOfShares shares next bar at PriceLevel stop;
    end;
end;
//------------------------
// Rule: Long entry - Orders Exits
//------------------------
if(MarketPosition > 0) then begin
    // StopLoss
    SL = EntryPrice - 20.0;
    SL = SQ_CorrectMinMaxSLPT(SL, MinimumSLPT, MaximumSLPT, true);
    Sell("LongSL") next bar at SL stop;
end;
//------------------------------------------------------------------
// Rule: Short entry
//------------------------------------------------------------------
if ShortEntrySignal
    and (not(LongEntrySignal))
then begin
    // Action #1
    if(OpenOrdersAllowed) then begin
        NumberOfShares = mmLots;
        PriceLevel = Round2Fraction(Close[0] + (2.70 * SQ_ATR(30)[0]));
        SellShort("ShortLimit") NumberOfShares shares next bar at PriceLevel limit;
    end;
end;
//------------------------
// Rule: Short entry - Orders Exits
//------------------------
if(MarketPosition < 0) then begin
    // StopLoss
    SL = EntryPrice + 40.0;
    SL = SQ_CorrectMinMaxSLPT(SL, MinimumSLPT, MaximumSLPT, true);
    BuyToCover("ShortSL") next bar at SL stop;
end;
//------------------------------------------------------------------
// Rule: Long exit
//------------------------------------------------------------------
if LongExitSignal
    and (not(LongEntrySignal))
    and (MarketPosition > 0)
then begin
    // Action #1
    Sell("ClosePositionLong") next bar at market;
end;
//------------------------------------------------------------------
// Rule: Short exit
//------------------------------------------------------------------
if ShortExitSignal
    and (not(ShortEntrySignal))
    and (MarketPosition < 0)
then begin
    // Action #1
    BuyToCover("ClosePositionShort") next bar at market;
end;

回復

使用道具 舉報

66

主題

0

好友

432

積分

管理員

Rank: 9Rank: 9Rank: 9

發表於 2019-2-2 21:34:26 |顯示全部樓層
你可以直接到以下網站向原廠反映本問題
https://roadmap.strategyquant.com/dashboard
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

Archiver|手機版|程式交易,系統交易資源討論區~Beta

GMT+8, 2019-6-20 04:07 , Processed in 0.062404 second(s), 10 queries , Wincache On.

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回頂部