EA HELP NEEDED

 

Hi, everybody. Had this ea but i want to opposite of that ea. When it buy i want SELL and when it sell i want BUY.

And i don't know what should i change. :(  

Help me please!!! 

 

 

 //+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+

extern int magic_number=5423343;

enum lotpick{FIXED_LOTSIZE, BALANCE_DEVIDER };

extern lotpick LOT_MODE=FIXED_LOTSIZE; 
extern double fixed_LotSize=0.1,BalanceDevider=10000; 

extern int Max_Number_of_Open_Order=1; 
extern double MAX_Spread=5; 
extern int Max_Slippage_pip_For_TakePosition=5; 

extern bool Close_position_with_oposite_signal=true; 
extern int daytgt=0;//Daily Target Profit Pip  
 


extern string note="SL/TP";
 extern int Stoploss_pip=15,TakeProfit_Pip=15; 

int  TrailingStop=0; 
int Trailling_step=0;
int Trailling_Start_from=0;
 
bool Break_even=false;
int Decreasing_StopLoss_pip=2,New_Stop_Loss=0;


extern string indi="AlSatOk";
extern int  dist2           = 21;
extern int  dist1           = 14; 


                                  
extern bool use_time_setting=false;                                  
                                  
extern bool Monday=true;
extern string Time_start1="00:30:00",Time_end1="22:30:00";
extern string Time_start2="00:30:00",Time_end2="22:30:00";
extern string Time_start3="00:30:00",Time_end3="22:30:00";
extern string Time_start3_1="00:30:00",Time_end3_1="22:30:00";

extern bool Tuesday=true;
extern string Time_start4="00:30:00",Time_end4="22:30:00";
extern string Time_start5="00:30:00",Time_end5="22:30:00";
extern string Time_start6="00:30:00",Time_end6="22:30:00";
extern string Time_start6_1="00:30:00",Time_end6_1="22:30:00";

extern bool Wednesday =true;
extern string Time_start7="00:30:00",Time_end7="22:30:00";
extern string Time_start8="00:30:00",Time_end8="22:30:00";
extern string Time_start9="00:30:00",Time_end9="22:30:00";
extern string Time_start9_1="00:30:00",Time_end9_1="22:30:00";

extern bool Thursday =true;
extern string Time_start10="00:30:00",Time_end10="22:30:00";
extern string Time_start11="00:30:00",Time_end11="22:30:00";
extern string Time_start12="00:30:00",Time_end12="22:30:00";
extern string Time_start12_1="00:30:00",Time_end12_1="22:30:00";

extern bool Friday =true;
extern string Time_start13="00:30:00",Time_end13="22:30:00";
extern string Time_start14="00:30:00",Time_end14="22:30:00";
extern string Time_start15="00:30:00",Time_end15="22:30:00";
extern string Time_start15_1="00:30:00",Time_end15_1="22:30:00";


 

 
datetime tm0=0; 

double PIP;int dg;
void init()
{  tm0=0;  
    PIP=Point();dg=1;
  if(Digits==3||Digits==5){PIP*=10;dg=10;}
  check_lasttype();
  ChartSetInteger(0,CHART_SHOW_GRID,0);
}

void OnDeinit(const int reason)
{ if(reason==REASON_PARAMETERS)day=-1;

}

double LOT;
double NR(double thelot)
{
    double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
    minilot = MarketInfo(Symbol(), MODE_MINLOT),
    lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
    double lots = lstep * MathFloor(thelot / lstep);
    lots = MathMax(MathMin(maxlots, lots), minilot);
    return (lots);
}
  
void LOTLOT( )
{
 if(LOT_MODE==BALANCE_DEVIDER){ LOT=NR(AccountBalance()/BalanceDevider); return;}
   
    LOT=fixed_LotSize; 
    
}  

  int day=-1;
