- 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).
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.
Yeah, I think I'm being too perfectionistic with Explore.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.
// 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);
}
}
That is what i use in my codeGoogle "ExRem in Amibroker". It may do what you want ?
I have that in my code.That is what i use in my code
good: more precisely I use: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)
Even if all this required a bit more coding.
- 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
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.
//to allow exrem to work properly in backtest
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Hello and welcome to Aussie Stock Forums!
To gain full access you must register. Registration is free and takes only a few seconds to complete.
Already a member? Log in here.