本帖最後由 Haydn 於 18-3-31 16:41 編輯
這程式碼是從定量策略大師 StrategyQuant v3.8.2轉成MC的程式碼
放進MC後 編譯成功 但是放進圖形後沒有反應 請問要修改哪裡讓城市能正常運作
inputs:
//------------------------------------------------------------------
// Strategy Options
MaxTradesPerDay(0),
ExitOnClose(true),
LimitSignalsToRange(true),
TimeRangeFrom(0800),
TimeRangeTo(0400),
//------------------------------------------------------------------
// Money Management Parameters
// MoneyManagementType:
// 0 - fixed size (from TradeSize)
// 1 - risk fixed % of account equity
// 2 - risk fixed amount in $
//------------------------------------------------------------------
CapitalSize(10000),
MoneyManagementType(0),
TradeSize(1.0),
SizeRounding(0),
RiskPerTrade(0), // in % or in $, depending on MM type
MaxTradeSize(0);
vars:
tickSize(MinMove/PriceScale),
PriceLevel(0), NumberOfShares(0),
LongSL(0),LongPT(0),
ShortSL(0),ShortPT(0),
SLSize(0),
LongEntryCondition(false),ShortEntryCondition(false),
LongExitCondition(false),ShortExitCondition(false);
// ------------------------------------------
// ENTRY RULES
// ------------------------------------------
if(LimitSignalsToRange = false or (Time >= TimeRangeFrom and Time < TimeRangeTo)) then begin
// Long --------
if(MaxTradesPerDay = 0 or EntriesToday(Date) < MaxTradesPerDay) then begin
LongEntryCondition = ((Average(Close,2)[1] < Average(Close,9)[1]) and (Average(Close,2)[0] >= Average(Close,9)[0]));
if(LongEntryCondition = true) then begin
SLSize = 31 * tickSize;
//NumberOfShares = SQ_MoneyManagement(CapitalSize, SLSize, MoneyManagementType, TradeSize, SizeRounding, RiskPerTrade, MaxTradeSize);
if(MarketPosition = 0) then
Buy("LongMarket") NumberOfShares shares next bar at market;
end;
end;
// Short --------
if(MaxTradesPerDay = 0 or EntriesToday(Date) < MaxTradesPerDay) then begin
ShortEntryCondition = ((Average(Close,2)[1] > Average(Close,9)[1]) and (Average(Close,2)[0] <= Average(Close,9)[0]));
if(ShortEntryCondition = true) then begin
SLSize = 31 * tickSize;
//NumberOfShares = SQ_MoneyManagement(CapitalSize, SLSize, MoneyManagementType, TradeSize, SizeRounding, RiskPerTrade, MaxTradeSize);
if(MarketPosition = 0) then
SellShort("ShortMarket") NumberOfShares shares next bar at market;
end;
end;
end;
// ------------------------------------------
// MANAGE TRADE & EXIT RULES
// ------------------------------------------
// Long --------
if(MarketPosition > 0) then begin
If BarsSinceEntry = 0 then begin
LongPT = 0;
LongSL = EntryPrice - 31 * tickSize;
end;
// Stop trailing
PriceLevel = Round2Fraction(Open[2] + (0.2) * (AvgTrueRange(112)[0]));
if(PriceLevel > 0) then begin
if(LongSL = 0 or LongSL < PriceLevel) then
LongSL = PriceLevel;
end;
if(LongPT > 0) then
Sell("LongPT") next bar at LongPT limit;
if(LongSL > 0) then
Sell("LongSL") next bar at LongSL stop;
end;
// Short --------
if(MarketPosition < 0) then begin
If BarsSinceEntry = 0 then begin
ShortPT = 0;
ShortSL = EntryPrice + 31 * tickSize;
end;
// Stop trailing
PriceLevel = Round2Fraction(Open[2] + (-0.2) * (AvgTrueRange(112)[0]));
if(PriceLevel > 0) then begin
if(ShortSL = 0 or ShortSL > PriceLevel) then
ShortSL = PriceLevel;
end;
if(ShortPT > 0) then
BuyToCover("ShortPT") next bar at ShortPT limit;
if(ShortSL > 0) then
BuyToCover("ShortSL") next bar at ShortSL stop;
end;
if(ExitOnClose) then
SetExitOnClose;
|