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

Re: wait function



PureBytes Links

Trading Reference Links

thanks .. I got a very short solution that also seems to work:

 MP=Marketposition;

waitlong=waitlong-1;
waitshort=waitshort-1;
If MP[1]>0 and (Low<=BuySp[1]) then waitlong=WaitT;
If MP[1]<0 and ( High>=SellSp[1]) then waitshort=WaitT;
OKlong=waitlong<=0;
OKshort=waitshort<=0;

If OkLong and BuyConditions then buy at market;
If OKShort and SellConditions then sell at market;

----- Original Message ----- 
From: "Alex Matulich" <alex@xxxxxxxxxxxxxx>
To: <evanscje@xxxxxxxxxxxxx>
Cc: <omega-list@xxxxxxxxxx>
Sent: Thursday, October 30, 2003 6:26 PM
Subject: Re: wait function


> > I am really struggling (again) with code to say wait N days if stopped
> > to enter a new position on same side of the market.  Is there a sample
> > of this code somewhere that someone knows about? Chris E.
> 
> Seems simple enough.  How about something like this (untested):
> 
> --------------------------------------------------------------------
> {function: OK_to_trade - series function
>  Must be called on every bar.
>  Returns True if it's been at least N bars since the end of the
>  last trade in the Direction specified.}
> 
> inputs:
>     N(NumericSimple),         {number of days to wait}
>     direction(NumericSimple); {direction to test 1=long, -1=short}
> 
> vars: tt(0), mp(0), BarsSinceLong(0), BarsSinceShort(0);
> 
> tt = TotalTrades;     {number of closed trades}
> mp = MarketPosition;  {current market position}
> 
> if tt > tt[1] then
>     if mp[1] > 0 then BarsSinceLong = 0 else BarsSinceShort = 0;
> 
> BarsSinceLong = BarsSinceLong + 1;   {bars since end of last long trade}
> BarsSinceShort = BarsSinceShort + 1; {bars since end of last short trade}
> 
> if (direction > 0 and BarsSinceLong >= N) or
>    (direction < 0 and BarsSinceShort >= N) then
>     OK_to_trade = true
> else
>     OK_to_trade = false;
> --------------------------------------------------------------------
> 
> Your specification "wait N days if stopped to enter a new position on same
> side of the market" is kind of ambiguous.  Stopped out at a loss?  Does it
> matter if the exit was due to stopping out or reaching a target profit?
> 
> The code above doesn't regard whether the previous trade was profitable or
> not; only that the previous trade was long or short and ended at least N
> days ago.  If you want to specify that the previous trade to test must
> have been a loss, then you need to modify the first 'if' statement to test
> for PositionProfit(1), like:
> 
> if tt > tt[1] and PositionProfit(1) < 0 then
>     if mp[1] > 0 then BarsSinceLong = 0 else BarsSinceShort = 0;
> 
> -Alex
> 
>