Author: @2009 Desynced Tech
Orders Execution
Checks for the total of open ordersChecks for the total of closed ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself
Indicators Used
Moving average indicatorParabolic Stop and Reverse systemMACD Histogram
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
4.00 %
Total Trades 126
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -14.40
Gross Profit 80.40
Gross Loss -1894.70
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 303
Won Trades 301
Lost trades 2
Win Rate 0.99 %
Expected payoff -15.55
Gross Profit 2.20
Gross Loss -4713.80
Total Net Profit -4711.60
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
44.00 %
Total Trades 47
Won Trades 46
Lost trades 1
Win Rate 0.98 %
Expected payoff -12.98
Gross Profit 475.50
Gross Loss -1085.60
Total Net Profit -610.10
-100%
-50%
0%
50%
100%
DayImpulse
//+------------------------------------------------------------------+
//|                                                   DayImpulse.mq4 |
//|                                              @2009 Desynced Tech |
//|                                     http://desynced.no-ip.org/fx |
//+------------------------------------------------------------------+
#property copyright "@2009 Desynced Tech"
#property link      "http://desynced.no-ip.org/fx"

datetime lastOrder = 0;
//bool hasHedge = false;
//bool hasHedgeWithStop = false;
extern double lots = 0.4;
extern int takeprofit = 200;
int MAGIC = 57;
int ticket;
int hedgeTik= -1;
int orderTik = -1;
datetime PreviousBar = 0;
//int edgeTries=0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

int decision () {

/*
SetIndexLabel(0, "Signal(" + per + ")");
   SetIndexLabel(1, "MA(" + maPeriod + ")");
   SetIndexLabel(2, "Signal2(" + per + ")");
   
   if ( x1 > y1  && y0 > x0 ) trend = -1;// Print ("yuppi sell " , x0 , " " , y0) ;
       if ( y1 > x1 && x0 > y0 ) trend = 1 ; //Print ("yuppi buy " , , x0 , " " , y0) ;
*/
   double sig0 = iCustom(NULL, 0, "dayImpulse2dd",0,0);
         double sig1 = iCustom(NULL, 0, "dayImpulse2dd",0,1);
         double ma0 = iCustom(NULL, 0, "dayImpulse2dd",1,0);
         double ma1 = iCustom(NULL, 0, "dayImpulse2dd",1,1);
         
         double z0 = iCustom(NULL, 0, "dayImpulse2dd",2,0);

   if (  sig0 < 0 && sig1 > 0 && sig1 > ma1 && ma0 > sig0 && z0 == 0 ) {
   
   Print( "sell " , sig0 , " " , sig1 ," ", ma0 , " " , ma1 ,  " " , z0 );
    return(-1);
   }
   if  ( ma1 > sig1 && sig0 > ma0 ) {
      Print("buy ",  sig0 , " " , sig1 ," ", ma0 , " " , ma1 ,  " " , z0 );
     return(1);
    }
   
   return(0);


}

int getNumberTrades()
{   
   int total = OrdersTotal();
   int numords = 0;
      
   for(int cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() &&  OrderMagicNumber() == MAGIC) 
      return (OrderTicket());
   }
   return(-1);
}  

void checkTicket (int tik) {
   
   
     int hstTotal=OrdersHistoryTotal();
     if(OrderSelect(tik,SELECT_BY_TICKET,MODE_HISTORY) !=false ) {
    
         lastOrder = OrderCloseTime();
         ticket =0;
             
     }  
     
}


void openHedge(int currentTicket, int currentOrderType,double hLots ) {

   if ( currentOrderType == 0  ) {
         // é um buy vou abrir um sell */
         OrderSend(Symbol(),OP_SELL, hLots, Bid, 3,0 /*Ask+200*Point*/, 0,"hedge", MAGIC, 0, Red);
         
         OrderModify(currentTicket,Ask,0,0,0,Blue);
         /*
                            mysql_connect("192.168.0.3","forex","forex","forex",3306);
 									 insertOrderDb(ticket,Symbol(),Bid,0, 0,MAGIC,"woodyEA-HEDGER",OP_SELL, TimeCurrent());
 									mysql_close(mysql);
                        
         */
      //   hasHedgeWithStop = true;
             
      }
      else if ( currentOrderType == 1  ) {
      
        OrderSend(Symbol(),OP_BUY, hLots, Ask, 3, 0/*Bid-200*Point*/, 0,"hedge", MAGIC, 0, Red); 
        OrderModify(currentTicket,Bid,0,0,0,Blue);
      //   hasHedgeWithStop = true;
      }



}


