Help with MA mean Reversion strategy - EasyLanguage Programming | futures io social day trading
futures io futures trading


Help with MA mean Reversion strategy
Updated: Views / Replies:145 / 9
Created: by Rosenberg12 Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 100,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Help with MA mean Reversion strategy

  #1 (permalink)
Trading Apprentice
Malmö,skåne,sweden
 
Trading Experience: Beginner
Platform: Multicharts
Favorite Futures: Stocks
 
Posts: 4 since Jun 2017
Thanks: 0 given, 0 received

Help with MA mean Reversion strategy

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
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Trading Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,884 since Apr 2013
Thanks: 310 given, 1,167 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

Reply With Quote
 
  #4 (permalink)
Trading Apprentice
Malmö,skåne,sweden
 
Trading Experience: Beginner
Platform: Multicharts
Favorite Futures: Stocks
 
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;


Last edited by Rosenberg12; February 4th, 2019 at 05:22 PM.
Reply With Quote
 
  #5 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Trading Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,884 since Apr 2013
Thanks: 310 given, 1,167 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

Reply With Quote
 
  #6 (permalink)
Trading Apprentice
Malmö,skåne,sweden
 
Trading Experience: Beginner
Platform: Multicharts
Favorite Futures: Stocks
 
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
 
  #7 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Trading Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,884 since Apr 2013
Thanks: 310 given, 1,167 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 ;


Reply With Quote
 
  #8 (permalink)
Trading Apprentice
Pecs, Hungary
 
Trading Experience: Beginner
Platform: Tradestation
Favorite Futures: ES, CL, GC
 
Posts: 14 since Jun 2018
Thanks: 7 given, 6 received


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 ;

To prevent division by 0, you might change

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

to

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

Reply With Quote
 
  #9 (permalink)
Trading Apprentice
Malmö,skåne,sweden
 
Trading Experience: Beginner
Platform: Multicharts
Favorite Futures: Stocks
 
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
 
  #10 (permalink)
 Vendor: www.abctradinggroup.com 
Hamburg Germany
 
Trading Experience: Advanced
Platform: Multicharts, Tradestation
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,884 since Apr 2013
Thanks: 310 given, 1,167 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


Reply With Quote
The following user says Thank You to ABCTG for this post:

Reply



futures io > > > > > Help with MA mean Reversion strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Journal Challenge $1600 in Prizes & Free Journalytix for all participants!

February
 

Trading Resolutions for 2019 - Avoiding Mistakes w/GFF Brokers

Feb 19
 

3 Excellent Entries, and How To Automate Them w/Kevin Davey

Feb 21
 

The Driving Force Behind the Market w/Earn2Trade

Mar 5
 

TBA w/Stage5 & iSystems

Mar 12
 

TBA w/John Grady @ No BS Day Trading

Mar 19
 

Day Trading Oil Futures: Reducing Risk & Increasing Profits w/DTN IQFeed

Mar 26
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mean reversion works, but can you stand the pain? Fat Tails Psychology and Money Management 23 February 8th, 2019 05:15 PM
Help coding simple mean reversion system (C# or Ninjascript) TickedOff Elite Automated Trading 4 November 10th, 2015 12:22 PM
Mean Reversion System based on RSI Aufidius Elite Automated NinjaTrader Trading 3 April 21st, 2015 01:59 AM
Mean reversion indicator?Which to choose findev NinjaTrader 0 April 16th, 2015 02:18 PM
Reversion to Mean indicator Skidboot NinjaTrader Programming 2 April 29th, 2014 05:31 AM


Tags
average, barssinceentry, buy, code, coding, easy language, easylanguage, futures, how to, indicator, indicators, moving average, multicharts, neoticker, programming, sma, strategy, tradestation, values, variable

All times are GMT -4. The time now is 10:49 AM. (this page content is cached, log in for real-time version)

Copyright © 2019 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432 WhatsApp Business, 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
Page generated 2019-02-17 in 0.18 seconds with 13 queries on phoenix