void  OnTick()
{  
  bool reach=daily_target_reached();
  if(reach){CUT(0);CUT(1);day=DayOfWeek();}
  
  
  
  if(day==DayOfWeek())return;
  counting();
  
  if (buy==0)cutbuy=0;
  if (sell==0)cutsell=0;
  if(cutbuy)CUT(0);
  if(cutsell)CUT(1);
  
if(use_time_setting)
{
if (TimeDayOfWeek(Time[0])==MONDAY)
 if ((!check_time(Time_start1,Time_end1) && !check_time(Time_start2,Time_end2) && !check_time(Time_start3,Time_end3) && !check_time(Time_start3_1,Time_end3_1)) || !Monday) 
    {Comment("Bu saatlerde calismiyorum.");return;} 

if (TimeDayOfWeek(Time[0])==TUESDAY ) 
 if ((!check_time(Time_start4,Time_end4) && !check_time(Time_start5,Time_end5) && !check_time(Time_start6,Time_end6) && !check_time(Time_start6_1,Time_end6_1))  || !Tuesday)
    {Comment("Bu saatlerde calismiyorum.");return ;} 

if (TimeDayOfWeek(Time[0])==WEDNESDAY) 
if ((!check_time(Time_start7,Time_end7) && !check_time(Time_start8,Time_end8) && !check_time(Time_start9,Time_end9) && !check_time(Time_start9_1,Time_end9_1))  || !Wednesday)
    {Comment("Bu saatlerde calismiyorum.");return ;} 

if (TimeDayOfWeek(Time[0])==THURSDAY) 
if ((!check_time(Time_start10,Time_end10) && !check_time(Time_start11,Time_end11) && !check_time(Time_start12,Time_end12) && !check_time(Time_start12_1,Time_end12_1))  || !Thursday)
    {Comment("Bu saatlerde calismiyorum.");return ;} 

if ( TimeDayOfWeek(Time[0])==FRIDAY) 
if ((!check_time(Time_start13,Time_end13) && !check_time(Time_start14,Time_end14) && !check_time(Time_start15,Time_end15) && !check_time(Time_start15_1,Time_end15_1))  || !Friday)
    {Comment("Bu saatlerde calismiyorum.");return ;} 
}
 Comment("");
 
int sig=signal();
 
 
if(Ask-Bid<=MAX_Spread*PIP)
{ if(sig==0&& lasttype!=0 && NEW(0) && buy<Max_Number_of_Open_Order)
  {LOTLOT();
  if(OrderSend(Symbol(),OP_BUY,LOT,Ask,Max_Slippage_pip_For_TakePosition*dg,0,0
  ,"BUY",magic_number,0,clrNONE)>0){lasttype=0;counting();}}
  
  if(sig==1&& lasttype!=1 && NEW(1) && sell<Max_Number_of_Open_Order)
  {LOTLOT();
  if(OrderSend(Symbol(),OP_SELL,LOT,Bid,Max_Slippage_pip_For_TakePosition*dg,0,0
  ,"SELL",magic_number,0,clrNONE)>0){lasttype=1;counting();}}

} 
 

if(Close_position_with_oposite_signal&&sig==0&&sell>0)cutsell=1;

if(Close_position_with_oposite_signal&&sig==1&&buy>0)cutbuy=1;
if(cutbuy)CUT(0);
if(cutsell)CUT(1);
}//   end

 bool NEW( int type)
  {
   datetime LastOP=0; 
   int total=OrdersHistoryTotal()-1;
   
   for(int ih=total; ih>=0; ih--)
     { if(OrderSelect(ih,SELECT_BY_POS,MODE_HISTORY))
        { if( magic_number==OrderMagicNumber() && OrderSymbol()==Symbol()&&OrderType()==type)   
          
          if (LastOP>=Time[0])return(0);
        }
     } 
    
      LastOP=0;
     total=OrdersTotal()-1;
   
   for(int ih=total; ih>=0; ih--)
     { if(OrderSelect(ih,SELECT_BY_POS,MODE_TRADES))
        { if( magic_number==OrderMagicNumber() && OrderSymbol()==Symbol()&&OrderType()==type)  
           if (LastOP>=Time[0])return(0);
        }
     } 
    
    return(1);
  }
  

 bool daily_target_reached( )
  { if(daytgt==0)return(0);
   datetime today=iTime(NULL,1440,0); 
   int total=OrdersHistoryTotal()-1;
   double pipget=0;
   for(int ih=total; ih>=0; ih--)
     { if(OrderSelect(ih,SELECT_BY_POS,MODE_HISTORY))
        { if( magic_number==OrderMagicNumber() && OrderSymbol()==Symbol() )   
          if(OrderCloseTime()<today)continue;
          if(OrderType()==0)pipget+=OrderClosePrice()-OrderOpenPrice();
          if(OrderType()==1)pipget-=OrderClosePrice()-OrderOpenPrice();
        }
     } 
     
     total=OrdersTotal()-1;
   
   for(int ih=total; ih>=0; ih--)
     { if(OrderSelect(ih,SELECT_BY_POS,MODE_TRADES))
        { if( magic_number==OrderMagicNumber() && OrderSymbol()==Symbol() )  
          
          if(OrderType()==0)pipget+=OrderClosePrice()-OrderOpenPrice();
          if(OrderType()==1)pipget-=OrderClosePrice()-OrderOpenPrice();
        }
     } 
     
     if(pipget>=daytgt*PIP)return(1);
    
    return(0);
  }
  


bool cutbuy=0,cutsell=0;
void CUT(int type)
{  for(int i=0; i<=OrdersTotal()-1; i++)         
 { if (!OrderSelect(i,SELECT_BY_POS) )continue;
   if(OrderSymbol()!=Symbol())continue;
   if(OrderMagicNumber()!=magic_number)continue;
   if(OrderType()==type||type==9)
   bool r=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Max_Slippage_pip_For_TakePosition*dg,clrNONE);    
 }
}
 
  
int signal()
{ int res=9; 
   

double yellow=iCustom(NULL,0,indi,dist1,dist2,0,0,0,0,0, 0,0);
double lime=iCustom(NULL,0,indi,dist1,dist2,0,0,0,0,0, 1,0);
double red =iCustom(NULL,0,indi,dist1,dist2,0,0,0,0,0, 2,0);
double aqua=iCustom(NULL,0,indi,dist1,dist2,0,0,0,0,0, 3,0);
 
 if(aqua!=EMPTY_VALUE ||lime!=EMPTY_VALUE) res=0;
 if(yellow!=EMPTY_VALUE ||red!=EMPTY_VALUE) res=1;

  return(res);
}

  
//+------------------------------------------------------------------+
 



