Download MetaTrader 5

My EA didn't open the second condition (Buy condition)

To add comments, please log in or register
ThanhTran
10
ThanhTran  
//+------------------------------------------------------------------+
//                        DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 
//
//                   Copyright ©2011, ForexEAdvisor.com
//                 ForexEAdvisor Strategy Builder version 0.2
//                        http://www.ForexEAdvisor.com 
//
// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2 
// on: 6/29/2017 3:29:23 AM
// Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty
// or liability obligations to you of any kind. 
// UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,
// FOR ANY LOSS OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR
// ECONOMIC LOSS OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,
// EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR 
// FOREXEADVISOR STRATEGY BUILDER     
// Because software is inherently complex and may not be completely free of errors, you are 
// advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder
// license for a complete understanding of ForexEAdvisor' disclaimers.  
// USE THIS EA AT YOUR OWN RISK. 
//  
// Before adding this expert advisor to a chart, make sure there are NO
// open positions.
//                      DO NOT DELETE THIS HEADER
//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 
//+------------------------------------------------------------------+
extern int MagicNumber=10001;
extern int BarSize=100;
extern int MidSize=50;
extern double Lots =0.1;
extern double StopLoss=0;
extern double TakeProfit=10;
extern int TrailingStop=100;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}
bool NewBar()
{
        static datetime OldTime = 0;
        if(OldTime < Time[0])
        {
                OldTime = Time[0];
                return(true);
        }
        else
        {
                return(false);
        }
}

int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  int TFPP=PERIOD_CURRENT; 
  double open2 ,close2, high2, low2,
  open1 ,close1 ,high1, low1,
  open3 ,close3 ,high3 ,low3,
  point ,barsize1 ,bar1up ,bar1down ,bar2up ,bar2down ,bar3up ,bar3down;
point=MarketInfo(Symbol(),MODE_POINT);
  
open1=NormalizeDouble(iOpen(Symbol(),TFPP,1),Digits);
open2=NormalizeDouble(iOpen(Symbol(),TFPP,2),Digits);
open3=NormalizeDouble(iOpen(Symbol(),TFPP,3),Digits);

close1=NormalizeDouble(iClose(Symbol(),TFPP,1),Digits); 
close2=NormalizeDouble(iClose(Symbol(),TFPP,2),Digits); 
close3=NormalizeDouble(iClose(Symbol(),TFPP,3),Digits); 
      
high1=NormalizeDouble(iHigh(Symbol(),TFPP,1),Digits);
high2=NormalizeDouble(iHigh(Symbol(),TFPP,2),Digits);
high3=NormalizeDouble(iHigh(Symbol(),TFPP,3),Digits);


low1=NormalizeDouble(iLow(Symbol(),TFPP,1),Digits);
low2=NormalizeDouble(iLow(Symbol(),TFPP,2),Digits);
low3=NormalizeDouble(iLow(Symbol(),TFPP,3),Digits);

barsize1=NormalizeDouble(((high1-low1)/point),0);

bar1up=NormalizeDouble(((close1-open1)/point),0);
bar1down=NormalizeDouble(((open1-close1)/point),0);
bar2up=NormalizeDouble(((close2-open2)/point),0);
bar2down=NormalizeDouble(((open2-close2)/point),0);
bar3up=NormalizeDouble(((close3-open3)/point),0);
bar3down=NormalizeDouble(((open3-close3)/point),0);
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  
     int result=0;
     if( (TotalOrdersCount()==0) &&
     (NewBar()) && (barsize1>BarSize) && 
     (open1>close1) && (open2<close2) && (open3<close3) && (bar1down>MidSize) && (bar2up>MidSize) && (bar3up>MidSize) &&
     (high1>=open1) && (low1<=close1) && 
     (low1<low2) &&
     (high2>=close2) && (low2<=open2) && 
     (high1<high2))
     {
        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        
     }
     if( (TotalOrdersCount()<1) &&
     (NewBar()) && (barsize1>BarSize) && 
     (open1<close1) && (open2>close2) && (open3>close3) && (bar1up>MidSize) && (bar2down>MidSize) && (bar3down>MidSize) &&
     (high1>=close1) && (low1<=open1) && 
     (low1>low2) &&
     (high2>=open2) && (low2<=close2) && 
     (high1>high2))
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
       
     }
  
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}



in the first time i tested ,the EA only open Buy order and didn't open Sell order ,then i write the Buy condition below the Sell condition ... And only have Sell order 

my English very bad , for give me ^^! , please help me fix my EA , thanks !!!

whroeder1
17093
whroeder1  
// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2
  • We hate EA builder
  • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
  • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
  • EA builder makes bad code counting up while closing multiple orders.
  • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
  • EA builder makes bad code Not adjusting for 4/5 digit brokers, TP/SL and slippage.
  • EA builder makes bad code not adjusting for ECN brokers.
  • EA builder makes bad code not checking return codes.
  • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)
To add comments, please log in or register