One thing I have discovered is that if I am having problems doing
something in regular AFL, try using a loop. It may be slower but with
fast computers it rarely makes a big difference unless you are 
running a huge optimization run. Now what you are asking for may be
possible without loops, but I decided to show it with loops.

I hope this works for you,
Cey

// I am assuming no reversals. So no closing a long trade and entering a short 
trade
// on the same bar
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell, Buy)
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);

fInLong = fInShort = false;

for (i=0; i < BarCount; i++)
{
        if (fInLong)
        {
                        // if we are in a long position then remove all Short 
and Cover signals
                        Short[i] = 0; 
                        Cover[i] = 0;
                        if (Sell[i])
                                fInLong = false;
        }
        else if (fInShort)
        {
                        // if we are in a short position then remove all Buy 
and Sell signals
                        Buy[i] = 0; 
                        Sell[i] = 0;
                        if (Cover[i])
                                fInShort = false;
        }
        else
        {
                // we are not in any position. See if we have a Buy or Short 
signal
                if (Buy[i])
                {
                        fInLong = True;
                        Short[i] = 0;
                        Cover[i] = 0
                }
                else if (Short[i])
                {
                        fInShort = True;
                        Buy[i] = 0;
                        Sell[i] = 0;
                }
                
        }
}

--- In amibroker@yahoogroups.com, Noah Bender <knowaben...@...> wrote:
>
> After spending weeks on trying to solve this problem I have come up
> with the following answer. I want to know if you  all agree agree. I
> want my chart to display the  buy,sell,short,cover arrows  when 1
> occurs in the corresponding array. That I can accomplish.
> 
> But I have short arrows occuring while I am in the middle of a long
> trade and long arrows occuring in the middle of a short trade. I have
> tried a whole bunch of solutions to this problem but at the end of the
> day to no avail.
> 
> I saw that zeek/mike had and excahnge about this and so did barry.
> 
> I have tried
> 
> a) the exrem function- but that does not solve much even if i do
> buy=exrem(buy,short or sell); as u suggested in an earlier email
> .because then a buy can still occur once a short has occured or even i
> change to cover a buy can still occur if there are 2 short trades in a
> row.
> b) i tried setting static vars - but can't backtest them or see them
> in exploration. so that does me know good.
> 
> c) I tried using the backtester interface to plot only real trades.
> that does plot real trades and there are no conflicting signals
> plotted. but in real time I still get a 1 in the short array while in
> the middle of a long trade.
> 
> d) i even tried the flip funciton. but it will always be reset to zero
> when the code reproccesses the array bc it needs to be initialized.
> 
> Is there anyway to avoid getting a 1 in the short array while the last
> signal in the buy/sell array was one in the buy array ( meaning in the
> middle of a long trade).
> 
> I am starting to think there is not.
> PLease correct me if I am wrong. I have seen posts on the forum with
> similar  frustrations.
> 
> thanks
>


Reply via email to