The following code uses our new functions to synthetically keep track of our trading to determine when to enter a new trade. The Turtle System only took trades after a losing trade took place. Even with the Virtual Trade functions you still need to keep track of whether the entries/exits generated a profitable trade. It simple enough to track the real trades – compare the entries/exits when a the market position changes.
inputs: absEntryChanLen(55),entryChanlen(20),exitChanLen(10),lastTradeLoserFilter(false); vars:lastTradeLoser(true),mp(0),virtmp(0),tradeProfit(0),virtBuyPrice(0),virtSellPrice(0), myFillPrice(0); mp = marketPosition; If mp <> 1 and mp[1] = 1 then Begin tradeProfit = ExitPrice(1) - EntryPrice(1); If tradeProfit > 0 then lastTradeLoser = false; print(date," Long Trader ",tradeProfit); end; If mp <> -1 and mp[1] = -1 then Begin tradeProfit = EntryPrice(1) - ExitPrice(1); If tradeProfit > 0 then lastTradeLoser = false; print(date," Short Trader ",tradeProfit," ",lastTradeLoser); end; If lastTradeLoserFilter = False then lastTradeLoser = True; If lastTradeLoser = False then Begin print(date," In Virtual Section And VirtTmp = ",virTmp); If(virtmp = 1) then Begin if(virtualLongExit(lowest(low[1],exitChanLen),1,myFillPrice) =1) then Begin tradeProfit = myFillPrice - virtBuyPrice; If tradeProfit < 0 then lastTradeLoser = true; virtmp = 0; end; end; If(virtmp = -1) then Begin if(virtualShortExit(highest(high[1],exitChanLen),1,myFillPrice) =1) then Begin tradeProfit = virtSellPrice - myFillPrice; If tradeProfit < 0 then lastTradeLoser = true; virtmp = 0; end; end; if(virtualBuy(highest(high[1],entryChanLen),1,myFillPrice) = 1) then Begin if virtmp <> 1 then begin virtBuyPrice = myFillPrice; virtmp = 1; tradeProfit = 0; If virtmp[1] = -1 then tradeProfit = virtSellPrice - virtBuyPrice; If tradeProfit < 0 then lastTradeLoser = true; end; end; if(virtualSell(lowest(low[1],entryChanLen),1,myFillPrice) = 1) then Begin if virtmp <> -1 then begin virtsellPrice = myFillPrice; virtmp = -1; tradeProfit = 0; If virtmp[1] = 1 then tradeProfit = virtBuyPrice - virtSellPrice; If tradeProfit < 0 then lastTradeLoser = true; end; end; print("End of Virtual Module : virTmp = ",virTmp); end;
Discover more from George Pruitt
Subscribe to get the latest posts sent to your email.