Need help on this EA . Place trade in same direction if in profit. Based off last trade in history

Back to topics list To post a new topic, please log in or register
avatar
2
Kable76 2016.03.21 05:30
 

Hi when I Compile I get no errors or warnings but still wont work :( any help?  I'm trying to get it to place a trade is the same direction if it was in profit or reverse if not. Based off last trade in history.

extern double           LotSize=0.01;
double                     pips;
extern double           My_Money_Profit_Target=1;
extern double           My_Money_Profit_Loss=-1;
int Slippage=5;
int b;

//int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   double ticksize=MarketInfo(Symbol(),MODE_TICKSIZE);
   if(ticksize==0.0001 || ticksize==0.001)
      pips=ticksize*10;
   else pips=ticksize;


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {


bool ut; 
 
    if ((Orders()==True) && (UpTradeP()==True))ut=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,NULL,Red);
 
    if ((Orders()==True) && (UpTradeL()==True))ut=OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,NULL,Green);  
 
 
 bool dt; 
  
    if ((Orders()==True) && (DownTradeP()==True))dt=OrderSend(Symbol(),OP_SELL,LotSize,Bid,3,0,0,NULL,NULL,Red);
 
    if ((Orders()==True) &&(DownTradeL()==True))dt=OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,0,0,NULL,NULL,Green);
 
 
 
bool a;
if (AccountProfit()>= My_Money_Profit_Target|| AccountProfit()<= My_Money_Profit_Loss)
   {
    for(b=OrdersTotal()-1;b>=0;b--)
       {
       a=OrderSelect(b, SELECT_BY_POS);
       int type   = OrderType();
              
       bool result = false;
             
       switch(type)
          {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
                         break;
              
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
                         
          }
         if(result == false)
          {
            Sleep(3000);
          } 
       }
      Print ("Account Profit Reached. All Open Trades Have Been Closed");
      return(0);
   } 
  
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",My_Money_Profit_Target);
 
   return(0);
  }
 

 ///////////////////////////////////////////////////////////////////////////////////////////////
bool Orders()
  {
  
   if(OrdersTotal()==0)
                  return(true);
               else
          return(false);     
  }

//////////////////////////////////////////////////////////////////////////////////////////////////
bool DownTradeP()
 
   {
   for(int dp=OrdersTotal()-1; dp >= 0; dp--)
    {
    if (OrderSelect(dp,SELECT_BY_POS,MODE_HISTORY))    
         if((OrderType()==OP_SELL)&& (OrderProfit()>0))
       
             return(True);
               else      
          return(False); 
              
       }
       return(0);
}
////////////////////////////////////////////////////////////////
bool DownTradeL()
 
   {
   for(int dl=OrdersTotal()-1; dl >= 0; dl--)
    {
    if (OrderSelect(dl,SELECT_BY_POS,MODE_HISTORY))    
         if((OrderType()==OP_SELL)&&(OrderProfit()<0))
       
             return(True);
               else
          return(False); 
              
       }
       return(0);
}
///////////////////////////////////////////////////////////////
bool UpTradeP()
 
   {
   for(int up=OrdersTotal()-1; up >= 0; up--)
    {
    if (OrderSelect(up,SELECT_BY_POS,MODE_HISTORY))    
       if((OrderType()==OP_BUY )&&(OrderProfit()>0))
          
             return(True);
               else
          return(False); 
              
       }
       return(0);
}
///////////////////////////////////////////////////////////////
bool UpTradeL()
  
   {
   for(int ul=OrdersTotal()-1; ul >= 0; ul--)
    {
    if (OrderSelect(ul,SELECT_BY_POS,MODE_HISTORY))
         if((OrderType()==OP_BUY )&& (OrderProfit()<0))
             return(True);
               else
          return(False); 
              
       }
       return(0);
}

Back to topics list  

To add comments, please log in or register