COCO研究院

 找回密碼
 註冊
搜索
查看: 2764|回復: 0

如何讓StrategyQuant X 跑出的MC程式 編譯完成後可以WORK

[複製鏈接]
發表於 19-8-14 16:45 | 顯示全部樓層 |閱讀模式
如提 這是FOR 電子期 所跑出來的策略
已經將SQ內建訊號匯入MC
也將下列程式碼在MC內編譯完成
但是就是不知道卡在哪邊
在MC上面就是跑不出來
在煩請有經驗的前輩指點指點

PS:附件為SQ本身內建函數&指標&訊號  需要先匯入才能編譯完成喔

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

// EasyLanguage Code for Tradestation / MultiCharts of Strategy 2.28.184
//
//   Generated by StrategyQuant X Build 122
//   at 08/14/2019 03:40
//
//   Generated for Main chart = Current Symbol / Current TF;
//------------------------------------------------------------------

inputs:
    // Strategy variables
    MagicNumber(11111),

    // Trading Options
    ExitAtEndOfDay(false),
    DayExitTime(2304),   
    ExitOnFriday(false),
    FridayExitTime(2240),
    LimitSignalsTimeRange(false),
    SignalTimeRangeFrom(0800),
    SignalTimeRangeTo(1600),
    ExitAtEndOfRange(false),
    MaxTradesPerDay(0),
    MinimumSL(0),  // Minimum SL in ticks/pips, 0 means unlimited
    MaximumSL(0),  // Maximum SL in ticks/pips, 0 means unlimited
    MinimumPT(0),  // Minimum PT in ticks/pips, 0 means unlimited
    MaximumPT(0),  // Maximum PT in ticks/pips, 0 means unlimited   

    // Money Management - Fixed size
    mmLots(0.1),
    InitialCapital(10000),
    CreatedBy("StrategyQuant X");  

vars:
    // Internal variables
    LongEntrySignal(false),
    ShortEntrySignal(false),
    LongExitSignal(false),
    ShortExitSignal(false),
    NumberOfShares(0),
    tickSize(MinMove/PriceScale),
    OpenOrdersAllowed(true),
    PriceLevel(0),LongSL(0),ShortSL(0),PT(0),
    LongTrailingStop(0),ShortTrailingStop(0),
    LongSLPlaced(false),ShortSLPlaced(false);

    Array: bool cond[100](false);



// =================================================================
// TRADING OPTIONS LOGIC
// =================================================================
OpenOrdersAllowed = true;


// Exit on close (end of day)
if(ExitAtEndOfDay) then begin
    SetExitOnClose;

    if DayExitTime <> 0000 and Time >= DayExitTime then begin
        if (MarketPosition > 0) then Sell("ExitEndOfDayL") next bar at market;
        if (MarketPosition < 0) then BuyToCover("ExitEndOfDayS") next bar at market;
        OpenOrdersAllowed = False;
    end;
end;

// Exit on Friday
if ExitOnFriday then begin
    if DayOfWeek(Date) = 5 then begin
        SetExitOnClose;

        if FridayExitTime <> 0000 and Time >= FridayExitTime then begin
            if (MarketPosition > 0) then Sell("ExitFridayL") next bar at market;
            if (MarketPosition < 0) then BuyToCover("ExitFridayS") next bar at market;
            OpenOrdersAllowed = False;
        end;   
    end
    else if DayOfWeek(Date) = 6 then begin
        OpenOrdersAllowed = False;
    end;
end;

// 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
// =================================================================

//------------------------------------------------------------------
// Rule: Trading signals
//------------------------------------------------------------------
Value1= SQ_MACD(Low, 196, 26, 16, 0)[2];
Value2= SQ_MACD(Low, 196, 26, 16, 1)[2];
Value3= Open[1];
Value4= SQ_BollingerBands(Close, 165, 2.1, 0)[1];
Value5= Open[0];
LongEntrySignal = (Value1<Value2) and ((Value3 > Value4) and (Value5 < Value4));



Value1= SQ_MACD(Low, 196, 26, 16, 0)[2];
Value2= SQ_MACD(Low, 196, 26, 16, 1)[2];
Value3= Open[1];
Value4= SQ_BollingerBands(Close, 165, 2.1, 1)[1];
Value5= Open[0];
ShortEntrySignal = (Value1>Value2) and ((Value3 < Value4) and (Value5 > Value4));



LongExitSignal = false;



ShortExitSignal = false;






