Going insane trying to figure out problem with this simple expert
-
When backtesting this expert behaves in weird ways I can't explain. All it should do is:
Branch 1
- If there is no position
- Buy if the SMA is higher than it was the previous bar
Branch 2
- If there is a position
- Close the position after x bars
I'm not going into all the weird stuff that happens but one thing that it always does is buy and sell within one second whenever conditions are met for the first time. After that it seems to behave as you would expect.
I can't understand why it would perform this buy followed by an immediate sell when the algorithm says to wait x bars (and on all subsequent trades the rule is followed)
Link to project below
https://fxdreema.com/shared/cbRvWooob
Thanks
-
@tonyramirez "every n bars" doesn't respect your positions with its calcuations, it will always fall out of sync - the block is kinda useless...
Use the pink loop block with "check age" to close the trades.
-
@roar Thanks, I'll give that a try. However, I don't think it has anything to do with what's going on. The problem appears regardless of how many n bars you set to close the trade. As for the 'every n bars' on the left branch - I shouldn't even need to use it but if I don't, even weirder things happen which I'm not even sure how to describe.