Australian (ASX) Stock Market Forum

Amibroker: Explore generates Sells with no previous Buy

Joined
28 May 2020
Posts
127
Reactions
229
Hi,

My current AFL generates Sells during Explore without a previous Buy.

Is this just how AB / Explore works, or is there a way to only generate Sells if the share has already been bought (and still owned).

See attached screenshot.

Thanks,
Linus

2020-07-20_09-13-23.png
 
I do not worry too much as this happens: it probably means you would have had a buy in the period preceding the one you are exploring for.
quickly check by rewinding a bit further...
 
Hi,

My current AFL generates Sells during Explore without a previous Buy.

Is this just how AB / Explore works, or is there a way to only generate Sells if the share has already been bought (and still owned).

It might help if you take the time to wrap your head around how Amibroker code works if you haven't already:
http://www.amibroker.com/guide/h_understandafl.html

If the bar meets your buy conditions, the variable for Buy it set to true. If the bar meets all your sell conditions, the variable Sell is set to true. The exploration is just showing you all Buy/Sell signals that occur within your chosen date range.
 
It might help if you take the time to wrap your head around how Amibroker code works if you haven't already:
http://www.amibroker.com/guide/h_understandafl.html

If the bar meets your buy conditions, the variable for Buy it set to true. If the bar meets all your sell conditions, the variable Sell is set to true. The exploration is just showing you all Buy/Sell signals that occur within your chosen date range.

I've read all 1487 pages of the AB manual. Doesn't mean I've memorized it, but it's a start.

If there is a section in the manual that says (in pseudocode):

  • When Explore generates a Buy, add that ticker to the portfolio
  • When Explore generates a Sell, alert only if that ticker is in the portfolio, and delete it from the portfolio

then I missed it.

I note "New --> Account", where it looks like you can create a portfolio and manually enter your buys and sells. Perhaps that can be done programmatically as well, and I thus add an additional check to the Sell criteria in my AFL code?

Or, someone more experienced than me could say, "mate, it's just the way it works", don't worry about it. If you try to enter a Sell at your broker, it will surely let you know if you don't own the stock.

TBH, I'm asking more with respect to paper trading, where I enter the positions into Share Trade Tracker. In "real trading" it won't be an issue, as noted above.
 
An exploration doesn't create or have any connection to a portfolio. An exploration just searches for all instances where a certain condition is true. In your example you asked it to list all instances where buy or sell is true. But you could also make an exploration to find, for example, all instances where the volume exceeds twice the 15 day average.

If you want to build a portfolio, you need to take those signals the exploration finds and manually enter them yourself into a portfolio tracker like an excel spreadsheet, share trade tracker. I've never used the Amibroker sim account, but I haven't heard of a way to automatically update it from the results of an exploration. Even if you could, I wouldn't recommend it personally. For live trading you want to record your trades outside of Amibroker anyway and I don't like the idea of maintaining the Amibroker account as well as your normal portfolio tracker.

But it's not as hard to keep track as you might think. What you've shown above is a year of signals. If you were paper trading then you'd run the explore at the end of every week (assuming weekly system) and then you'd only get a few sell signals. It doesn't take long to check if one of your 20 odd codes is in that list.

As for the broker, using CMC markets as an example - If you want to sell, you select from a drop down list that only contains stocks you currently hold. It then shows you how many shares you have available to sell and you input how many you want sold. So you will never send a sell order for a stock you don't hold as you can't complete the order without knowing how many shares you purchased in the first place.
 
An exploration doesn't create or have any connection to a portfolio. An exploration just searches for all instances where a certain condition is true. In your example you asked it to list all instances where buy or sell is true. But you could also make an exploration to find, for example, all instances where the volume exceeds twice the 15 day average.

If you want to build a portfolio, you need to take those signals the exploration finds and manually enter them yourself into a portfolio tracker like an excel spreadsheet, share trade tracker. I've never used the Amibroker sim account, but I haven't heard of a way to automatically update it from the results of an exploration. Even if you could, I wouldn't recommend it personally. For live trading you want to record your trades outside of Amibroker anyway and I don't like the idea of maintaining the Amibroker account as well as your normal portfolio tracker.

But it's not as hard to keep track as you might think. What you've shown above is a year of signals. If you were paper trading then you'd run the explore at the end of every week (assuming weekly system) and then you'd only get a few sell signals. It doesn't take long to check if one of your 20 odd codes is in that list.

As for the broker, using CMC markets as an example - If you want to sell, you select from a drop down list that only contains stocks you currently hold. It then shows you how many shares you have available to sell and you input how many you want sold. So you will never send a sell order for a stock you don't hold as you can't complete the order without knowing how many shares you purchased in the first place.
Yeah, I think I'm being too perfectionistic with Explore.

I tried this:

Code:
// Add the ticker to the global variable
for (i=0; i < BarCount -1; i++) {
    if (Buy[i]) {
        ticker = StrFormat("|%s|",Name());
        tickers += ticker;
        printf("###%s   >>>%s",ticker,tickers);
    }
}  

...

// Remove the ticker from the global variable
// This assumes that ALL shares are sold, i.e. there are no partial sales
for (i=0; i < BarCount -1; i++) {
    if (Sell[i]) {
        ticker = StrFormat("|%s|",Name());
        tickers = StrReplace(tickers,ticker,"");
        printf("###%s   >>>%s",ticker,tickers);
    }
}

The concept worked in some test code, but broke when I tried it in Explore.
 
That is what i use in my code
I have that in my code.

I wish Explore could be coded like:

  • Generate a Buy signal
  • Do I already own it?
  • If so, do I allow pyramiding?
  • If not, discard Buy signal
  • If so, Buy
  • Store the fact that I bought this ticker (such as in a portfolio object)

  • Generate a Sell signal
  • Do I already own it (i.e. check the portfolio)
  • If not, discard Sell signal
  • If so, Sell, and delete ticker from the portfolio
Even if all this required a bit more coding.

What I have learned from perusing the Amibroker forums is "Exploration is not Backtesting". Backtesting has additional functionality not present in Exploration.

As per replies above, I'm not going to worry about this anymore.

Thanks for all the replies. Much appreciated.
 
I have that in my code.

I wish Explore could be coded like:

  • Generate a Buy signal
  • Do I already own it?
  • If so, do I allow pyramiding?
  • If not, discard Buy signal
  • If so, Buy
  • Store the fact that I bought this ticker (such as in a portfolio object)

  • Generate a Sell signal
  • Do I already own it (i.e. check the portfolio)
  • If not, discard Sell signal
  • If so, Sell, and delete ticker from the portfolio
Even if all this required a bit more coding.

What I have learned from perusing the Amibroker forums is "Exploration is not Backtesting". Backtesting has additional functionality not present in Exploration.

As per replies above, I'm not going to worry about this anymore.

Thanks for all the replies. Much appreciated.
good: more precisely I use:
Code:
//to allow exrem to work properly in backtest
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
 
Top