Author: @2009 Desynced Tech
Orders Execution
It can change open orders parameters, due to possible stepping strategyChecks for the total of closed ordersIt automatically opens orders when conditions are reachedChecks for the total of open orders
Indicators Used
DeMarker indicatorStochastic oscillator
0 Views
0 Downloads
0 Favorites
roScalper
//+------------------------------------------------------------------+
//|                                                    roScalper.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>

extern int takeprofit = 60;
extern double lots = 0.1;
extern int MAGIC = 85;
extern int trailingStep = 40;
extern int profTarget = 25;
extern int stoploss = 0;


int maxprofit = 0;



#define MABULL 1
#define MABEAR -1

datetime lastOrder;

double max = 0 ;

int ticket;

double tp ;

double dsStopLoss = 0 ;
double dbStopLoss = 0 ;


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

bool canTrade() {

   //if ( Minute() == 0) return(false);

   if ( Hour() >= 1 && Hour() < 2 || (Hour() == 2 && Minute() < 20 )  ) return (false);
   
   if ( Hour() >= 9 && Hour() < 10 || (Hour() == 10 && Minute() < 20 ) ) return (false);
   
   if ( Hour() >= 13 && Hour() < 14 || ( Hour() == 14 && Minute() < 20 )) return (false);
   
   if ( Hour() == 17 ) return(false);
   
   return (true);

}





void trailingProfit( int tp , int profittarget, int step) {
   
   int tik = getNumberTrades ();

   if ( tik == -1 ) return;
   
   if ( OrderType() == OP_BUY && OrderProfit() > 0 ) {
         
       //  Print(" diff  " ,OrderProfit() , " = > " ,((OrderTakeProfit() - Ask)/Point));
         
         if ( ((OrderTakeProfit() - Ask)/Point) <= profittarget ) OrderModify(tik,OrderOpenPrice(),Bid-step*Point,Ask+step*Point,0,Blue);
   
   }
   
   if ( OrderType() == OP_SELL && OrderProfit() > 0 ) {
   
            if ( (  (OrderTakeProfit()-Bid)/Point)*(-1) <= profittarget ) OrderModify(tik,OrderOpenPrice(), Ask+step*Point,Bid-step*Point,0,Red);
   }
   

}


void checkTicket (int tik) {
   
   
     int hstTotal=OrdersHistoryTotal();
     if(OrderSelect(tik,SELECT_BY_TICKET,MODE_HISTORY) !=false ) {
     
     
     Print(tik, " max profit was " , maxprofit);
         lastOrder = OrderCloseTime();
         ticket =0;
         maxprofit = 0 ;
             
     }  
     
}



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




