EURGBPASIAN

Author: @2009 Desynced Tech
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself Checks for the total of closed ordersIt automatically opens orders when conditions are reached
Indicators Used
Relative strength index
0 Views
0 Downloads
0 Favorites
EURGBPASIAN
//+------------------------------------------------------------------+
//|                                                       RaviEA.mq4 |
//|                                              @2009 Desynced Tech |
//|                                     http://desynced.no-ip.org/fx |
//+------------------------------------------------------------------+
#property copyright "@2009 Desynced Tech"
#property link      "http://desynced.no-ip.org/fx"


#include <mysql.mqh>
datetime lastOrder ;

int ticket = -1;
extern int takeprofit = 50;
int orderTik;
int hedgeTik;

int MAGIC = 1666;

extern double lots = 0.1;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
  
  int decision () {
  
  
         double rsi0 = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);  
         double rsi1 = iRSI(NULL, 0, 14, PRICE_CLOSE, 1);  
         
         double rsi2 = iRSI(NULL, 0, 14, PRICE_CLOSE, 2);  
  
        // if ( rsi2 < 40 && rsi1 > 40 && rsi0 > 50 ) return(1);
        
        
        if ( rsi0 > 70 && rsi1 < 70 ) return(1);
        
         
        // Comment( x0 , " " , x1 ) ;
  
  }
  
  
  
bool canTrade() {

   if ( Hour() >2  && Hour() < 9 ) return (true);
   
   return (false);

}
  
  
  
  void  getTrades() {


    int total = OrdersTotal();
   int numords = 0;
   
   int tickets[10];
   int ticketsFound = 0; 
     
   for(int cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() &&  OrderMagicNumber() == MAGIC) 
   
      tickets[ticketsFound] = OrderTicket();
      ticketsFound++;
   }
   
   if ( ticketsFound == 2 ) {
   
      if ( tickets[0] < tickets[1] ) {
      
         orderTik = tickets[0];
         hedgeTik = tickets[1];
         
        // Print("orignal é " , tickets[0] , " hedge " , tickets[1] ) ;
      
      }
      else {
         //Print("orignal é " , tickets[1] , " hedge " , tickets[0] ) ;
         
         orderTik = tickets[1];
         hedgeTik = tickets[0];
      
      }
   
   
   }
   else if ( ticketsFound == 1  ) {
   
         orderTik = tickets[0];
          
         hedgeTik = -1;
   }
   else if ( ticketsFound < 1 ) {
   
      orderTik = -1;
      hedgeTik = -1;
   }
   else if ( ticketsFound > 2 ) {
   
      Print("FODDASE NAO PODE HAVER MAIS QUE 2 ");
   }
}



int closeOrder(int ticket,int orderType, double lts) {

if ( orderType == OP_BUY ) {

   OrderClose(ticket,lts,Bid,3,Green);
   return(0);
}
else {
   OrderClose(ticket, lts, Ask, 3, Green);
    return(0);

}
}

datetime checkTicket (int tik) {
   
   
     int hstTotal=OrdersHistoryTotal();
     datetime ret = 0;
     if(OrderSelect(tik,SELECT_BY_TICKET,MODE_HISTORY) !=false ) {
     
        ret = OrderCloseTime();
        return(ret);
             
     }  
      
     return(0); 
}

  
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {


      orderTik = -1;
      hedgeTik = -1;
      getTrades();
      
      
      if ( orderTik != -1 )  {
      
            OrderSelect(orderTik, SELECT_BY_TICKET); 
            
           // if ( (TimeCurrent() - OrderOpenTime() ) > (60*60*4) ) closeOrder(orderTik,OrderType(),OrderLots());
            
      
            return(0);
      }

 //  if ( !canTrade () )return(0);
  

    int decision =   decision();
    
   if ( ticket > 0 ) {
    datetime lastOrder = checkTicket(ticket);
    
      if ( (TimeCurrent() - lastOrder) < (60*60*4) ) return(0);
   } 
    
    
 if ( decision == 1 ) {
              
               
                
                
                      ticket = OrderSend(Symbol(),OP_BUY, lots, Ask, 3, 0, Ask+takeprofit*Point,"", MAGIC, 0, Red); 
                     
                     
                     if ( ticket > 0 ) {
                      
                     /*
                          mysql_connect("192.168.0.3","forex","forex","forex",3306);
                          insertOrderDb(ticket,Symbol(),Ask,0, Ask+takeprofit*Point,MAGIC,"RAVIEA",OP_BUY, TimeCurrent());
                          mysql_close(mysql);
                        
                      */
                      lastOrder = TimeCurrent();
                     }

         }
         
         else if ( decision == -1 ) {
             
            
             ticket =  OrderSend(Symbol(),OP_SELL, lots, Bid, 3, 0, Bid-takeprofit*Point,"", MAGIC, 0, Red); 
                       
                        if ( ticket > 0 ) {
                        
                        /*
                        
                            mysql_connect("192.168.0.3","forex","forex","forex",3306);
                             insertOrderDb(ticket,Symbol(),Bid,0, Bid-takeprofit*Point,MAGIC,"RAVIEA",OP_SELL, TimeCurrent());
                            mysql_close(mysql);
                      
                               lastOrder = TimeCurrent();
                           */ 
                        }
            
         }


    
    
    
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---