bool check_time(string Time_start,string Time_end)
{ 
  string D= TimeToStr(TimeCurrent(),TIME_DATE)+" ";
  
  if(TimeCurrent()>=StringToTime(D+Time_start) && TimeCurrent()<StringToTime(D+Time_end))return(1);
  return(0); 
  
}
 
int lasttype=9;
void check_lasttype()
{  lasttype=9;
   datetime LastOP=0; 
   int total=OrdersHistoryTotal()-1;
   
   for(int ih=total; ih>=0; ih--)
     { if(OrderSelect(ih,SELECT_BY_POS,MODE_HISTORY))
        { if( magic_number==OrderMagicNumber() && OrderSymbol()==Symbol() &&OrderType()<2)   
          
          if (OrderOpenTime()>LastOP){lasttype=OrderType();}
        }
     } 
    
      LastOP=0;
     total=OrdersTotal()-1;
   
   for(int ih=total; ih>=0; ih--)
     { if(OrderSelect(ih,SELECT_BY_POS,MODE_TRADES))
        { if( magic_number==OrderMagicNumber() && OrderSymbol()==Symbol() &&OrderType()<2)  
           if (OrderOpenTime()>LastOP){lasttype=OrderType();}
        }
     } 
    
    

}
 int buy,sell;
void counting()
{   bool r; buy=0;sell=0;
  double STL=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;
  double trail=MathMax(TrailingStop*PIP,STL),TSstart=Trailling_Start_from*PIP;
  double jump =MathMax(Trailling_step,0.1)*PIP;
  double TSLB= Bid-trail; double TSLS=Ask+trail;
  for(int i=0; i<=OrdersTotal()-1; i++)         
     {
      if (!OrderSelect(i,SELECT_BY_POS) )continue;
         if(OrderSymbol()!=Symbol())continue;
          if(OrderMagicNumber()!=magic_number)continue;
           double theTP=OrderTakeProfit();
           double OOP= OrderOpenPrice();
           double theSL=OrderStopLoss();
           int OT=OrderTicket();
            if (OrderType()==OP_BUY)
            { buy++;  
             
              if(theSL==0&&theTP==0&& (Stoploss_pip>0||TakeProfit_Pip>0))
              if(OrderModify(OT,OOP,(OOP-PIP*Stoploss_pip)*(Stoploss_pip>0),(OOP+TakeProfit_Pip*PIP)*(TakeProfit_Pip>0),0,clrNONE))continue;
             
              if(Break_even&&Bid-OOP>PIP*Decreasing_StopLoss_pip && theSL+0.1*PIP<OOP+PIP*New_Stop_Loss)
              if(OrderModify(OT,OOP,OOP+(PIP*New_Stop_Loss),theTP,0,Green))theSL=OOP+(PIP*New_Stop_Loss);
             
              if(TrailingStop!=0 && TSLB-OOP>=TSstart&&theSL+jump <=TSLB)
              r= OrderModify(OT,OOP,TSLB,theTP,0,Green); 
             }
             
             
           if (OrderType()==OP_SELL)
           { sell++; 
             if(theSL==0&&theTP==0&& (Stoploss_pip>0||TakeProfit_Pip>0))
             if(OrderModify(OT,OOP,(OOP+PIP*Stoploss_pip)*(Stoploss_pip>0),(OOP-TakeProfit_Pip*PIP)*(TakeProfit_Pip>0),0,clrNONE))continue;
               
             if(Break_even&&(OOP-Ask>PIP*Decreasing_StopLoss_pip) && (theSL==0 || theSL-0.1*PIP>OOP-PIP*New_Stop_Loss))
             if(OrderModify(OT,OOP,OOP-(PIP*New_Stop_Loss),theTP,0,Red))theSL=OOP-(PIP*New_Stop_Loss);
             
             if(TrailingStop!=0 && OOP-TSLS>=TSstart&&(theSL-jump >=TSLS||theSL==0))
             r= OrderModify(OT,OOP,TSLS,theTP,0,Red); 
           }
           
        
     }
}
 
 void clear(string name="line_")
{
 for (int a=ObjectsTotal()-1;a>=0;a--)
  { string n=ObjectName(a);
    if (StringFind(n,name,0)>-1) ObjectDelete(n);
  }
}
 
furkan9: d i don't know what should i change. :( 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. 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.
  3. Just reversing a loosing EA will not result in a winning EA. Always buying and always selling are both loosers.
 

int sig=signal();

change too

int sig=signal();

if(sig==0) sig=1;

else

 if(sig==1) sig=0;

 
thanks bro but it didn't work :(
 
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. 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.
  3. Just reversing a loosing EA will not result in a winning EA. Always buying and always selling are both loosers.
okey :) i'm just new :)