{------------------------------------------------------------------------------- Trading Strategy Code Population member: 9 Max bars back: 78 Created by: Adaptrade Builder version 2.4.1.0 Created: 7/24/2019 5:17:05 PM Scripting language: TradeStation 6 or newer Symbol file: MES Build dates: 1/7/2000 to 7/18/2019 Project file: LongTermIndex_LongOnly_Top.gpstrat -------------------------------------------------------------------------------} { Strategy inputs } Inputs: N1 (2), { Day of week (0 to 6 for Sunday to Saturday) } N2 (72), { Indicator look-back length (bars) } Shift1 (6), { Indicator shift value (bars) } NBarEn1 (17), { Price pattern look-back length (bars) } NBarEn2 (56), { Indicator look-back length (bars) } NBarEn3 (88), { Indicator look-back length (bars) } EntFr (3.2618), { Multiple of price difference (e.g., ATR); entry } MMStopPct (8.155), { Value of percentage money management stop } NBarEx1 (86), { Number of bars from entry for market exit if profitable } StartEquity (20000.00), { Starting account equity value } PSParam (200.00), { Position sizing parameter value } RoundPS (true), { Round-to-nearest (true/false) } RoundTo (1), { Round-to position size value } MinSize (1), { Minimum allowable position size } SizeLimit (100); { Maximum allowable position size } { Variables for entry and exit prices } Var: EntPrL (0), LStop (0); { Variables for entry and exit conditions } Var: VarL1 (0), VarL2 (0), VarL3 (0), CondL1 (false), CondL2 (false), EntCondL (false); { Variables for position sizing } Var: NShares (0), Equity (0); { Entry price } EntPrL = L[NBarEn1] - EntFr * AbsValue(XAverage(L, NBarEn2) - XAverage(H, NBarEn3)); { Entry and exit conditions } VarL1 = DayOfWeek(date); VarL2 = AvgTrueRange(N2)[Shift1]; VarL3 = TrueRange; CondL1 = VarL1 crosses below N1; CondL2 = VarL2 >= VarL3; EntCondL = CondL1 or CondL2; { Position sizing calculations } Equity = StartEquity + NetProfit + OpenPositionProfit; NShares = (Equity * 0.01 * PSParam)/AbsValue(EntPrL * BigPointValue); If RoundPS and RoundTo > 0 then NShares = IntPortion(NShares/RoundTo) * RoundTo; NShares = MaxList(NShares, MinSize); NShares = MinList(NShares, SizeLimit); { Entry orders } If MarketPosition = 0 and EntCondL then begin Buy("EnLimit-L") NShares shares next bar at EntPrL limit; end; { Exit orders, long trades } If MarketPosition = 1 then begin If BarsSinceEntry = 0 then begin LStop = (1 - MMStopPct/100.0) * EntryPrice; end; Sell("ExStop-L") next bar at LStop stop; If (BarsSinceEntry >= NBarEx1 and C > EntryPrice) then Sell("ExMark-L") next bar at market; end;