Best strategy for exit with dynamic stoploss

 
I'm developing a scalping strategy EA and have been doing well so far but I stumbled upon a small problem. I'm not sure if it is small though.

As in any scalper, I am able to get small gains almost every few minutes, but on a specific instant, the trend goes wildly strange and I'm in loss. So I've tried to apply a number of mechanisms to stop the loss dynamically. Those are summarized in the following:

1- If we reach X bars without any improvement in the trend, then try to exit in the best position within 2X bars (could be an exit between X and 2X bars) from the order.
2- If the trend goes wildly wrong (huge jump or drop in the opposite direction), just exit immediately
3- If there is a steady trend in the opposite direction with spikes in the between (in the right direction) but not quite enough to create profit, then after Y spikes, take the highest spike (in trend direction) and exit there to reduce loss
4- If the trend seems to go in the right direction but suddenly goes opposite and starts to go back in the same direction again but could not be good enough to create profit, then just wait for the next time after Z waves and exit on top of that trend with the smallest loss possible.
5- If you find bizarre behaviour while waiting to be in profit (such as extremely huge difference between High and Low or because of too many dodges), then exit immediately as something strange is probably going to happen.

With a combination of the above, I was able to cut down my losses by about half to two thirds, but the problem is when and how to optimize the X, Y, Z values above. Also, are there any other better ways to stop the loss dynamically?

Finally, do you think I should start optimizing those values based on historical data for each pair independently. Also, do you think that taking the average period of successful orders is a good way to calculate those values?

Thanks for your help.

investor_me
Reason: