{------------------------------------------------------------------------------- Trading Strategy Code Population member: 316 Max bars back: 30 Created by: Adaptrade Builder version 4.7.1.0 Created: 8/9/2024 2:14:08 AM Scripting language: TradeStation 6 or newer Symbol: ES ##-## (Intraday, 15 min bars), Primary (Data1) (C:\Adaptrade\MarketData\NinjaExport\ES ##-##.txt) Build dates: 1/2/2018 to 8/5/2023 Project file: C:\Adaptrade\Newsletters\Adaptrade\RobustOpt\RobustOpt.gpstrat -------------------------------------------------------------------------------} { Strategy inputs } Inputs: NL1 (17), { Price pattern look-back length (bars), long trades } NL2 (72), { Indicator look-back length (bars), long trades } ShiftL1 (11), { Indicator shift value (bars), long trades } NBarExL1 (99), { Number of bars from entry for market exit if profitable, long trades } TrailFlrL (1037.50), { Trailing stop floor value per share/contract, long trades } TrailPctL (57.0000), { Trailing stop percentage, long trades } NBarExL2 (90), { Number of bars from entry for market exit if unprofitable, long trades } TargPctL (3.422), { Value of percentage exit target, long trades } EntryPctS (0.9735), { Value of percentage entry (stop/limit), short trades } PriceBandSz (6.0000), { Size of price band for limit orders } PSParam (1.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: EntPrS (0), TargPrL (0), LStop (0), NewLStop (0), LTrailOn (false), InBandEnS(false), InBandExL(false); { Variables for entry and exit conditions } Var: VarL1 (0), VarL2 (0), VarL3 (0), VarS1 (0), VarS2 (0), VarS3 (0), VarS4 (0), VarS5 (0), EntCondL (false), EntCondS (false), ExCondS (false); { Variables for position sizing } Var: NShares (0); { Entry prices } EntPrS = C + AbsValue(C) * EntryPctS/100.0; InBandEnS = AbsValue(EntPrS - C) <= PriceBandSz; { Entry and exit conditions } VarL1 = HighD(0); VarL2 = H[NL1]; VarL3 = ZLTrend(VarL2, NL2)[ShiftL1]; VarS1 = HighD(0); VarS2 = CloseD(1); VarS3 = AS_ConsecBarsUp(VarS2); VarS4 = TypicalPrice; VarS5 = AS_ConsecBarsDn(VarS4); EntCondL = VarL1 < VarL3; EntCondS = VarS1 crosses above O; ExCondS = VarS3 < VarS5; { Position sizing calculations } NShares = PSParam; 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("EnMark-L") NShares shares next bar at market; end; If MarketPosition = 0 and EntCondS and C < EntPrS and InBandEnS then begin Sell short("EnLimit-S") NShares shares next bar at EntPrS limit; end; { Exit orders, long trades } If MarketPosition = 1 then begin If BarsSinceEntry = 0 then begin LStop = 0; LTrailOn = false; end; If C - EntryPrice > TrailFlrL/BigPointValue then LTrailOn = true; If LTrailOn then begin NewLStop = EntryPrice + TrailPctL * (C - EntryPrice)/100.0; LStop = MaxList(LStop, NewLStop); end; If LTrailOn then Sell("ExTrail-L") next bar at LStop stop; TargPrL = EntryPrice + AbsValue(EntryPrice) * TargPctL/100.0; InBandExL = AbsValue(TargPrL - C) <= PriceBandSz; If InBandExL then Sell("ExTarg-L") next bar at TargPrL limit; If (BarsSinceEntry >= NBarExL1 and C > EntryPrice) or (BarsSinceEntry >= NBarExL2 and C < EntryPrice) then Sell("ExMark-L") next bar at market; end; { Exit orders, short trades } If MarketPosition = -1 then begin If ExCondS then Buy to cover("ExMark-S") next bar at market; end;