|
各位大大, 我在網上找到一個程式碼, 但很複雜, 求解釋一下他的邏緝
程式碼如下:
{ Public inputs }
Inputs:LuckyNet(0),IntraDay(0), TradeStopLoss(0.031),TradeProfit(0.039) ;
Inputs:TradeInday(1),Time1SW(1),Time1B(945),Time1E(1200) ;
Inputs:Time2SW(0),Time2B(1300),Time2E(1430),Time3SW(0) ;
Inputs:Time3B(900),Time3E(1300),PositionSW(1) ;
inputs:Frac_LMM(1.81),NBar_LM(2),Frac_SMM(5.25),NBar_SM(8) ;
{ Public Variables }
Vars:Cond_LE(false),Cond_SE(false),CondNet_L(false),CondNet_S(false),
UBuy(0),USell(0),BuyStop(0),SellStop(0),BuyStopA(0),SellStopA(0),
NewBuyStopA(0),NewSellStopA(0),PL(0),PS(0),LastTradeDay(false) ;
Vars:TimeOK1(true),TimeOK2(true),TimeOK3(true),PosSW(true) ;
{ BuyMode Setup }
inputs:Bar_L1(36),NBar_LE(7),Frac_LE(0.78) ;
{ SellMode Setup }
inputs:Bar_S1(9),NBar_SE(7),Frac_SE(4.44) ;
{ Exit Long Position Setup }
{ Exit Short Position Setup }
inputs:TRLen_S(4),TRPct_S(91),Ratio_TS(0.77),NBar_SX(99) ;
{ BuyMode Variable Setup }
Vars:LE_ATR(0) ;
{ SellMode Variable Setup }
Vars:SE_ATR(0) ;
{ Exit Long Position Variable Setup }
Vars:LMM_ATR(0) ;
{ Exit Short Position Variable Setup }
Vars:TS_ATR(0),Trigger_TSA(false) ;
Vars:SMM_ATR(0) ;
{ ***** LastTradeDay ***** }
LastTradeDay = _MagicQS268_LTD ;
{ initial profit and loss }
if MarketPosition = 0 then begin
PL = AvgPrice*TradeProfit ;
PS = AvgPrice*TradeStopLoss ;
end ;
{ ATR calculate for code }
LMM_ATR = AvgTrueRange(NBar_LM);
LE_ATR = AvgTrueRange(NBar_LE);
SMM_ATR = AvgTrueRange(NBar_SM);
SE_ATR = AvgTrueRange(NBar_SE);
TS_ATR = AvgTrueRange(TRLen_S);
{ Entry and Exit prices }
UBuy = Highest(Close, Bar_L1) + Frac_LE * LE_ATR ;
USell = Highest(Low, Bar_S1) - Frac_SE * SE_ATR ;
{ Long and Short Entry Condition Setup }
Cond_LE = DayofWeek(Date) <> 7 ;
Cond_SE = MOD(DayofMonth(Date),8) = 3 ;
{ Combine Trade Number in day }
Cond_LE = Cond_LE and EntriesToday(date) <= TradeInDay ;
Cond_SE = Cond_SE and EntriesToday(date) <= TradeInDay ;
{ Combine Trade time zone in day }
if Time1SW = 0 then TimeOK1 = true else TimeOK1 = (time >= Time1B and time <= Time1E) ;
Cond_LE = Cond_LE and TimeOK1 ;
Cond_SE = Cond_SE and TimeOK1 ;
{ Check Position status for entry}
if PositionSW = 0 then PosSW = true else PosSW = (MarketPosition = 0) ;
Cond_LE = Cond_LE and PosSW ;
Cond_SE = Cond_SE and PosSW ;
{ Entry Long orders }
if Cond_LE then Buy next bar at UBuy Stop ;
{ Entry Short orders }
if Cond_SE then SellShort next bar at USell Stop ;
{ Exit orders, long trades }
If MarketPosition > 0 then begin
PL = EntryPrice(0)* TradeProfit;
PS = EntryPrice(0)* TradeStopLoss ;
If BarsSinceEntry = 0 then begin
BuyStop = EntryPrice - Frac_LMM * LMM_ATR;
end;
SetStopLoss(PS * BigPointValue) ;
end;
{ Exit orders, short trades }
If MarketPosition < 0 then begin
PL = EntryPrice(0)* TradeProfit;
PS = EntryPrice(0)* TradeStopLoss ;
If BarsSinceEntry = 0 then begin
SellStop = EntryPrice + Frac_SMM * SMM_ATR;
SellStopA = 0 ;
Trigger_TSA = false;
end;
If EntryPrice - Close > Ratio_TS * TS_ATR then
Trigger_TSA = true;
If Trigger_TSA then begin
NewSellStopA = EntryPrice - TRPct_S * (EntryPrice - Close)/100.;
SellStopA = MinList(SellStopA, NewSellStopA);
end;
if BarsSinceEntry >= NBar_SX then BuytoCover next bar at Market ;
If Trigger_TSA then
BuytoCover next bar at SellStopA stop;
end;
if IntraDay = 0 then SetExitonClose
else if IntraDay = 1 and LastTradeDay then SetExitonClose ;
|
|