Help with MA mean Reversion strategy - futures io
futures io futures trading



Help with MA mean Reversion strategy


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 4 posts (1 thanks)
    2. looks_two Rosenberg12 with 4 posts (0 thanks)
    3. looks_3 Sharon9999 with 1 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 768 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 8 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Help with MA mean Reversion strategy

(login for full post details)
  #1 (permalink)
Malmö,skåne,sweden
 
 
Posts: 4 since Jun 2017
Thanks: 0 given, 0 received

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, "

Reply With Quote

Can you help answer these questions
from other members on futures io?
Work with historical tcks data on MUltichart NET PowerLa …
MultiCharts
Reading A set of Trading Signals
EasyLanguage Programming
Which kind of Blockvolume is visible? - order processing
Emini and Emicro Index
NT8 indicator to simulate a Funding Evaluation where to …
NinjaTrader
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Selling Options on Futures?
109 thanks
Battlestations: Show us your trading desks!
104 thanks
Rank your Futures vs Stocks trading priority
54 thanks
Want your NinjaTrader indicator created, free?
26 thanks
Whats this confusion with margins?
23 thanks
 
(login for full post details)
  #3 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received


Rosenberg12,

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.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #4 (permalink)
Malmö,skåne,sweden
 
 
Posts: 4 since Jun 2017
Thanks: 0 given, 0 received

Bellow is what i have got so far. Tt is the part in condition1 where i have only made % that i am not sure how to solve

inputs: Price( Close ), SlowLength( 5 ), fastLength (2) ;
variables: var1( 0 ), var2( 0 ), var3 (0) ;

var1 = Average( close , SlowLength );
var2= Average( close , fastLength );
// var3 = (var1 - var2)/100 ;

condition1= var2 is 3 % or more from var1 :



If condition1 then buy this bar on close ;



IF barssinceentry = 3 then sell this bar on close;

Reply With Quote
 
(login for full post details)
  #5 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

Rosenberg12,

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.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #6 (permalink)
Malmö,skåne,sweden
 
 
Posts: 4 since Jun 2017
Thanks: 0 given, 0 received

Hellow

Bellow is the code i came up with not sure if it is correct

inputs: Price( Close ), SlowLength( 5 ), fastLength (2) ;
variables: var2( 0 ), var1( 0 ), var3 (0) ;

var1 = Average( close , SlowLength );
var2= Average( close , fastLength );
var3= ((var1-var2)/var1)*100 ;


condition1= var3 >=3;


If condition1 then buy this bar on close ;

condition2= var2 > var1;

if condition2 then sell this bar on close ;

Reply With Quote
 
(login for full post details)
  #7 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

Hi Rosenberg12,

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.

Regards,

ABCTG


Rosenberg12 View Post
Hellow

Bellow is the code i came up with not sure if it is correct

inputs: Price( Close ), SlowLength( 5 ), fastLength (2) ;
variables: var2( 0 ), var1( 0 ), var3 (0) ;

var1 = Average( close , SlowLength );
var2= Average( close , fastLength );
var3= ((var1-var2)/var1)*100 ;


condition1= var3 >=3;


If condition1 then buy this bar on close ;

condition2= var2 > var1;

if condition2 then sell this bar on close ;


Follow me on Twitter Reply With Quote
 
(login for full post details)
  #8 (permalink)
Malmö,skåne,sweden
 
 
Posts: 4 since Jun 2017
Thanks: 0 given, 0 received


Sharon9999 View Post
To prevent division by 0, you might change

var3= ((var1-var2)/var1)*100 ;

to

var3= ((var1-var2)/(var1+0.00000001))*100 ;

Thansk Sharon I will try this

Reply With Quote
 
(login for full post details)
  #9 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

Rosenberg12,

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).

 
Code
if var1 <> 0 then
   var3= ((var1-var2)/(var1))*100 ;
else //use an alternative  calculation
   var3= ((var1-var2)/(var1+0.00000001))*100 ;
Regards,

ABCTG


Rosenberg12 View Post
Thansk Sharon I will try this


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Help with MA mean Reversion strategy


Last Updated on February 13, 2019


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts