I often cannot find bugs unless they occur whilst I am watching, because I do not know what happens. Tonight, I watched Aurora steadfastly ignore several sell opportunities.
I had forgotten to convert a variable in the conversion to Stealth, (coders, it was 'take' - should have been PendingTake in the call to the filter) that caused A to consult the RN filter with a TP value of zero. This meant that for buy trades, the open price and the tp never straddled the upper line; for sells it always straddled the lower line. Sell trades should never have been taken with RN enabled.
Having fixed that, I watched A take a trade, then move the stop to BE rather early, so I worked out why A was sometimes getting those premature trades and why Gi sometimes opens a trade then closes it almost immediately.
Because the price line that we see on the chart is the Bid, I based all trade opening and closing decisions on this. However, all Sell trades are closed at the Ask, so basing closure decisions on the Bid was cutting out the spread. Here is the sequence of events that caused premature stop moves, or at least I think it is:
- all the filters for a sell trade is in place, so A sets up the pending.
- the trigger candle is very small - say 2 or 3 pips.
- trade fills, with a hidden tp of about 5 pips.
- with the move stop to BE based on the Bid, and given a spread of 2, the price only has to fall 3 pips to move the hidden stop loss to BE + breakeven profit.
- this can be less that the Bid, so A spots this and closes the trade
So, I have changed the BE stop move for a sell and the closure decision so that it is based on the Ask. Let's see if this works better, because another solution is to not move the stop to BE until the bid is on the right side of it and the trade will not instantly close.
We shall see.