Results 1 to 6 of 6
 0 Attachment(s)    

Thread: Add a moving average filter

  1. #1
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default Add a moving average filter

    In the extern parameters, add :

    Code:
    extern bool MAFilter=false;//|-------------------moving average filter
    extern int MAPeriod=20;//|-----------------------ma filter period
    extern int MAMethod=0;//|------------------------ma filter method
    extern int MAPrice=0;//|-------------------------ma filter price
    In the start body, add :

    Code:
    //|---------moving average filter
    
    double MAF=iMA(Symbol(),0,MAPeriod,0,MAMethod,MAPrice,i);
    
    bool MABUY=false;bool MASELL=false;
    
    if((MAFilter==false)||(MAFilter&&Bid>MAF))MABUY=true;
    if((MAFilter==false)||(MAFilter&&Ask<MAF))MASELL=true;
    In the buy conditions, add :

    Code:
    &&MABUY
    In the sell conditions, add :

    Code:
    &&MASELL

  2. #2
    Junior Member
    Join Date
    May 2009
    Posts
    5

    Default It's not working

    I get "i" is undefined error when compiling.

    I've been trying to code this into Gartley v103 without any success.

    How can I make 3 or 4 MAs Like this?


    Do I define them as MAF1, MAF2, MAF3, MAF4?

    I would really like to learn more of this programming.

    thanks for the reply!

  3. #3
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by Disciple2 View Post
    I get "i" is undefined error when compiling.

    I've been trying to code this into Gartley v103 without any success.

    How can I make 3 or 4 MAs Like this?


    Do I define them as MAF1, MAF2, MAF3, MAF4?

    I would really like to learn more of this programming.

    thanks for the reply!
    Hi Disciple2,

    You have to replace i by 1.

    See in this code for the 4 MAs : Momo Counts Scalper

  4. #4

    Question

    Quote Originally Posted by funyoo View Post
    In the extern parameters, add :

    Code:
    extern bool MAFilter=false;//|-------------------moving average filter
    extern int MAPeriod=20;//|-----------------------ma filter period
    extern int MAMethod=0;//|------------------------ma filter method
    extern int MAPrice=0;//|-------------------------ma filter price
    In the start body, add :

    Code:
    //|---------moving average filter
    
    double MAF=iMA(Symbol(),0,MAPeriod,0,MAMethod,MAPrice,i);
    
    bool MABUY=false;bool MASELL=false;
    
    if((MAFilter==false)||(MAFilter&&Bid>MAF))MABUY=true;
    if((MAFilter==false)||(MAFilter&&Ask<MAF))MASELL=true;
    In the buy conditions, add :

    Code:
    &&MABUY
    In the sell conditions, add :

    Code:
    &&MASELL
    Thanks a lot for teaching us how to code, I have a question:

    BID = price to sell
    ASK = price to buy

    So, why do we need to check the BID price to have a valid Buy signal and the opposite(ASK) for the sell signal?

    double MAF=iMA(Symbol(),0,MAPeriod,0,MAMethod,MAPrice,i); - Why Symbol() and not NULL?
    i=1 - previous bar?

    Sorry for so many questions, but I am just trying to have a better understanding of the code.
    Last edited by szmvscla; 06-11-2009 at 02:57.

  5. #5

    Default

    1. You can use Symbol() or NULL, it doesn't matter. Either way it is the CURRENT symbol.
    2. In this example i comes in the place of shift, meaning that it will use the previous bar.
    3. It doesn't matter if you check MA against Bid or Ask. The difference is only a few pips anyway. You can use Close[i] to keep the code consistent.
    FXCode Inc.
    Expert Advisor Developer

  6. #6

    Thumbs up

    Quote Originally Posted by FXCode View Post
    1. You can use Symbol() or NULL, it doesn't matter. Either way it is the CURRENT symbol.
    2. In this example i comes in the place of shift, meaning that it will use the previous bar.
    3. It doesn't matter if you check MA against Bid or Ask. The difference is only a few pips anyway. You can use Close[i] to keep the code consistent.
    Thanks a lot!

Similar Threads

  1. Replies: 0
    Last Post: 07-21-2014, 11:18
  2. EA WITH ONLY ONE MOVING AVERAGE
    By afoson in forum Trading discussion
    Replies: 0
    Last Post: 07-09-2010, 19:09
  3. Moving average EA
    By Rascacio in forum Expert advisors backtesting
    Replies: 3
    Last Post: 02-16-2010, 18:46
  4. Moving Average EA
    By best2004 in forum Ideas for expert advisors
    Replies: 11
    Last Post: 12-10-2009, 20:15
  5. Moving average v2
    By funyoo in forum Expert advisors backtesting
    Replies: 5
    Last Post: 08-12-2009, 20:39

Tags for this Thread

add, average, backtesting, expert, how to, learn, moving average, programming, scalper, signal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •