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/28/2022 at 5:13 PM #203165
Hi, took a look at the snippet library but could not find what i was looking for. I want to add to my system following:
- If x of last trades were losses, increase size by y
- If x of last trades were wins, decrease size back to y
Saw something similar on ICT and how to flatline your equitycurve by going down to normal size after x number of wins in a row
10/28/2022 at 6:22 PM #203170There you go (not tested):
123456789101112131415161718ONCE x = 5ONCE y = 1ONCE LotSize = yONCE WinningTrades = 0ONCE LosingTrades = 0IF StrategyProfit > StrategyProfit[1] THENWinningTrades = WinningTrades + 1IF WiningTrades >= x THENWiningTrades = 0LotSize = yENDIFELSIF StrategyProfit < StrategyProfit[1] THENLosingTrades = LosingTrades + 1IF LosingTrades >= x THENLosingTrades = 0LotSize = LotSize + yENDIFENDIF1 user thanked author for this post.
10/28/2022 at 8:13 PM #203173Link to above added as Log 342 here …
1 user thanked author for this post.
10/28/2022 at 11:01 PM #203174Thanks as always Roberto!!
add to losses1234567891011121314151617ONCE y = 0.2ONCE LotSize = 0.2ONCE WinningTrades = 0ONCE LosingTrades = 0IF StrategyProfit > StrategyProfit[1] THENWinningTrades = WinningTrades + 0.2IF WiningTrades >= 5 THENWiningTrades = 0LotSize = yENDIFELSIF StrategyProfit < StrategyProfit[1] THENLosingTrades = LosingTrades + 0.2IF LosingTrades >= 1 THENLosingTrades = 0LotSize = LotSize + 0.2ENDIFENDIFThis is what i got this far, but size does not reset back to 0.2 lots, i want the system to have:
- 0.2 lot size as STANDARD.
- When making one loss, i want to add 0.2 lots, if it makes a loss again (two in a row) Add another 0.2 lots. Makes 3 in a row, another 0.2 lots and so on until it makes a win, then i want it to reset back to Standard 0.2 lot size
- When got a win, add 0.2 up to 5 wins, if system reaches 5 wins in a row, reset back to standard 0.2 lot size.
- If possible, also add max lotsize of MAXLOTSIZE
1 user thanked author for this post.
10/28/2022 at 11:09 PM #20317510/28/2022 at 11:24 PM #20317610/28/2022 at 11:38 PM #203177Here is the full code if it helps 🙂
my strat12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061// 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 = FALSEONCE MaxTrades = x //no more than 2 trades a dayONCE Tally = 0IF IntraDayBarIndex = 0 THENTally = 0ENDIFIF Not OnMarket THENMyExit = 0ELSEc1 = 0ENDIF////////////////////////////////////////////////////////////////////////////////////////////////////////////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 0.2 Contract AT MyHI + 1 * pipsize STOPSELLSHORT 0.2 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 STOPENDIFENDIF10/29/2022 at 5:54 AM #20317912345WinningTrades = WinningTrades + 0.2IF WinningTrades >= 5 THEN // Winning, not wining.WinningTrades = 0 // Winning, not wining.LotSize = yENDIFUlle, the above is from your example. It should work better with these corrections.
Btw, I don’t find this back in your main code (which is not for my brains anyway – it really is too full with mistakes/faults 😉 ).
Try to get your sample code to work, and when it does what you want, slowly expand it to your strategy idea.
🙂1 user thanked author for this post.
10/29/2022 at 10:40 AM #203182Sorry for mispelling, but I could not test it, as I was writing it from my mobile phone.
In such cases using GRAPH may help quite a lot!
10/29/2022 at 12:06 PM #203186It is a best example of why PRT should not allow to use variables (without producing an error) that were not defined earlier in the code. Thus :
12345WinningTrades = WinningTrades + 0.2IF WiningTrades >= 5 THEN // This should error out.WiningTrades = 999 // But because this is here, the line above is treated as OK and WiningTrades will always be 0.LotSize = yENDIFPRT developers apply the intelligence that because the WiningTrades = 0 line exists, the If above it does not produce an error.
I once lost money because of such a typo and IIRC the response was that I should not make typos.
So I repeat from back then : there is no language that I know of which allows this. And it is worse :The official response from PRT support (in Paris) was :
If we don’t do it this way, nobody is able to get his program to run because of errors.A weirdest response ever. Apparently it is better to lose money.
PS: V12 provides a kind of solution to this.
10/29/2022 at 12:16 PM #203188To be honest I prefer the current solution to the previous one, when it was difficult to test variables as you always got the “undefined variable” error message and you had to always comment/uncomment lines. It was so much time consuming!
10/29/2022 at 12:34 PM #203189nobody is able to get his program to run because of errors.
PRT likely got many Coding Support Queries due to above and so easy way to reduce Queries … make errors not show as errors at all!?
10/29/2022 at 6:29 PM #203196To be honest I prefer the current solution to the previous one, when it was difficult to test variables as you always got the “undefined variable” error message and you had to always comment/uncomment lines. It was so much time consuming!
I 100% agree with you. That is, would it be really like that. But it was not ..
The crazy time consuming was about that a variable was not used …
Example :1234567MyVar = 1 // <-- Errors on this line because it is not used in the program.My2ndVar = 1//If MyVar = 1 thenIf My2ndVar = 1 then // Like this now.Buy x at MarketEndifSo we could not comment-out lines unless in this case the first line was commented out as well.
And back to the old If ? indeed a crime (requires 1st line to uncomment and the 2nd to comment out).But this is not related to what’s odd today (in V11).
10/29/2022 at 8:54 PM #203197PeterST, no i did not get it to work anywhere close to what i wanted, it took positions up to 20 lots, I want a maxsize of total of 2-3 lots and add to every loss. So i scrapped it, hoping code-wizards like Roberto could make some magic and add to my original code 😀 my codingskillz are way worse than my english ^^,
10/29/2022 at 10:05 PM #203199Shall the X trades, either winning or losing ones, be consecutive?
-
AuthorPosts
Find exclusive trading pro-tools on