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

Re: Coding % stop loss in easy language



PureBytes Links

Trading Reference Links

Alfredo,

See if this will work for you.

Inputs:XLstop(.97);
Variables:BSE(0);
BSE=barssinceentry;

{the following would get you out at x% from top since entry, like a
trailing stop}

If MarketPosition>=1 then begin
ExitLong next bar at (Highest(H, BSE)*XLstop) - 1 point stop;
End;

{this will get you out at x% below your entry price}

If MarketPosition>=1 then ExitLong next bar at (EntryPrice*XLstop) - 1
point stop;

There's many ways to write this depending on whether you want to use stop
orders for next bar or closes or highs/lows, etc., etc.

Hope that helps.

Carlos Lourenco

ps: the following are a couple of exits from "The Code" which you may want
to look at:

{Exit #1 - Trailing Stop from "The Code"}

VAR: BestLong(0), LongExit(0), BestShort(0), ShortExit(0);

IF MarketPosition(0)=1 THEN 
   BEGIN
      BestLong = MaxPositionProfit / (CurrentContracts * BigPointValue) 
+ EntryPrice(0);

      LongExit = BestLong - 3*StdDev(Close - Close[1], 30);

      ExitLong ("Exit #1-Lng") Next Bar at LongExit Stop;
   END;

IF MarketPosition(0)=-1 THEN
   BEGIN
      BestShort = EntryPrice(0) - MaxPositionProfit / (CurrentContracts 
* BigPointValue);

      ShortExit = BestShort + 3*StdDev(Close - Close[1], 30);

      ExitShort ("Exit #1-Sht") Next Bar at ShortExit Stop;
   END;

{Exit #2 - Profit Taking Stop from "The Code"}
Inputs: Factor(3),SDLen(30);
VAR: VolIndex(0), LongLimit(0), LongStop(0), ShortLimit(0), 
ShortStop(0);

VolIndex = Factor*StdDev(Close - Close[1],SDLen);

IF MarketPosition(0)=1 THEN
   BEGIN
      LongLimit = EntryPrice(0) + VolIndex;
      LongStop = EntryPrice(0) - VolIndex;
      ExitLong ("Exit #2 Ln +") Next Bar at LongLimit Limit;
      ExitLong ("Exit #2 Ln -") Next Bar at LongStop 	Stop;
   END;

IF MarketPosition(0)=-1 THEN
   BEGIN
      ShortLimit = EntryPrice(0) - VolIndex;
      ShortStop = EntryPrice(0) + VolIndex;
      ExitShort ("Exit #2 Sh +") Next Bar at ShortLimit Limit;
      ExitShort ("Exit #2 Sh -") Next Bar at ShortStop 	Stop;
   END;



----------
> From: Alfredo Mayall Simas <alfredo.simas@xxxxxxx>
> To: omega-list@xxxxxxxxxx
> Subject: Coding % stop loss in easy language
> Date: Friday, September 04, 1998 7:01 PM
> 
> Hi Netters,
> 
> Does anyone know how to code in easy language a % stop loss. 
> That is: stop when the loss is, say, 3% of the entry price.
> 
> I tried to use entryprice but I get erratic results.
> 
> Thank you
> Alfredo
>