When I have this piece of code, it plots on the chart,
Buy = O>MA(C,20); ;
Sell = O<MA(C,20);
but when I add more to it, like this, `Buy = O>MA(C,20) OR O>MA(C,8);
Sell = O<MA(C,20)-1;
The -1 in second line caused the problem with plotting. Can anyone tell me why?
@Veasnar, you will have to think about your logic here a bit more.
Your Sell Condition should evaluate to a True or False.
Your Sell is trying to do subtraction from a Logic value, so you will get an error.
Your Buy condition is TWO logical tests that are "OR"ed together. That is a Logical OR so it is allowed.
Not sure what you are after with the "-1" in the Sell, so you will have to define it better, and see if you can come up with a condition expression.
Thanks for your response, Snoopy.pa30,
"-1" is for yesterday or one day after it happened.
BTW, there is no error with compilation.
@Veasnar of course there is no error with compilation. You entered a mathematical equation. What you need is to familiar with the
Ref function to refer to yesterday (or previous bar's)
If you are uncertain about what your calculations are creating then create an Exploration and see what all your variables are doing.
Continuing the discussion from
How do I learn AFL?:
Many new users with zero programming experience struggle when their formula works incorrectly. Here are few hints that everyone should use to make finding errors easier.
First of all: you have to get insight into what the formula is actually doing, not what you think it does.
Typically new user has no idea what is happening inside. Pretty often you make an assumption that things work one way but in fact they work differently. Do not assume t…
But also even though you have been a member of the forum for 10 months, you do not appear to have gone through some important steps in learning afl. I suggest you spend some significant time reading and coding what you find as you work your way through the resources listed in this forum post,
Thanks for your advice and suggestion, portfoliobuilder.