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)
I need help to program a part of a strategy in easy language. The part I need help with is how to calculate the % difference between 2 SMA. Below is copy from the strategy in text
Thanks
"when the 2 period moving average begins to move away from the 5 period moving average it’s analogous to a jaw being opened. Once the gap between the two moving averages exceeds 3% an entry condition occurs, "
Can you help answer these questions from other members on NexusFi?
welcome to futures.io. Your code has access to the average values, so you should be able to compute the percentage the faster SMA is above/below the slower SMA using math. You might want to post the code that you have, so others can point you in the right direction.
Then you can monitor the percentage and either allow an entry when the difference is > X % or only on the bars where the difference crosses over X.
computing the percentage difference between two averages is the same as for example computing the percentage difference between two stock prices or any two values for that matter.
You could compute it as:
( Fast Average - Slow Average ) / Slow Average
To make your programming life easier I would suggest using meaningful variable names, as this will make your code much easier to read.
a good way to check if the code is doing what you have in mind is to use the "Print" reserved word to check the internal values within your code. This can be very helpful in understanding what the code does.
Alternatively you could convert part of your logic into an indicator and plot the percentage that you computed on the same chart as the strategy is applied to.
you could still run into a division by zero error in the unlikely case that var1 = -0.00000001. A good coding practice within Easylanguage is to check the denominator before every division to make sure that it's not zero. In case it is, you can use an alternative value then (or do nothing and have the variable keep its current value).