void checkProfit(double currentProfit , int currentTicket , int currentOrderType , double currentLots , double hedgeProfit , int hedgeTicket , int  hedgeType , double hedgeLots,  int hedgeLoss, bool hasHedgeWithStop ) {

/*
   double currentProfit = OrderProfit();
   int orderTicket = OrderTicket();
   int orderType = OrderType();
  */ 
  // double hLots = OrderLots();
   double hLots = currentLots+0.1;
   
   
   if ( hedgeTicket != -1 ) Print(" current " , currentTicket , " " ,currentProfit , " HEDGE" , hedgeTicket , " " , hedgeProfit) ;
  
   
   if ( hedgeTicket > 0 ) {
   
      if ( currentProfit > 0 && hedgeProfit <0  ) {
         // esta na altura de fechar a original e abrir um hedge do hedge  
         Print (" deu para o torto  fechei" ,currentProfit , " " , hedgeProfit);
         
         closeOrder(currentTicket,currentOrderType,currentLots);
         
         openHedge(hedgeTicket, hedgeType , hedgeLots+0.1);
         
         return(0);
         
         
         
         
      
      }
   
   }
   if ( hedgeTicket == -1 && currentProfit < hedgeLoss ) {
      
     // int decision = stochasticAlert();
      
      if ( currentOrderType == 0  ) {
         // é um buy vou abrir um sell */
         OrderSend(Symbol(),OP_SELL, hLots, Bid, 3,0 /*Ask+200*Point*/, 0,"hedge", MAGIC, 0, Red);
         
         OrderModify(currentTicket,Ask,0,0,0,Blue);
         /*
                            mysql_connect("192.168.0.3","forex","forex","forex",3306);
 									 insertOrderDb(ticket,Symbol(),Bid,0, 0,MAGIC,"woodyEA-HEDGER",OP_SELL, TimeCurrent());
 									mysql_close(mysql);
                        
         */
         hasHedgeWithStop = true;
             
      }
      else if ( currentOrderType == 1  ) {
      
        OrderSend(Symbol(),OP_BUY, hLots, Ask, 3, 0/*Bid-200*Point*/, 0,"hedge", MAGIC, 0, Red); 
        OrderModify(currentTicket,Bid,0,0,0,Blue);
         hasHedgeWithStop = true;
      }
     
      return(0);
   
   }
   else if ( hedgeTicket > 0 && !hasHedgeWithStop) {
   
         // ja tenho um edge e agora que faco com ele 
         bool res = false;
         double point = 0 ;
         if ( hedgeType == OP_BUY ) {
            
            res = OrderModify(hedgeTicket,Ask,OrderOpenPrice(),0,0,Blue);
            
            point = MathAbs((Ask-OrderOpenPrice()));
         
         }
         else {
            
           res =  OrderModify(hedgeTicket,Bid,OrderOpenPrice(),0,0,Blue);
           
             point = MathAbs((Bid-OrderOpenPrice()));
         }
         if ( res ) {
         
           // Print(" modifiquei no hedge" , hedge);
            
         }
         else {
              // edgeTries++;
              // Print(" modifiquei no hedge" , edgeTries);
         }
   
   }
   else if  ( hedgeTicket > 0 && hasHedgeWithStop ) {
      
      if ( currentProfit + hedgeProfit > 0 ) {
         
               if ( currentProfit + OrderProfit() > 30 )  {
                  closeOrder(hedgeTicket,hedgeType,hedgeLots);
                  closeOrder(currentTicket,currentOrderType,currentLots);
                  
               }
               Print("tenho aqui um ponto de lucro " , currentProfit + hedgeProfit);
         }
   
   
   }
   else if ( hedgeTicket < 0 ) {
   /*
         getNumberTrades();
         
         if ( OrderTakeProfit() == 0 ) {
         
         
            if ( OrderType() == OP_BUY ) {
            
                  Print("aqui");
                  OrderModify(OrderTicket(),Ask,0,OrderOpenPrice(),0,Blue);
                  
            }
            else  {
            Print("aqui");
            OrderModify(OrderTicket(),Bid,0,OrderOpenPrice(),0,Blue);
            }
         
         
         }
   */
   }
   

}


  
  
  
  
/*
int getHedgeTrades() {


   int z = OrdersTotal();
   
   for(int i=0;i<z;i++) {
   
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if ( OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC && OrderComment() == "hedge" ) {
         hasHedge = true;
         if ( OrderStopLoss() == OrderOpenPrice() ) hasHedgeWithStop = true;
         return (OrderTicket());
      }
   
   }
   
   hasHedge = false;
   hasHedgeWithStop = false;
   edgeTicket = 0;
   
   
   return(-1);

}
*/



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);

}




}  