//------------------------------------------------------------------
// Rule: Long entry
//------------------------------------------------------------------
if LongEntrySignal
then begin
    // Action #1
    if(OpenOrdersAllowed) then begin
        NumberOfShares = mmLots;
        PriceLevel = Round2Fraction(SQ_BollingerBands(Open, 10, 2.1, 0)[1] + (1.90 * SQ_BarRange[2]));

        if(MarketPosition = 0) then Buy("LongStop") NumberOfShares shares next bar at PriceLevel stop;
    end;

end;

//------------------------
// Orders Exits (SL, PT, Trailing) for Rule: Long entry
//------------------------
if(MarketPosition > 0) then begin
    If BarsSinceEntry = 0 then begin
        LongSL = 0;
        LongTrailingStop = 0;
    end;
    LongSLPlaced = false;
    // StopLoss
    LongSL = EntryPrice - 60.0 * tickSize;
    LongSL = SQ_CorrectMinMaxSLPT(LongSL, MinimumSL, MaximumSL, true);

    Sell("LongSL") next bar at LongSL stop;
    LongSLPlaced = true;


    // ProfitTarget
    PT = EntryPrice + 150.0 * tickSize;
    PT = SQ_CorrectMinMaxSLPT(PT, MinimumPT, MaximumPT, false);
    Sell("LongPT") next bar at PT limit;

    // Trailing Stop
    PriceLevel = 40.0 * tickSize;
    If PriceLevel > 0 and Close - EntryPrice >= Round2Fraction(0) and (LongTrailingStop = 0 or Round2Fraction(Close - PriceLevel) > LongTrailingStop) then begin
        LongTrailingStop = Round2Fraction(Close - PriceLevel); // remember also trailing stop
    end;
    If LongTrailingStop > 0 and LongTrailingStop > LongSL then begin
        Sell("LongTrailingStop") next bar at LongTrailingStop stop;
        LongSLPlaced = true;
    end;        

    if LongSLPlaced = false and LongSL > 0 then begin
        // no SL activated this bar, use default one - handling if there is no SL, only Trailing stop or Move2BE
        Sell("LongSLD") next bar at LongSL stop;
    end;   
end;


//------------------------------------------------------------------
// Rule: Short entry
//------------------------------------------------------------------
if ShortEntrySignal and (not(LongEntrySignal))
then begin
    // Action #1
    if(OpenOrdersAllowed) then begin
        NumberOfShares = mmLots;
        PriceLevel = Round2Fraction((SQ_BollingerBands(Open, 10, 2.1, 1)[1] - (1.9 * SQ_BarRange[2])));

        if(MarketPosition = 0) then SellShort("ShortStop") NumberOfShares shares next bar at PriceLevel stop;
    end;

end;

//------------------------
// Orders Exits (SL, PT, Trailing) for Rule: Short entry
//------------------------
if(MarketPosition < 0) then begin
    If BarsSinceEntry = 0 then begin
        ShortSL = 0;
        ShortTrailingStop = 0;
    end;
    ShortSLPlaced = false;
    // StopLoss
    ShortSL = EntryPrice + 60 * tickSize;
    ShortSL = SQ_CorrectMinMaxSLPT(ShortSL, MinimumSL, MaximumSL, true);

    BuyToCover("ShortSL") next bar at ShortSL stop;
    ShortSLPlaced = true;


    // ProfitTarget
    PT = EntryPrice - 150 * tickSize;
    PT = SQ_CorrectMinMaxSLPT(PT, MinimumPT, MaximumPT, false);
    BuyToCover("ShortPT") next bar at PT limit;

    // Trailing Stop
    PriceLevel = 40 * tickSize;
    If PriceLevel > 0 and EntryPrice - Close >= Round2Fraction(0) and (ShortTrailingStop = 0 or Round2Fraction(Close + PriceLevel) < ShortTrailingStop) then begin
        ShortTrailingStop = Round2Fraction(Close + PriceLevel);
    end;   
    If ShortTrailingStop > 0 and (ShortTrailingStop < ShortSL or ShortSL = 0)  then begin
        BuyToCover("ShortTrailingStop") next bar at ShortTrailingStop stop;
        ShortSLPlaced = true;
    end;        

    if ShortSLPlaced = false and ShortSL > 0 then begin
        // no SL activated this bar, use default one - handling if there is no SL, only Trailing stop or Move2BE
        BuyToCover("ShortSLD") next bar at ShortSL stop;
    end;   
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;


SQ_MC.zip

39.52 KB, 下載次數: 98

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

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-12-23 03:33

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |