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.
Topic moved to the ProOrder Support Forum.
Please try to post in the correct forum to get the best possibility of an answer 🙂
Once PositionSize = 1
IF tradecount = 5 then
positionSize = positionsize + 1
tradecount = 0
endif
IF (your conditions) then
BUY positionsize contract at market
tradecount = tradecount + 1
endif
Not tested.
Hi,
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:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 080000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 190000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Once PositionSize = 1
IF tradecount = 5 then
positionSize = positionsize + 1
tradecount = 0
endif
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = Average[20](close)
c1 = (indicator1 CROSSES OVER indicator2)
IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY positionsize PERPOINT AT MARKET
tradecount = tradecount + 1
ENDIF
// Stops and targets
SET STOP pLOSS 15
SET TARGET pPROFIT 30
Any idea what I’m doing wrong?
Many thanks.
somehow it didn’t take the list of trades last time
It 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:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 080000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 190000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Once PositionSize = 1
IF tradecount = 5 then
positionSize = positionsize + 1
tradecount = 0
endif
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = Average[20](close)
c1 = (indicator1 CROSSES OVER indicator2)
IF Not OnMarket and c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY positionsize PERPOINT AT MARKET
tradecount = tradecount + 1
ENDIF
// Stops and targets
SET STOP pLOSS 15
SET TARGET pPROFIT 30
Now 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.
That 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.
Now 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.
I’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.
[attachment file=73884]
What happens with a “defparam preloadbars=0”?
with 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
What 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?
Sometimes 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 🙂
Forcing 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!