int decision2() {

int Current = 0;

int PeriodIXO = 15;

      double Buy1_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
      double Buy1_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
      double Buy2_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
      double Buy2_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
      double Buy3_1 = iSAR(NULL, 0, 0.005, 0.05, Current + 1);
      double Buy3_2 = iSAR(NULL, 0, 0.005, 0.05, Current + 0);
      double Buy4_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 1);
      double Buy4_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 0);
      double Sell1_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
      double Sell1_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 1);
      double Sell2_1 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
      double Sell2_2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, Current + 0);
      double Sell3_1 = iSAR(NULL, 0, 0.005, 0.05, Current + 1);
      double Sell3_2 = iSAR(NULL, 0, 0.005, 0.05, Current + 0);
      double Sell4_1 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 1);
      double Sell4_2 = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, Current + 0);
      double diIXO10=iCustom(NULL,0,"I_XO_A_H",PeriodIXO,0,0);
      double diIXO21=iCustom(NULL,0,"I_XO_A_H",PeriodIXO,1,0);
      double d22=(0);


      if (Buy1_1 < Buy1_2 && Buy2_1 >= Buy2_2 && Buy3_1 < Buy3_2 && Buy4_1 < Buy4_2 && diIXO10 > d22) return(1);
      if (Sell1_1 > Sell1_2 && Sell2_1 <= Sell2_2 && Sell3_1 > Sell3_2 && Sell4_1 > Sell4_2 && diIXO21< d22) return(-1);
      
      return (0);


}


 
  bool NewBar()
{
   if(PreviousBar<Time[0])
   {
      PreviousBar = Time[0];
      return(true);
   }
   else
   {
      return(false);
   }
   return(false);    // in case if - else statement is not executed
}




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 start()
  {

      orderTik = -1;
      hedgeTik = -1;
      getTrades();
      
      
      if ( orderTik != -1 )  {
      
         double currentProfit;     
         int currentOrderType;
         double currentLots;
         
         
         double hedgeProfit = 0;
         
         int  hedgeType = -1;
         double hedgeLots= 0 ;
         int hedgeLoss = -150;
         bool hasHedgeWithStop= false;
         
         
         //void checkProfit(double currentProfit , int currentTicket , int currentOrderType , double currentLots , double hedgeProfit , int hedgeTicket , int  hedgeType , double hedgeLots,  int hedgeLoss, bool hasHedgeWithStop ) {
           
            OrderSelect(orderTik,SELECT_BY_TICKET,MODE_TRADES);
            
            currentProfit = OrderProfit();
            currentOrderType = OrderType();
            currentLots = OrderLots();
            
            if ( hedgeTik != -1 ) {
               
                  OrderSelect(hedgeTik,SELECT_BY_TICKET,MODE_TRADES);
                  hedgeProfit = OrderProfit();
                  hedgeType = OrderType();
                  hedgeLots = OrderLots();
                  hasHedgeWithStop = OrderStopLoss() == OrderOpenPrice();
                  
            }
            checkProfit(currentProfit,orderTik,currentOrderType,currentLots,hedgeProfit,hedgeTik,hedgeType,hedgeLots,hedgeLoss , hasHedgeWithStop );

         
         
        // Print(" tenho ordem Activa ") ;
         
         return(0);
      }
      


/*
      checkTicket(ticket);
      int tik = getNumberTrades() ;
      
      if ( tik != -1 ) {
      
         checkProfit(-100);
         
      /*
            if ( OrderType() == OP_BUY  && decision == -1) {
            
               closeOrder(OrderTicket(),OrderType(),OrderLots());
            }
            
            if ( OrderType() == OP_SELL  && decision == 1 ) {
            
               closeOrder(OrderTicket(),OrderType(),OrderLots());
            }
      
            
      
      
      return(0);
      }
   */  
     if(NewBar() == false ) return(0);
    
      
      int decision = decision2();
      
      
      if ( decision == 1 ) {
              
               
                if ( (TimeCurrent() - lastOrder ) > (60*60*3 ) ) {

                      ticket = OrderSend(Symbol(),OP_BUY, lots, Ask, 3, 0, Ask+takeprofit*Point,"", MAGIC, 0, Red); 
                      
                      /*
                            mysql_connect("192.168.0.3","forex","forex","forex",3306);
 									 insertOrderDb(ticket,Symbol(),,0, Ask+60*Point,MAGIC,"woodyEA",OP_BUY, TimeCurrent());
 									mysql_close(mysql);
                        
                      */
                      lastOrder = TimeCurrent();
               }

         }
         
         else if ( decision == -1 ) {
         
             if ( (TimeCurrent() - lastOrder ) > (60*60*3 ) ) {
             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-60*Point,MAGIC,"woodyEA",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 ---