Change size depending on result
Forums › ProRealTime English forum › ProOrder support › Change size depending on result
- This topic has 17 replies, 4 voices, and was last updated 2 years ago by
PeterSt.
-
-
10/30/2022 at 2:32 AM #203203
But this is not related to what’s odd today (in V11).
I meant to say : in V10.3.
10/30/2022 at 2:41 AM #203204Anyway, just use the code I first posted AS IS (you may change it at a later moment), but with the correct spelling, and don’t be afraid of using GRAPH:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788// pl: 130 sl: 70 t & ts: 50 x: 1 = 3min 528$, 46,88W, 25% BE, 3.1 G/L ratio, 1,82 time in the market. 64 tradesDEFPARAM CumulateOrders = FALSE//ONCE x = 5ONCE y = 1ONCE LotSize = yONCE WinningTrades = 0ONCE LosingTrades = 0IF StrategyProfit > StrategyProfit[1] THENWinningTrades = WinningTrades + 1IF WinningTrades >= x THENWinningTrades = 0LotSize = yENDIFELSIF StrategyProfit < StrategyProfit[1] THENLosingTrades = LosingTrades + 1IF LosingTrades >= x THENLosingTrades = 0LotSize = LotSize + yENDIFENDIF//ONCE MaxTrades = x //no more than 2 trades a dayONCE Tally = 0IF IntraDayBarIndex = 0 THENTally = 0ENDIFIF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF//once sl = 30once pl = sl * 2once adr = 30once t = 10once ts = t////////////////////////////////////////////////////////////////////////////////////////////////////////////NewTrade = (OnMarket AND Not OnMarket[1]) OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) OR ((Not OnMarket AND Not OnMarket[1]) AND (StrategyProfit <> StrategyProfit[1]))IF NewTrade THENTally = Tally + 1ENDIF////////////////////////////////////////////////////////////////////////////////////////////////////////////// ADR Average Daily RangeMyADR = average[20,0](Dhigh(1) - Dlow(1))//IF (Time = 000000) OR ((Time > 000000) AND (Time < Time[1])) THENMyHI = highMyLO = lowc1 = 0ENDIFIF Time <= 142900 THENMyHI = max(MyHI,high)MyLO = min(MyLO,low)MyRange = MyHI - MyLOc1 = ((MyRange / MyADR) * 100) < adrENDIFIF LongOnMarket THENSET TARGET pPROFIT PL //you can change this value for LONG tradesSET STOP pLOSS SL //you can change this value for LONG tradesELSIF ShortOnMarket THENSET TARGET pPROFIT PL //you can change this value for SHORT tradesSET STOP pLOSS SL //you can change this value for SHORT tradesENDIFIF Time >= 142900 AND Time <= 220000 AND c1 AND Tally < MaxTrades AND Not OnMarket THEN //trade only between 15:30 and 18:00BUY LotSize Contract AT MyHI + 1 * pipsize STOPSELLSHORT LotSize Contract AT MyLO - 1 * pipsize STOPSET TARGET pPROFIT PL //initial values cannot be different with pending ordersSET STOP pLOSS SLENDIFIF MyExit = 0 THENIF LongOnMarket AND (close - TradePrice) >= t * pipsize THEN //you can change this value for LONG tradesMyExit = TradePriceENDIFIF ShortOnMarket AND (TradePrice - close) >= ts * pipsize THEN //you can change this value for SHORT tradesMyExit = TradePriceENDIFENDIFIF MyExit > 0 THENIF LongOnMarket THENSELL AT MyExit STOPELSIF ShortOnMarket THENEXITSHORT AT MyExit STOPENDIFENDIFgraph LotSize10/30/2022 at 4:59 AM #203210Here’s my take, based on the original snippet from Roberto.
Ulle, As far as I can see this should do what you want.
It is optimized on the TakeProfit and the StopLoss, and I would not use this in Live. Also, I made it a version for Short only, as this works out for the better (Long loses whatever I try within the mechanism).12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849ONCE x = 5ONCE y = 1ONCE LotSize = yONCE WinningTrades = 0ONCE LosingTrades = 0ONCE Spread = 1.5 // Nasdaq average of the day. Fill this at Backtest (Editor) start as well.// These are (over-)optimized, so be careful :ONCE TPA = 124ONCE SLA = 66 // Set to 33 for a nice test.IF StrategyProfit > StrategyProfit[1] THENWinningTrades = WinningTrades + 1LosingTrades = 0 // Reset.IF WinningTrades >= x THENWinningTrades = 0 // Start all over.LotSize = yENDIFELSIF StrategyProfit < StrategyProfit[1] THENLosingTrades = LosingTrades + 1WinningTrades = 0 // Reset.IF LosingTrades >= x THENLotSize = LotSize + (y / 5) // = 0.2LosingTrades = 0 // Start all over.ENDIFENDIFTP = TPA * LotSizeSL = SLA * LotSizeIf Not OnMarket then//Buy Lotsize Shares at Market // Long version.SellShort Lotsize Shares at Market // Short version.elseGain = (PositionPerf * abs(countofposition) * TradePrice) - (Spread * CountOfPosition)If Gain > TP then//Sell at Market // Long version.ExitShort at market // Short version.elseIf Gain < -SL then // Don't make too small or else no subsequent losses of x will occur.//Sell at market // Long version.ExitShort at market // Short version.endifendifendifGraph winningTrades Coloured ("Green")Graph LosingTrades Coloured ("Red")Graph LotSize Coloured ("White")Use this on Nasdaq (Tech 100), Contract size of 1 euro.
Timeframe 1 minute.
Load 100K bars.
The problem with this idea – at least how I see it – is that the subsequent losses form the mechanism, while the subsequent losses only form (really emerge) at the lower SL which implies losing because of the Spread. And thus the SL must be higher than the mechanism desires, and next the mechanism doesn’t work well.
Have fun now !
-
AuthorPosts
Find exclusive trading pro-tools on