Results 1 to 9 of 9
 0 Attachment(s)    

Thread: EA Coding

  1. #1

    Default EA Coding

    Hello everyone,
    I'm kind of new to EA.
    I would like to find out where i can learn how to write an EA.
    Should i be using the MetaEditor to write them?
    How can i do a test, i know there's this thing called Strategy Tester in MT4 but sometimes when i run certain EA that i got from here, i can't see any results.
    It's as if the EA doesn't do anything. I'm unsure if i got the steps wrong or is the EA corrupted.
    When i load the EA in to my chart, i read somewhere i should see a smiley face... but i see a sad one. Is this right?

    I just would like to learn how to write my own EA as i want to back test a strategy that i'm thinking of.

    Please help me.
    Thank You.

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    25

    Default

    Here you can learn MQL4:

    MQL4 Tutorial

  3. #3

    Default Thank You

    Thank You K-B.
    Very much appreciated.

  4. #4

    Default Funyoo, when you get a moment please .....

    ..... I'm stuck on a line of code and wonder if either you or somebody else can help me please.

    This block of code is being used within an EA to process orders in the account history.

    Code:
    // --- Process Closed Orders
    
      while (Closed_Order_Total > PosC)
       {
        if (OrderSelect(PosC,SELECT_BY_POS,MODE_HISTORY))
         {
          if(OrderType() == OP_BUY) {Dir = 1;}
          if(OrderType() == OP_SELL) {Dir = -1;}
          
          string OS = OrderSymbol();
          double OP = OrderProfit()+OrderSwap()+OrderCommission();
    //      double Pips_Won = Dir * (OrderClosePrice()-OrderOpenPrice())/Point;
          double Pips_Won = Dir * (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OS,MODE_POINT);
          datetime TradeTime = MathAbs(OrderCloseTime() - OrderOpenTime());
    
          int    Magic = OrderMagicNumber();
          
          if (OS == Pair_A && Magic == Magic_A) {OT_Pair_A++; OP_Pair_A = OP_Pair_A+OP; TradeTime_Pair_A=TradeTime_Pair_A+TradeTime; Pips_Won_Pair_A=Pips_Won_Pair_A+Pips_Won; if(OP>=0){OW_Pair_A++; WT_Pair_A = WT_Pair_A+OP;} if(OP<0){OL_Pair_A++; LT_Pair_A = LT_Pair_A+OP;}}
          if (OS == Pair_B && Magic == Magic_B) {OT_Pair_B++; OP_Pair_B = OP_Pair_B+OP; TradeTime_Pair_B=TradeTime_Pair_B+TradeTime; Pips_Won_Pair_B=Pips_Won_Pair_B+Pips_Won; if(OP>=0){OW_Pair_B++; WT_Pair_B = WT_Pair_B+OP;} if(OP<0){OL_Pair_B++; LT_Pair_B = LT_Pair_B+OP;}}
          if (OS == Pair_C && Magic == Magic_C) {OT_Pair_C++; OP_Pair_C = OP_Pair_C+OP; TradeTime_Pair_C=TradeTime_Pair_C+TradeTime; Pips_Won_Pair_C=Pips_Won_Pair_C+Pips_Won; if(OP>=0){OW_Pair_C++; WT_Pair_C = WT_Pair_C+OP;} if(OP<0){OL_Pair_C++; LT_Pair_C = LT_Pair_C+OP;}}
          if (OS == Pair_D && Magic == Magic_D) {OT_Pair_D++; OP_Pair_D = OP_Pair_D+OP; TradeTime_Pair_D=TradeTime_Pair_D+TradeTime; Pips_Won_Pair_D=Pips_Won_Pair_D+Pips_Won; if(OP>=0){OW_Pair_D++; WT_Pair_D = WT_Pair_D+OP;} if(OP<0){OL_Pair_D++; LT_Pair_D = LT_Pair_D+OP;}}
          if (OS == Pair_E && Magic == Magic_E) {OT_Pair_E++; OP_Pair_E = OP_Pair_E+OP; TradeTime_Pair_E=TradeTime_Pair_E+TradeTime; Pips_Won_Pair_E=Pips_Won_Pair_E+Pips_Won; if(OP>=0){OW_Pair_E++; WT_Pair_E = WT_Pair_E+OP;} if(OP<0){OL_Pair_E++; LT_Pair_E = LT_Pair_E+OP;}}
          if (OS == Pair_F && Magic == Magic_F) {OT_Pair_F++; OP_Pair_F = OP_Pair_F+OP; TradeTime_Pair_F=TradeTime_Pair_F+TradeTime; Pips_Won_Pair_F=Pips_Won_Pair_F+Pips_Won; if(OP>=0){OW_Pair_F++; WT_Pair_F = WT_Pair_F+OP;} if(OP<0){OL_Pair_F++; LT_Pair_F = LT_Pair_F+OP;}}
          if (OS == Pair_G && Magic == Magic_G) {OT_Pair_G++; OP_Pair_G = OP_Pair_G+OP; TradeTime_Pair_G=TradeTime_Pair_G+TradeTime; Pips_Won_Pair_G=Pips_Won_Pair_G+Pips_Won; if(OP>=0){OW_Pair_G++; WT_Pair_G = WT_Pair_G+OP;} if(OP<0){OL_Pair_G++; LT_Pair_G = LT_Pair_G+OP;}}
          if (OS == Pair_H && Magic == Magic_H) {OT_Pair_H++; OP_Pair_H = OP_Pair_H+OP; TradeTime_Pair_H=TradeTime_Pair_H+TradeTime; Pips_Won_Pair_H=Pips_Won_Pair_H+Pips_Won; if(OP>=0){OW_Pair_H++; WT_Pair_H = WT_Pair_H+OP;} if(OP<0){OL_Pair_H++; LT_Pair_H = LT_Pair_H+OP;}}
          if (OS == Pair_I && Magic == Magic_I) {OT_Pair_I++; OP_Pair_I = OP_Pair_I+OP; TradeTime_Pair_I=TradeTime_Pair_I+TradeTime; Pips_Won_Pair_I=Pips_Won_Pair_I+Pips_Won; if(OP>=0){OW_Pair_I++; WT_Pair_I = WT_Pair_I+OP;} if(OP<0){OL_Pair_I++; LT_Pair_I = LT_Pair_I+OP;}}
          if (OS == Pair_J && Magic == Magic_J) {OT_Pair_J++; OP_Pair_J = OP_Pair_J+OP; TradeTime_Pair_J=TradeTime_Pair_J+TradeTime; Pips_Won_Pair_J=Pips_Won_Pair_J+Pips_Won; if(OP>=0){OW_Pair_J++; WT_Pair_J = WT_Pair_J+OP;} if(OP<0){OL_Pair_J++; LT_Pair_J = LT_Pair_J+OP;}}
          
          
         }
        PosC++;
        }
    I am satisfied that the code is working properly and I am able to carry out the remaining processes of the EA with one exception.

    When I use the line that I have rem'd out and highlighted in red, the EA works but, because it uses the value of Point for the symbol that the EA is attached to, this is no good for processing symbols other than the current symbol unless their Point happens to be the same.

    When I substitute the red line for the line that I have highlighted in blue using the MarketInfo() function, the EA returns a Zero Divide error message. I can't see what I am doing wrong.

    Can somebody help please, as this is driving me crazy.

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

    Default

    Quote Originally Posted by jezzer1961 View Post
    ..... I'm stuck on a line of code and wonder if either you or somebody else can help me please.

    This block of code is being used within an EA to process orders in the account history.

    I am satisfied that the code is working properly and I am able to carry out the remaining processes of the EA with one exception.

    When I use the line that I have rem'd out and highlighted in red, the EA works but, because it uses the value of Point for the symbol that the EA is attached to, this is no good for processing symbols other than the current symbol unless their Point happens to be the same.

    When I substitute the red line for the line that I have highlighted in blue using the MarketInfo() function, the EA returns a Zero Divide error message. I can't see what I am doing wrong.

    Can somebody help please, as this is driving me crazy.
    Hi jezzer1961,

    Try this :

    Code:
    double Pips_Won = Dir * NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),Digits)/NormalizeDouble(MarketInfo(OS,MODE_POINT),Digits);

  6. #6

    Default

    Thanks for your suggestion, Funyoo, but it still returns the Zero Divide error unfortunately.

    For that to happen, it suggests that the MarketInfo() function itself is returning a zero value and I don't understand why.

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

    Default

    Quote Originally Posted by jezzer1961 View Post
    Thanks for your suggestion, Funyoo, but it still returns the Zero Divide error unfortunately.

    For that to happen, it suggests that the MarketInfo() function itself is returning a zero value and I don't understand why.
    Strange.

    Then, you have not a lot of choices, you have to add a lots of conditions.

    double PPoint;

    if(Symbol()="EURUSD")PPoint=0.0001;
    if(...

    double Pips_Won = Dir * (OrderClosePrice()-OrderOpenPrice())/PPoint;

  8. #8

    Default

    It certainly is strange, Funyoo, and thanks for your other suggestion. I didn't really want to go that route though if I could avoid it.

    I'd like to be able to resolve it an easier way if possible, but I'm lacking ideas at the moment.

    Are there any other suggestions or an explanation please?

  9. #9

    Default

    Well I knew there was an easy solution.

    Replacing Pips_Won with its formula in each of the 10 lines of conditions gets it to work as intended. I don't really understand why this should be, but at least I can move on again.

    Thanks for your help, Funyoo.

Similar Threads

  1. help with coding.
    By pelm in forum Ideas for expert advisors
    Replies: 1
    Last Post: 07-17-2013, 04:49
  2. Coding using MA
    By 100pipsv3.1[1]ea in forum MQL programming
    Replies: 0
    Last Post: 06-01-2012, 17:30
  3. Coding Help
    By Pheniox in forum MQL programming
    Replies: 1
    Last Post: 01-19-2012, 12:33
  4. Anyone still coding?
    By Equi in forum Ideas for expert advisors
    Replies: 2
    Last Post: 01-17-2012, 15:12
  5. Need Help Coding Help
    By andrewbisme31 in forum Commercial expert advisors
    Replies: 0
    Last Post: 01-14-2012, 14:20

Tags for this Thread

coding, color, ea works, eurusd, how to, learn, magic, mql, mt4, strategy, test, thank you

Posting Permissions

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