I’ve been experimenting with a different way to control the cumulation of orders.
What I want is after it makes 2 entries, it can’t buy any more unless it averages down, ie can only buy below the existing positionprice, to a max of 5 in total.
This seemed to work, but today I had a situation where one position hit its target and closed, leaving 2 positions open. Then it opened 2 more positions (total of 4) even though it was well above the positionprice.
This is the code:
MaxPos = 2*positionsize
MaxPos2 = 5*positionsize
IF not longonmarket and CB THEN
BUY positionsize CONTRACT AT MARKET
elsif Ctime and longonmarket and CB2 and COUNTOFLONGSHARES < MaxPos then
BUY positionsize CONTRACT AT MARKET
elsif longonmarket and CB2 and close <positionprice and COUNTOFLONGSHARES < MaxPos2 then
BUY positionsize CONTRACT AT MARKET
SET STOP %LOSS sl
SET TARGET %PROFIT tp
ENDIF
ENDIF
Should line 8 be
elsif longonmarket and CB2 and tradeprice <positionprice and COUNTOFLONGSHARES < MaxPos2 then
or is there a better way to do it ???
Shouldnt it be =< maxpos ?
< maxpos if maxpos is 2 has to be 1 right? Im probably missing something
If it opens 1 position, then that is still < 2, so it buys another. If it were <= then it would buy a 3rd position.
That part seems to be ok, it’s the maxpos2 (only buy if averaging down) that isn’t doing what it should.
I realised my mistake above, please ignore.
Also why not use positionperf instead of positionprice, maybe it works differently in cumulating orders
elsif longonmarket and CB2 and positionperf < 0 and COUNTOFLONGSHARES < MaxPos2 then
Yeah that could work – def worth trying.
Hmm, actually in backtest it makes no difference – exactly the same result as “close <positionprice” – also continues to open new positions above the the existing positionprice
Sorry I would test myself but im using work laptop.
Another idea is –
elsif longonmarket and CB2 and (close<positionprice[1] or close<positionprice[2]) and COUNTOFLONGSHARES < MaxPos2 then
Im thinking once first position closes, the position price resets.
Im really interested in the solution too. Hope someone helps
Nice idea, but that also gives exactly the same result 🤔
Maybe has to be done using a Flag … ?
This seems to work, for anyone who’s interested:
MaxPos = 2*positionsize
MaxPos2 = 5*positionsize
IF Not OnMarket THEN
Flag = 1
Flag1 = 1
Flag2 = 1
Flag3 = 1
ENDIF
// Conditions to enter long positions
if tradetype=1 or tradetype=2 then
IF not longonmarket and CB and Flag THEN
BUY positionsize CONTRACT AT MARKET
elsif Ctime and longonmarket and CB2 and COUNTOFLONGSHARES < MaxPos and Flag then
BUY positionsize CONTRACT AT MARKET
Flag = 0
elsif longonmarket and CB2 and positionperf <0 and COUNTOFLONGSHARES < MaxPos2 and Flag1 then
BUY positionsize CONTRACT AT MARKET
Flag1 = 0
elsif longonmarket and CB2 and positionperf <0 and COUNTOFLONGSHARES < MaxPos2 and Flag2 then
BUY positionsize CONTRACT AT MARKET
Flag2 = 0
elsif longonmarket and CB2 and positionperf <0 and COUNTOFLONGSHARES < MaxPos2 and Flag3 then
BUY positionsize CONTRACT AT MARKET
Flag3 = 0
SET STOP %LOSS sl
SET TARGET %PROFIT tp
ENDIF
ENDIF
Wo muss ich den Eintrag in den Code einfügen bzw. gegen was ersetzen?Where do I have to insert the entry in the code or replace it with what?
@Maik2404
Only post in the language of the forumthat you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Where do I have to add the entry in the code or replace it with something?
Thank you very much for your effort @nonetheless, this robot is actually amazing. By the way, I’ve been testing it on demo and real accounts since version 5.3 and yesterday the robot entered 5 long positions. Usually, when the price reaches the trailing SL triggering point, the positions are covered and the trailing starts to work. Nevertheless, yesterday after the entry of the 5 long positions, the price reached the SL triggering point but it did not trigger neither in real acc nor in demo acc, so I decided to close the positions manually before night for security as long as they were not covered by the trailing SL. Did somebody have the same problem?
In the backtests the positions opened yesterday seem to be still open, so it would be interesting if other users that have this robot working could check if the positions opened yesterday are properly covered by the trailing SL.
Which version are you referring to?