Results 1 to 2 of 2

Thread: EA Error

  1. #1
    tkuan77 is offline Newbie
    Join Date
    Jun 2012
    Posts
    10

    Default EA Error

    Hi guys, I am having some error with my EA codes and would like you to seek help here. I have done some editing previously however, my EA still only opens 1 trade and the stop executing new trades can some1 point me in the right direction here?

    my strategy works in such a way that if SMA 20 crosses SMA 50 downwards (downtrend) the system will only open trade when LWMA 10 crosses LWMA 20 downwards and ignoring the crosses upwards.

    the reverse is the same for when SMA 20 crosses SMA 50 upwards for a uptrend.

    Thanks

    //--- input parameters
    extern double TakeProfit=1000.0;
    extern double Lots=0.01;
    extern double StopLoss=1500.0;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //----
    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //----
    //----
    return(0);
    }
    int mainCrossed (double mainline1 , double mainline2)
    {
    static int mainlast_direction = 0;
    static int maincurrent_dirction = 0;
    if(mainline1>mainline2)maincurrent_dirction = 1; //main up
    if(mainline1<mainline2)maincurrent_dirction = 2; //main down
    if(maincurrent_dirction != mainlast_direction) //main changed
    {
    mainlast_direction = maincurrent_dirction;
    return (mainlast_direction);
    }
    else
    {
    return (0);
    }
    }


    int Crossed (double line1 , double line2)
    {
    static int last_direction = 0;
    static int current_dirction = 0;
    if(line1>line2)current_dirction = 1; //up
    if(line1<line2)current_dirction = 2; //down
    if(current_dirction != last_direction) //changed
    {
    last_direction = current_dirction;
    return (last_direction);
    }
    else
    {
    return (0);
    }
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start()
    {
    //----
    int cnt, ticket, total, downcounter, upcounter;
    double shortEma, longEma, mainshortEma, mainlongEma;
    if(Bars<100)
    {
    Print("bars less than 100");
    return(0);
    }
    if(TakeProfit<10)
    {
    Print("TakeProfit less than 10");
    return(0); // check TakeProfit
    }
    shortEma = iMA(NULL,0,10,0,MODE_LWMA,PRICE_CLOSE,0);
    longEma = iMA(NULL,0,20,0,MODE_LWMA,PRICE_CLOSE,0);

    mainshortEma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
    mainlongEma = iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0);

    int mainisCrossed = mainCrossed (mainshortEma,mainlongEma);

    int isCrossed = Crossed (shortEma,longEma);


    total = OrdersTotal();

    downcounter = 1;
    upcounter = 1;



    if(mainisCrossed == 2)
    {
    downcounter++;


    if(total < 1 && isCrossed == 2 && downcounter > 1)
    {
    ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+S topLoss*Point,
    Bid-TakeProfit*Point,"My EA",12345,0,Red);


    }
    return(0);
    }
    return(0);



    if(mainisCrossed == 1)
    {
    upcounter++;


    if(total < 1 && isCrossed == 1 && upcounter > 1)
    {
    ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,
    Ask+TakeProfit*Point,"My EA",12345,0,Green);

    }
    return(0);

    }
    return(0);



    }
    //+------------------------------------------------------------------+


  2. #2
    goldylox's Avatar
    goldylox is offline Junior Member
    Join Date
    Aug 2011
    Posts
    289
    It works for me. it does not open alot of orders because you have it set to a high stoploss and takeprofit.

    Code:
    if(maincurrent_dirction != mainlast_direction) //main changed
    //{
    //mainlast_direction = maincurrent_dirction;
    Why not just return maincurrent_dirction?

    Code:
       double ma=iMA(NULL,0,maperiod1,0,mamethod,maprice,shift);
       double maa=iMA(NULL,0,maperiod1,0,mamethod,maprice,shift+1);
       
       double ma2=iMA(NULL,0,maperiod2,0,mamethod,maprice,shift);
       double ma2a=iMA(NULL,0,maperiod2,0,mamethod,maprice,shift+1);
       
      
       if(ma>ma2 && maa<ma2a ) //buy;
       if(ma<ma2 && maa>ma2a ) //sell;
    You r better off doing something like this to find your MA crosses. Otherwise you will have a buy or sell order as soon as you close a trade, instead of the ma cross.

    Then you could use an opposite close?

Similar Threads

  1. fxsol - error msg
    By imemine88 in forum Newbie Island
    Replies: 2
    Last Post: 12-20-2007, 11:13 AM
  2. Trial and Error
    By traderlady in forum Newbie Island
    Replies: 4
    Last Post: 12-04-2007, 10:05 AM
  3. Know Your P's and L's error?
    By SozzledBoot in forum Bugs and Suggestions
    Replies: 0
    Last Post: 11-15-2007, 06:07 AM
  4. Error in my Expert Advisor
    By arkangel007 in forum Newbie Island
    Replies: 3
    Last Post: 09-21-2007, 06:51 AM
  5. MT4 - Trade is disabled [error] ??
    By constantijn in forum Trading Platforms and Software
    Replies: 1
    Last Post: 03-17-2007, 02:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
"You can't make an omelet without breaking eggs."
Origin Unknown