Correct way to use PositionPerf for increasing OrderSize
Forums › ProRealTime English forum › ProOrder support › Correct way to use PositionPerf for increasing OrderSize
- This topic has 8 replies, 4 voices, and was last updated 3 years ago by theo123.
-
-
12/21/2020 at 10:06 AM #154699
Hi,
what is the correct way to increase or change ordersize based on either loss or win from previous trade. The below I created does not proceed to order anything when I do the probacktest. Should this be embedded somewhere?
can “OrderSize” be stated “OrderSize[1]” meaning previous Ordersize same as notation of close, indicators, etc?
123456Once OrderSize=1if positionperf(1)>0 OR positionperf(2)>0 and positionperf(1)<=0 then //starts with first 2 loses, 1 order (no increase)OrderSize =1elsif positionperf(2)<=0 and positionperf(1)<=0 then //after 2 or more loses, ordersize is the sum of previous 2 ordersizeOrderSize =OrderSize[1]+OrderSize[2]endif12/22/2020 at 12:43 AM #1548071. what size do you want to start with?
2. what increment does it have to perform after a WIN?
3. what decrement does it have to perform after a LOSS?
01/01/2021 at 8:41 AM #15583601/01/2021 at 10:02 AM #155839theo123 – I deleted that double post. Please pay attention to the forum rules.
- Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.
01/01/2021 at 10:44 AM #155843Please post the code and explain better any issue you have.
01/01/2021 at 12:41 PM #155850Here you go. This works before v11 but now it does not after update. Thanks for checking.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455defparam preloadbars=10000oNCE OrderSize = 1ONCE BadTrades = 0ONCE ExitIndex = -2//some entry codes here//The PiquemoucheIF NOT LongOnMarket AND LongEntry THENBUY OrderSize CONTRACTS AT MARKETset stop ploss LongSLpipset target Profit TakeProfitENDIF// Conditions to exit long positionsIf LongOnMarket AND LongExitDoor THENSELL AT MARKETExitIndex=BarIndexENDIF// Conditions to enter SHORT positionsIF NOT ShortOnMarket AND ShortEntry THENSellshort OrderSize CONTRACTS AT MARKETset stop ploss ShortSLpipset target Profit TakeProfitENDIF// Conditions to exit long positionsIf ShortOnMarket AND ShortExitDoor THENEXITSHORT AT MARKETExitIndex=BarIndexENDIF//----------------------------IF Barindex = ExitIndex + 1 THENExitIndex = 0IF PositionPerf(1) <= 0 THENBadTrades = BadTrades + 1IF BadTrades < 3 THEN//// If the last trade was losing and there are less than 3 successive losses,//// add one to OrderSize.OrderSize = OrderSize + 1ELSIF BadTrades MOD 3 = 0 THEN//// If the last position was losing and there are more than 3 consecutive losses,//// double OrderSize.OrderSize = OrderSize * 2ENDIFELSIF PositionPerf(1) > 0 THEN// If the previous trade was winning, reset OrderSize to 1.OrderSize = 1BadTrades = 0ENDIFENDIF01/01/2021 at 5:30 PM #155866I think you need to utilize strategyprofit and strategyprofit [1] to determine when the trade closed, and make the calculation of positionperf
Example below:
12345678910111213maxconsecutiveloss = 5once losscount = 0if strategyprofit <> strategyprofit[1] thenif positionperf(1)<0 thenlosscount = losscount + 1elselosscount = 0endifendifIF losscount > maxconsecutiveloss THENQuit // abandon strategy with consecutive loss above requiredENDIF01/01/2021 at 5:35 PM #155867Maybe better to directly try with your code,
12345678910111213141516171819202122//----------------------------IF Barindex = ExitIndex + 1 THENExitIndex = 0IF strategyprofit <> strategyprofit[1] THENIF PositionPerf(1) <= 0 THENBadTrades = BadTrades + 1IF BadTrades < 3 THEN//// If the last trade was losing and there are less than 3 successive losses,//// add one to OrderSize.OrderSize = OrderSize + 1ELSIF BadTrades MOD 3 = 0 THEN//// If the last position was losing and there are more than 3 consecutive losses,//// double OrderSize.OrderSize = OrderSize * 2ENDIFELSIF PositionPerf(1) > 0 THEN// If the previous trade was winning, reset OrderSize to 1.OrderSize = 1BadTrades = 0ENDIFENDIFENDIFBtw,
1) Your comment “If the last position was losing and there are more than 3 consecutive losses,” seems doesn’t tally with the code, why to mod with 3 and not >= 3?
2) Using my example, I’m not sure if the ExitIndex still necessary, perhaps can be removed, otherwise I’m not sure if it will enter the condition when trade is closed by STOP LOSS or TARGET
01/10/2021 at 4:38 PM #157217 -
AuthorPosts
Find exclusive trading pro-tools on