Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Need help with simple EA

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    2

    Default Need help with simple EA

    I am trying an idea I thought of for an EA. It is a martingale that increases TP and SL instead of position size. So, if the first position is TP 10 and SL 10, and it hits the SL, then the second position is TP 20 and SL 20. Next is 40, then 80, and so on. But position size remains constant. Here is code I have, but it is not closing the positions in strategy tester. Any help would be appreciated.

    Code:
    #property copyright "CJE 2011"
    
    extern int     TP          = 100;
    extern int     SL          = 100;
    extern int     Direction   = 1;
    extern double  Lots        = 0.01;
    extern int     mm          = 0;
    
    extern int     MagicNumber = 962245;
    
    //int ticket;
    
    double         dTarget     = 0;
    double         dReverse    = 0;a
    int            iTradeDir   = 0;
    int            iLosses     = 1;
    
    int            slippage    = 3;
    int            ticket      = 0;
    double         lotsi       = 0;
    double         mylotsi     = 0;
    bool           bInTrade    = FALSE;
    string         CurrentBuild= "v1.02";
    
    int init(){return(0);}
    int deinit(){return(0);}
    
    int start()
    {
       int cnt = 0;
    
    //1. Money management & trade sizing
       if (mm != 0)
          lotsi = MathRound(AccountBalance() * 0.0002) / 100;
       else
          lotsi = Lots;
       mylotsi = .001;
       if (mylotsi > 100) mylotsi = 100;
    
       if  (bInTrade == FALSE)
       {
       if   (iTradeDir == 0)
          {
             dTarget = Bid + TP * Point * iLosses;
             dReverse = Bid - SL * Point * iLosses;
             ticket = OrderSend(Symbol(), OP_BUY, mylotsi, Ask, slippage, 0, 0, NULL, MagicNumber, 0, White);
             bInTrade = TRUE;
             Alert("Open #",ticket,"  InTrade = ",bInTrade);
             ObjectCreate("Target", OBJ_HLINE, 0, 0, dTarget);
             ObjectCreate("Reverse", OBJ_HLINE, 0, 0, dReverse);
          }
          else
          {
             dTarget = Ask - TP * Point * iLosses;
             dReverse = Ask + SL * Point * iLosses;
             ticket = OrderSend(Symbol(), OP_SELL, mylotsi, Bid, slippage, 0, 0, NULL, MagicNumber, 0, Red);
             bInTrade = TRUE;
             Alert("Open #",ticket,"  InTrade = ",bInTrade);
             ObjectCreate("Target", OBJ_HLINE, 0, 0, dTarget);
             ObjectCreate("Reverse", OBJ_HLINE, 0, 0, dReverse);
             iTradeDir = 1;
          }
       }
       
       if (bInTrade == TRUE)
       {
       if (iTradeDir == 0)
       {
          if (Bid <= dReverse)
          {
             OrderClose(ticket, OrderLots(), OrderClosePrice(), slippage, White);
             bInTrade = FALSE;
             Alert("Close #",ticket,"  InTrade = ",bInTrade);         
             ObjectDelete("Target");
             ObjectDelete("Reverse");
             iLosses ++;
             iTradeDir = 1;
          }
          if (Bid >= dTarget)
          {
             OrderClose(ticket, OrderLots(), OrderClosePrice(), slippage, White);
             bInTrade = FALSE;
             Alert("Close #",ticket,"  InTrade = ",bInTrade);         
             ObjectDelete("Target");
             ObjectDelete("Reverse");
             iLosses = 1;
             iTradeDir = 0;
          }   
       }
       }
       
       if (bInTrade == TRUE)
       {
       if (iTradeDir == 1)
       {
          if (Ask >= dReverse)
          {
             OrderClose(ticket, OrderLots(), OrderClosePrice(), slippage, Red);
             bInTrade = FALSE;
             Alert("Close #",ticket,"  InTrade = ",bInTrade);         
             ObjectDelete("Target");
             ObjectDelete("Reverse");
             iLosses ++;
             iTradeDir = 0;
          }
          if (Ask <= dTarget)
          {
             OrderClose(ticket, OrderLots(), OrderClosePrice(), slippage, Red);
             bInTrade = FALSE;
             Alert("Close #",ticket,"  InTrade = ",bInTrade);         
             ObjectDelete("Target");
             ObjectDelete("Reverse");
             iLosses = 1;
             iTradeDir = 1;
          }      
       }}
       Comment(
               "  Direction = ", iTradeDir,
               "\nLots = ", mylotsi,
               "  Losses = ", iLosses,
               "\nBuild: ", CurrentBuild);
       
       return(0);
    }

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

    Default

    I can help you please send me a pm with your contact details.

Similar Threads

  1. Simple hi-lo ea
    By checkmail in forum Ideas for expert advisors
    Replies: 0
    Last Post: 11-22-2012, 14:27
  2. Simple EA
    By Shahram in forum Ideas for expert advisors
    Replies: 0
    Last Post: 05-27-2011, 16:16
  3. Simple 14 SMA system
    By julz in forum Ideas for expert advisors
    Replies: 9
    Last Post: 07-08-2010, 20:21
  4. Simple Rsi Ea
    By Cyrillic in forum Ideas for expert advisors
    Replies: 2
    Last Post: 04-21-2010, 16:24
  5. REQ Simple EA
    By 626mx in forum Ideas for expert advisors
    Replies: 0
    Last Post: 09-07-2009, 04:50

Tags for this Thread

100, 2011, closing, magic, martingale, money, simple, slippage, strategy

Posting Permissions

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