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

Re: Simulation of SetPercentTrailing logic



PureBytes Links

Trading Reference Links

Ernie asked:
>Has    anyone    simulated   the SetPercentTrailing  function?

It seems to be a reserved word, not a function.

>That  is,  using  your  own buy/sell  easylanguage  code  and
>logic,  do the same or as close as possible to the
>SetPercentTrailing function.
>
>The syntax is :
>
> SetPercentTrailing(DollarProfitTarget, PercentTrail);
>
>And would you share?

Well, let's see.  From the top of my head, I can come up with this.
Try it out.

------------------------------------------------------------------------

{Signal SetPctTrailing}

Inputs: DollarProfitTarget(500), PercentTrail(20);

Vars: activated(false), stopprice(0);

if MarketPosition = 0 then activated = false;

if activated = false and PositionProfit >= DollarProfitTarget then begin
    activated = true;
    if MarketPosition > 0 then stopprice = -999999;
    if MarketPosition < 0 then stopprice = 999999;
end;

if activated then begin
    value1 = 0.01 * PositionProfit * PercentTrail / BigPointValue;
    if MarketPosition > 0 then begin
        stopprice = MaxList(stopprice, close - value1);
        ExitLong("PxL") at stoprice stop;
    end;
    if MarketPosition < 0 then begin
        stopprice = MinList(stopprice, close + value1);
        ExitShort("PxS") at stopprice stop;
    end;
end;

{From the EL documentation:

This signal is used to specify the amount of the maximum open
position profit you are willing to lose (as a percent) as well as
the profit level that must be reached in order for the stop to
take effect. The position or contract/share is closed out when the
specified percentage of the maximum profit is lost.

Syntax: SetPercentTrailing(FloorAmnt, Amount)

Parameters:  FloorAmnt is the amount of profit to be reached before
the stop takes effect. Amount is the percent of the profit you are
willing to lose.
}

------------------------------------------------------------------------

-- 
  ,|___    Alex Matulich -- alex@xxxxxxxxxxxxxx
 // +__>   Director of Research and Development
 //  \ 
 // __)    Unicorn Research Corporation -- http://unicorn.us.com