[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Code for trailing stop



PureBytes Links

Trading Reference Links

Hi,

I just coded by own trailing stop, because I wasn't sure how Omega's works and I don't 
trust what I don't code myself.  I thought others might be interested in it.  Also, if any 
EL whizes notice any bugs or problems, please let me know, or post improvements to 
the list.  The inputs Trail$ is the trailing amount below the best level the position ever 
achieved and Floor$ is the amount of profit above which the stop kicks in.  You could 
set Floor$ to 0 to get a simple trailing stop.  Use the includesystem to include this 
code in any of your other systems.  Hope this is of some use to people.

Regards,

Lawson McWhorter
lawson@xxxxxxxxxxxxx

Inputs:Trail$(2000),Floor$(2000);
Vars:BestLong(0),LongExit(0),BestShort(0),ShortExit(0);

if marketposition(0)=1 then begin
	BestLong=MaxPositionProfit/BigPointValue + EntryPrice(0);
	LongExit=BestLong - (Trail$/BigPointValue);
	if MaxPositionProfit>Floor$ then Exitlong("Risk Trail Long") next bar at 
Longexit stop;		
	end;

if marketposition(0)=-1 then begin
	BestShort=EntryPrice(0) -  MaxPositionProfit/BigPointValue;
	ShortExit=BestShort + (Trail$/BigPointValue);
	if MaxPositionProfit>Floor$ then Exitshort("Risk Trail Short") next bar at 
shortexit stop;		
	end;