I often use a parabolic trailing stop I have adjusted over time to use in Multicharts. It has a factor to adjust so that the stop is below last low as well as a factor for speed of acceleration of the stop. The problem is that when I print out the results, I am getting two different stops for each bar. It works with Multicharts anyways, but I wonder whether I haven't put some kind of redundancy into the code. Any help is appreciated:
variables:
var0( 0 ), //tracks market position
var1( 0 ), //becomes the stop price
var2( 0 ), //starts as the acceleration factor step
var3( 0 ) , //starts as the bar high
mp(0),
TL_LX(0),
var4(0); //bars since entry factor
var0 = MarketPosition ; //makes var0 the market position variable
var4 = barssinceentry;
if var0 = 1 then //when position is long
begin //start
if var0[1] 1 then //checking if this is the first bar of long position
begin //if it is then set the following---
var1 = Low - AvgTrueRange( ATRLength ) * NumATRs ; //stop price is low - ATR of 3 periods*1.5, calculated on current bar for next bar stop level
var2 = AccFactorStep ; //var2 is acceleration factor step
var3 = High ; //var3 is current bar high
end
else //after the first bar of a new long position start the following
begin
if High > var3 then //only moves the stop if the high is higher than last bar
var3 = High ; //sets var3 to the new high
var1 = var1 + var2 * var4 * Multiplyer{( var3 - var1 )} ; //new stop is last stop + accelaration factor step*{(high-prior stop)//barssinceentry
condition1 = var3 > var3[1] and var2 Low then //if stop is higher than current bar low, then step becomes low
var1 = Low - stopcorrection ;
if barssinceentry >= NumBars then begin //after a certain number of bars, start the stop
Sell ( "ParTrLX" ) next bar at var1 stop ;
end;
end ;