Breakout This is a simple channel breakout system with two filters, once using moving average convergence-divergence and another based on volatility. Sub ChannelForAdaptF(SLen as integer) Dim MinMove Dim TrProfit Dim LowPrice As Double Dim HighPrice As Double LowPrice = Lowest(Low,SLen,0) HighPrice = Highest(High,SLen,0) MinMove = GetActiveMinMove() If Macd(Close,12,26,9)>0 And Range < 3.5*Average(Range,40,0) Then VirtualBuy(“ChanBuy”,1,HighPrice+MinMove ,Stop,Day) If Macd(Close,12,26,9) < 0 And Range < 3.5*Average(Range,40,0) Then VirtualSell(“ChanSell”,1,LowPrice-MinMove,Stop,Day) VirtualExitShort(“SX”,””,1,HighPrice+MinMove ,Stop,Day) VirtualExitLong(“LX”,””,1,LowPrice-MinMove,Stop,Day) If Macd(Close,12,26,9)>0 And Range<3.5*Average(Range,40,0) Then Buy(“ChanBuy”,1,HighPrice+MinMove ,Stop,Day) If Macd(Close,12,26,9)<0 And Range<3.5*Average(Range,40,0) Then Sell(“ChanSell”,1,LowPrice-MinMove,Stop,Day) ExitShort(“SX”,” “,1,HighPrice+MinMove ,Stop,Day) ExitLong(“LX”,””,1,LowPrice-MinMove,Stop,Day) End Sub 3. Window of opportunity The adaptive f concepts adjusts the trade-size value in accordance to the same principles of optimal f, but without the benefit of hindsight and using a moving window that better reflects current market conditions. Function CalcOptimalF_TPVir(Increment As Double, TradeLookBack, objMark As TSProcessor.IMarket,ByRef LargestLoss) Dim Trades As Array Dim f As Double Dim bestF As Double Dim bestValue As Double Dim biggestLoser As Double Dim curValue As Double Dim i As Integer Dim TradeInfo As Array TradeLookBack = Min(TradeLookBack, objMark.TradeCount) If TradeLookBack = 0 Then CalcOptimalF_TPVir = .1 Exit Function End If ReDim (Trades, TradeLookBack) For i = 0 To TradeLookBack - 1 Trades[i] = objMark.VirTrade(i).Profit Next bestValue = -9999999 biggestLoser = Min(Trades) For f = (0 + Increment) To (1 - Increment) Step Increment curValue = 1 For i = 0 To UBound(Trades)-1 curValue = curValue * (1 + (f * ( -1 * Trades[i] / biggestLoser))) Next If curValue > bestValue Then bestValue = curValue bestF = f End If Next LargestLoss = biggestLoser CalcOptimalF_TPVir = bestF End Function 4. Top to bottom Here’s the code for our entire trade plan, integrating adaptive f into the mix. Sub AdaptiveFTradePlanAugArt(steps,F_TradeWindowSize,ScaleF,Ceiling) Dim S As Integer Dim M As Integer Dim DollarPerTrade Dim StartAccount Dim OptF Dim BigLoser Dim objMark As TSProcessor.IMarket If tradeplan.MarketType = 0 Then If Tradeplan.SummEquity < tradeplan.MarginForOneLot Then MsgBox “not enough money” StopRun End If ‘If Tradeplan.SummEquity< Tradeplan.TotalMarginForPlan Then ‘MsgBox “Margin Call Account below minimum margin required” ‘StopRun End If DollarPerTrade = tradeplan.SummEquity/tradeplan.MarketCount For S = 0 To TradePlan.SessionCount – 1 TradePlan.Session(S).UnitSize = 1 For M = 0 To TradePlan.Session(S).MarketCount – 1 objMark = TradePlan.Session(S).Market(M) OptF=CalcOptimalF_TPVir(steps,F_TradeWindowSize, TradePlan.Session(S).Market(M),BigLoser) If OptF>.60 Then OptF=.60 End If If BarNumber>500 Then If OptF>steps Then objMark.EntryNumUnits = Min(Max(DollarPerTrade/(Abs(BigLoser)/(OptF*ScaleF)),1),Ceiling) Else objMark.EntryNumUnits=1 End If Else objMark.EntryNumUnits = 1 End If objMark.ExitNumUnits = objMark.NumContractsHeld Next End Sub