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

Re: Help on easylanguage code



PureBytes Links

Trading Reference Links

> But I find that my code enters and exits immedaitely.

You have the right idea.  You attempted to capture the crossover 
event, rather than just looking to see if avg1 was greater than 
avg2:

> { set buy flag to 1 when there is an up crossover }
> IF Value1 > Value2 AND Value1[1] < Value2[2] then begin

One minor error:  you should be looking at Value2[1] instead of 
Value2[2].  

Easy Language supports "crosses over" and "crosses under" 
operators to simplify this.  You could instead use:

  IF Value1 crosses over Value2 then begin ...

But that's not what's causing your problem.  The reason your code 
keeps re-entering is because you never clear BuyFlag / SellFlag 
when you enter a position, so the buy order keeps getting re-
issued.  By default TS will only take one position in each 
direction, so it doesn't buy again while you're long.  But as 
soon as you exit on the profit target, *poof* there you go again.

Try something like

if MarketPosition = 1 then BuyFlag = 0;
if MarketPosition = -1 then SellFlag = 0;

> { Buy above previous high on any bar after crossover }
> IF BuyFlag = 1 then buy at high + 1 stop;

Be aware that as long as BuyFlag is 1, it will issue the buy 
statement on every bar, just as it should.  But it will use the 
high of THAT BAR on every order.  Is that what you want?  Maybe 
you should store the high of the bar where the crossover happens?

Gary