Increase position size after certain number of trades
Forums › ProRealTime English forum › ProOrder support › Increase position size after certain number of trades
- This topic has 18 replies, 3 voices, and was last updated 5 years ago by Vonasi.
-
-
06/20/2018 at 7:05 PM #73823
Hi.
I want to test some ideas but I can’t do the programming. I tried ideas from the forum but still, nothing works the way I want. If anyone can code this it would be great as I can’t figure out how to do ‘it.
I want to be able to increase the size after each trade regardless of the result and not to depend on the size of the account.
And, if somehow is possible to increase the size after a certain number of trades it would be even greater. Something like – first 5 trades to have size 1, next 5 trades – size 2 and so on.
Many thanks.
06/20/2018 at 7:10 PM #7382406/20/2018 at 7:23 PM #7382506/20/2018 at 8:35 PM #73826Hi,
Many thanks for the quick reply.
It is increasing the size but sometimes there are 4 trades at a certain value while other times there are 6 or 7 trades on the same value. Attached is the list of closed trades.
I tried your code with a simple strategy:
123456789101112131415161718192021222324252627282930313233// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 080000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 190000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0Once PositionSize = 1IF tradecount = 5 thenpositionSize = positionsize + 1tradecount = 0endif// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = Average[20](close)c1 = (indicator1 CROSSES OVER indicator2)IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY positionsize PERPOINT AT MARKETtradecount = tradecount + 1ENDIF// Stops and targetsSET STOP pLOSS 15SET TARGET pPROFIT 30Any idea what I’m doing wrong?
Many thanks.
06/20/2018 at 8:51 PM #73828somehow it didn’t take the list of trades last time
06/20/2018 at 9:21 PM #73833It is because you do not have the condition IF NOT ONMARKET in your IF statement. CUMULATEORDERS = FALSE stops more than one position from being opened but if the conditions are met while a position is open then 1 is still added to trade count but no position is opened.
Try this:
123456789101112131415161718192021222324252627282930313233// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 080000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 190000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0Once PositionSize = 1IF tradecount = 5 thenpositionSize = positionsize + 1tradecount = 0endif// Conditions to enter long positionsindicator1 = Average[5](close)indicator2 = Average[20](close)c1 = (indicator1 CROSSES OVER indicator2)IF Not OnMarket and c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY positionsize PERPOINT AT MARKETtradecount = tradecount + 1ENDIF// Stops and targetsSET STOP pLOSS 15SET TARGET pPROFIT 3006/20/2018 at 9:43 PM #73834Now it’s better but still few things are acting strangely.
If I start with tradecount of 1 on 5 min chart it starts with a size of 15, with a tradecount of 3 it starts with a size of 5 and it does trade 6 times with the similar quantity.
The issue will be now the starting quantity, 16 units it’s a little bit too much for my account now.
However, backtesting looks interesting.
Many thanks again.
06/21/2018 at 6:56 AM #73847That seems odd. I don’t have my platform open at the moment but will try to test it later when I do.
I have changed the title of your topic to something more relevant then ‘help needed with code’ to help others forum users to know what is being discussed.
06/21/2018 at 9:55 AM #73875Now it’s live on the demo account, and actually, the number of trades open is correct, it seems that last night I didn’t realize that on the list it shows for each position the open and close of the trade.
The only problem now is the size, on one minute it started with a size of 24.
I will do few versions more and let them trade live on the demo to see how they are doing on different timeframes.
06/21/2018 at 11:17 AM #73883I’ve run my own tests and I am to be honest completely flummoxed!
I changed everything and nothing made any difference. I changed your entry condition and from what that told me it appears that the IF NOT ONMARKET is being completely ignored so when the first trade is actually opened the values of PositionSize and TradeCount have already been modified. I think it is a weird bug.
Unless someone else can come up with a theory I would suggest posting a question in the Platform Support forum with a link to here and also send in a problem ticket to PRT.
Here is my image using a different entry criteria and it can be seen from graphing positionsize and tradecount that positionsize starts very high and tradecount is already set to 4 even though no trades have previously been opened.
06/21/2018 at 11:50 AM #7388606/21/2018 at 11:53 AM #73887with a “defparam preloadbars=0” it’s working well.
Many thanks to all. Now it’s time to see how it’s performing on the live demo accounts.
thanks again
06/21/2018 at 12:07 PM #73889What happens with a “defparam preloadbars=0”?
That is a good workaround but surely it should not be doing anything prior to the start time of the strategy and if it is doing something then it shouldn’t be ignoring an instruction in the code?
06/21/2018 at 12:48 PM #73903Sometimes while preloading bars, the strategy is already doing things with variables even if the backtest period has not started, so that’s why you get weird values in your graph window.
Forcing ProBacktest to not load bars before when the strategy should start can change everything 🙂
06/21/2018 at 12:51 PM #73905Forcing ProBacktest to not load bars before when the strategy should start can change everything
Maybe we all need to start including that in every strategy just in case then!
-
AuthorPosts
Find exclusive trading pro-tools on