int start()
  {








int tik = getNumberTrades ();
if ( tik != -1 ) {
   
   /*
   if ( OrderProfit() > maxprofit ) maxprofit = OrderProfit();
   
   if ( OrderType() == OP_BUY && OrderProfit() > 0 ) {
         
       //  Print(" diff  " ,OrderProfit() , " = > " ,((OrderTakeProfit() - Ask)/Point));
         
         if ( ((OrderTakeProfit() - Ask)/Point) <= 6 ) OrderModify(tik,OrderOpenPrice(),Bid-takeprofit*Point,Ask+50*Point,0,Blue);
   
   }
   
   if ( OrderType() == OP_SELL && OrderProfit() > 0 ) {
   
  
   
   
            if ( (  (OrderTakeProfit()-Bid)/Point)*(-1) <= 6 ) OrderModify(tik,OrderOpenPrice(), Ask+takeprofit*Point,Bid-50*Point,0,Red);
   
   
           // Print(" diff sell " ,OrderProfit() , " = > " ,(  (OrderTakeProfit()-Bid)/Point)*(-1));
   }
   
*/

}
else {

   if ( ticket != 0 )   checkTicket(ticket);

}



//if ( AccountBalance() > 2300 ) lots = 0.2;


if ( !canTrade()  ) {
         
            Comment("no trade time");
            return(0);
         }
         else Comment("");


//if ( x1 != 0 && x1< 0.7 && x2 < 2  && getNumberTrades () == -1 && stoch == 1 && demarker < 0.36 && (TimeCurrent() - lastOrder) > (60*60*4) ) {

 //if(NewBar() == false ) return(0);

double demarker = iDeMarker(NULL,0,14,0);





double idx0 = iCustom(NULL, 0, "stc_plot_dcec",0,0);
double idx1 = iCustom(NULL, 0, "stc_plot_dcec",0,1);



if ( stoploss > 0 ) {
   
   dsStopLoss = Ask+stoploss*Point   ;
   dbStopLoss = Bid-stoploss*Point;
   
   

}
else {

      dsStopLoss = 0 ;
      dbStopLoss = 0 ;
}


if ( idx1 < 15 && idx0 > 15 &&  getNumberTrades () == -1 && (TimeCurrent() - lastOrder) > (60*60*4)  && demarker < 0.36) {




  // Print (x1, " " , x2 , " ", stoch, " " , demarker, " " );
    if ( takeprofit > 0 ) {
              
                  tp = Ask+takeprofit*Point;
         }
         else tp = 0;

        ticket =  OrderSend(Symbol(),OP_BUY, 0.1, Ask, 3, dbStopLoss, tp,"", MAGIC, 0, Red); 
        
        if ( ticket > 0 ) {
        /*
       
                            mysql_connect("192.168.0.3","forex","forex","forex",3306);
 									 insertOrderDb(ticket,Symbol(),Bid,0, tp,MAGIC,"roScalper",OP_BUY, TimeCurrent());
 									mysql_close(mysql);
      */
        
         lastOrder = TimeCurrent();
         return(0);
        }

}

if ( idx1 > 85 && idx0 < 85 &&  getNumberTrades () == -1 &&  (TimeCurrent() - lastOrder) > (60*60*4) && iDeMarker(NULL,0,14,0) < 0.7) {
      Print ("possible SELL ",iDeMarker(NULL,0,14,0) , " " ,( (TimeCurrent() - lastOrder)/(60*60*4)) );
      
      if ( takeprofit > 0 ) {
              
                  tp = Bid-takeprofit*Point;
              }
              else tp = 0;
             
              ticket =  OrderSend(Symbol(),OP_SELL, lots, Bid, 3, dsStopLoss, tp,"", MAGIC, 0, Red); 
      
      if ( ticket > 0 ) {
      
      
                      /*  
                            mysql_connect("192.168.0.3","forex","forex","forex",3306);
 									 insertOrderDb(ticket,Symbol(),Bid,0, tp,MAGIC,"roScalper",OP_SELL, TimeCurrent());
 									mysql_close(mysql);
       */
        
         lastOrder = TimeCurrent();
         return(0);
        }

}


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


  int stochasticAlert() {

   double mainLine;
   double prevMainLine;
   double signalLine;
   double prevSignalLine;
      
   for(int a=0;a<=4 ;a++)
   {
      mainLine=iStochastic(0,0,14,3,3,MODE_SMA,0,MODE_MAIN,a);
      prevMainLine=iStochastic(0,0,14,3,3,MODE_SMA,0,MODE_MAIN,a+1);
      signalLine=iStochastic(0,0,14,3,3,MODE_SMA,0,MODE_SIGNAL,a);
      prevSignalLine=iStochastic(0,0,14,3,3,MODE_SMA,0,MODE_SIGNAL,a+1);
 
      if(prevMainLine<prevSignalLine && mainLine>signalLine) {
        // Print("buy " , mainLine , " " , signalLine );
         return (MABULL);
        }
      if(prevMainLine>prevSignalLine && mainLine<signalLine) {
      
      //   Print("sell " , mainLine , " " , signalLine );
         return (MABEAR);
        }
   }
   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);
} 

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