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

Re: Help on easylanguage code



PureBytes Links

Trading Reference Links

>I have a two moving average crossover system, which should exit on
>a profit target. Once it exits it should not reenter on the same
>crossover signal.
>
>But I find that my code enters and exits immedaitely.
>
>The code is given below, any help is appreciated.

How about this, which enters a new position only when the crossover
status has changed:

 ===================================================================

Vars: Entryflag(0);

{ calculate 2 simple moving averages }

Value1 = average(close,9);
Value2 = average(close,45);

{set Entryflag to 1 or -1 depending on the current crossover direction}
IF Value1 > Value2 AND Value1[1] < Value2[2] then Entryflag = 1;
IF Value1 < Value2 AND Value1[1] > Value2[2] then Entryflag = -1;

If Entryflag <> Entryflag[1] then begin {crossover just occurred}
    { Buy above previous high on any bar after crossover }
    IF Entryflag > 0 then buy at high + 1 stop;
    { Sell below previous low on any bar after crossover }
    IF Entryflag < 0 then sell at low -1 stop;
end;

{exit on a profit target }
exitlong at entryprice + 20 limit;
exitshort at entryprice - 20 limit;

 ===================================================================

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