I have found a strange bug when using stop orders and auto trading.
I'll attach the code in the bottom.
1. Say you have a BuyStop for 5 contracts @ 1100 and a SellStop for 5 contracts @ 1050.
2. 1100 is filled and a new SellStop for 5 contracts @ 1051 is generated by the code.
3. Now you should have the original SellStop for 5 contracts @ 1050 + the new sellstop for 5 contracts @ 1051.
But what happens is that the original SellStop @ 1050 doubles to 10 contracts.
4. So now you have a SellStop for 10 contracts @ 1050 + a SellStop for 5 contracts @ 1051.
If the market moves very fast below 1050 you will be short 10 contracts instead of 5.
5. What it should look like is one SellStop for 5 contracts @ 1051 + one SellStop for 5 contracts @ 1050.
I understand why it happens as you're Long five it adds 5 to make you flat before, but it disregards the fact that you also have a stop order BEFORE and you will be flat when it comes down to 1050.
I've added some pictures to show the bug...
Hope anyone can help with this.
Edit: Is it known that the auto trader can double the position when using stop orders ?
It will not happen when backtesting but I fail to see the point of autotrading if it's not similar to backtesting.
Edit: I've added a img of how the orders should be placed.
Thanks, Lars
Code: Select all
[IntrabarOrderGeneration = false]
inputs: Length( 3 ), NoOfContracts(2) ;
Buy ( "Long1" ) NoOfContracts contracts next bar at HighestFC( High, Length ) + 1 point stop ;
Sell ("Init Exit Long1") from Entry ("Long1") next bar at LowestFC( Low, Length ) + 1 point stop;
Sell Short ( "Short1" ) NoOfContracts contracts next bar at LowestFC( Low, Length ) - 1 point stop ;
BuyToCover ("Init Exit Short1") from Entry ("Short1") next bar at HighestFC( High, Length ) - 1 point stop;