I have always been a big fan of trailing stops. They serve two purposes – lock in some profit and give the market room to vacillate. A pure trailing stop will move up as the market makes new highs, but a ratcheting stop (my version) only moves up when a certain increment or multiple of profit has been achieved. Here is a chart of a simple 30 minute break out on the ES day session. I plot the buy and short levels and the stop level based on whichever level is hit first.
When you program something like this you never know what is the best profit trigger or the best profit retention value. So, you should program this as a function of these two values. Here is the code.
So, basically I set my multiples to zero on the first bar of the trading session. If the multiple = 0 and you get into a long position, then your initial stop will be entryPrice + (0 – 1) * trailAmt. In other words your stop will be trailAmt (6 in this case) below entryPrce. Once price exceeds or meets 7 points above entry price, you increment the multiple (now 1.) So, you stop becomes entryPrice + (1-1) * trailAmt – which equals a break even stop. This logic will always move the first stop to break even. Assume the market moves 2 multiples into profit (14 points), what would your stop be then?
stop = entryPrice + (2 – 1) * 6 or entryPrice + 6 points.
See how it ratchets. Now you can optimized the profit trigger and profit retention values. Since I am keying of entryPrice your first trailing stop move will be a break-even stop.
This isn’t a strategy but it could very easily be turned into one.