Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
How to use if() function to check value returned from cross() function
Dear all, I am a beginner to Amibroker & AFL.
Actually, I want to implement the following logic:
I want to generate the buy signal when both EMA and MACD shows crossover but they need not to happen on the same day (e.g. EMA shows crossover today, and 3 days later, MACD shows crossover, I still buy the stock)
The following gives more details:
When 10 days EMA crossovers 20 days EMA, remember this as part of the buying signal by assigning TRUE to a variable.
Then, look at MACD, if the MACD line crossovers signal line, remember this buying signal by assigning TRUE to another variable.
After that, check both buying signal. If both are TRUE, buy the stock.
I would like to use if() function to check value returned from cross() function. However, an error occurs. I know cross() function returns an array with the value of true/flase or 1/0 and may be that's why causing the error.
Can anyone tell me how to extra the "true" or "false" value from cross() function and can be checked by if() function?
Thank you very much!
Can you help answer these questions from other members on NexusFi?
I think you have to use "IIF" instruction instead of "if"
"IIf" function deals array, "if" deals variables.
See the manual for IIF function or post your TS.
Your code is using barindex. So it will work in EOD time frame only. If he wants to use intraday with day delay then this code should work. Not tested.