Simple EA ii

Author: Nicholishen @ Apex Group Investments,LLC
Profit factor:
0.48
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicatorMACD HistogramMovement directional index
1 Views
0 Downloads
0 Favorites
Simple EA ii
//+------------------------------------------------------------------+
//|                                              StochScalp^^2^^.mq4 |
//|                                                      Nicholishen |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Nicholishen @ Apex Group Investments,LLC"
#property link      "www.forex-tsd.com"

#include <stdlib.mqh>
#include <WinUser32.mqh>

  extern int Confirm=0;
  // extern int K=15,D=2,SL=1;
   extern double lots=0.1;            
   extern int TakeProfit=75;             
   extern int StopLoss=25;            
   bool UseTrail    = true; 
   
   double  TrailingAct   = 6;    
   double  TrailingStep   = 6;  

 
   extern bool UseTimeFilter=false;
   extern int BeginHour=8;
   extern int EndHour=18;
 
  
   int bar;
   int TestStart;
   int k;
   int mm,dd,yy,hh,min,ss,tf;
   string comment;
   string syym;
   string qwerty;
   int OrderID;
   double TrailPrice;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+


int TimeFilter(){
   if(Hour()>EndHour || Hour()<BeginHour){
      return(1);
   }
   return(0);
}
//+------------------------------------------------------------------+
// Calculates Current Orders on TF,Pair,EA
//+------------------------------------------------------------------+

int CalculateCurrentOrders(){
   int orders=0;
   
   for(int i=0;i<OrdersTotal();i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==OrderID ){
            orders++;
         }
      }
   }
   
   return(orders);
}



int TradeSignal(int functyp){
 //  bool Rev=false;  
 //  int x = Confirm;
 //  double sto1=iStochastic(NULL,0,K,D,SL,MODE_SMA,0,MODE_MAIN,x);
 //  double sto2=iStochastic(NULL,0,15,2,1,MODE_SMA,0,MODE_SIGNAL,1); 
 //  double stdev=iStdDev(NULL,0,10,MODE_SMA,0,0,0);
  //double sto3=iStochastic(NULL,1440,15,2,1,MODE_SMA,0,MODE_MAIN,0);
 // double sto4=iStochastic(NULL,1440,15,2,1,MODE_SMA,0,MODE_SIGNAL,0);
int x=Confirm;
double 
   MA1=iMA(NULL,0,24,0,MODE_EMA,PRICE_HIGH,x),
   MA2=iMA(NULL,0,24,0,MODE_EMA,PRICE_LOW,x),
   MACD=iMACD(NULL,0,8,18,5,MODE_CLOSE,MODE_SIGNAL,x),
   adx=iADX(NULL,0,14,MODE_CLOSE,0,x);
   
/*
MA1 - 24 Exp high
MA2 - 24 Exp low
Macd - default
adx - default
*/
   if(functyp==1){//exit
      if(Ask > MA1 && MACD > 0.00040 && adx > 22)return(2);
      if(Bid < MA2 && MACD < -0.00040 && adx > 22)return(1);
   }
   if(functyp==2){//open
      if(Bid<MA2 && MACD < 0 )return(0);
      if(Ask>MA1 && MACD > 0)return(0);
   }
 /*  
buy
1. price above MA1
2. macd above +0.00040
3. adx above 22

exit - price below MA2
- macd below 0

sell - 1. price below MA2
2. macd below -0.00040
3. adx above 22

exit - price above MA1
macd above 0

tp = 200
stoploss = 25
trailing sl = 5
TF = 1hr
   
   
if(functyp==1){
   if(sto1 >99 ){
      if(Rev){
         return(1);
      }else{
         return(2);
      }
   }

   if(sto1 < 1 ){
      if(Rev){
         return(2);
      } else{
         return(1);
      }
   }
}
if(functyp==2){
   if(sto1 >99){
      if(Rev){
         return(1);
      }else{
         return(2);
      }
   }
   if(sto1 < 1){
      if(Rev){
         return(2);
      } else{
         return(1);
      }
   }
}
 */  return(0);
}

//+------------------------------------------------------------------+
//| Open Conditions                       |
//+------------------------------------------------------------------+

void CheckForOpen(){
double sl,tp; int res,error;

  if(TradeSignal(1)==2){
      if (StopLoss==0) {sl=0;} else sl=Bid+Point*StopLoss;
      if (TakeProfit==0) {tp=0;} else tp=Bid-Point*TakeProfit;
      bar=Bars;
      res = OrderSend(Symbol(),OP_SELL,lots,Bid,3,sl,tp,"D2",OrderID,0,Blue); // def
      if(res<0){
         error=GetLastError();
         Print("Error = ",ErrorDescription(error));
      }
  }
  if(TradeSignal(1)==1){
      if (StopLoss==0) {sl=0;} else sl=Ask-Point*StopLoss;
      if (TakeProfit==0) {tp=0;} else tp=Ask+Point*TakeProfit;
      bar=Bars;
      res = OrderSend(Symbol(),OP_BUY,lots,Ask,3,sl,tp,"D2",OrderID,0,Red); // def
      if(res<0){
         error=GetLastError();
         Print("Error = ",ErrorDescription(error));
      }
  }
}   
  
//+------------------------------------------------------------------+
//| Close conditions                      |
//+------------------------------------------------------------------+
void CheckForClose(){

   for(int i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);    
      if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID && Symbol()==OrderSymbol()){
         if (TradeSignal(2)==2) {                          // MA SELL signals
            int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close 
            TrailPrice=0;
            if(res<0){
               int error=GetLastError();
               Print("Error = ",ErrorDescription(error));
            }
         }     
      } 
      if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID && Symbol()==OrderSymbol() ){
         if (TradeSignal(2)==1) {                          // MA BUY signals
            res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close 
            TrailPrice=0;
            if(res<0){
               error=GetLastError();
               Print("Error = ",ErrorDescription(error));
            }
         }     
      }  
   }    
}
void TrailingPositions() {
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderMagicNumber()==OrderID ) {
         if (OrderType()==OP_BUY) {
            if (Bid-OrderOpenPrice()>TrailingAct*Point && TrailPrice ==0) {
               TrailPrice=Bid-TrailingStep*Point;
               Print("TRAIL PRICE MODIFIED: ",TrailPrice);
            }
            if (TrailPrice>0 && TrailPrice < Bid-TrailingStep*Point){
               TrailPrice=Bid-TrailingStep*Point;
               Print("TRAIL PRICE MODIFIED: ",TrailPrice);
            }
            if (TrailPrice >0 && TrailPrice >= Bid-TrailingStep*Point){
               CloseOrder(1);
            }
         }
         if (OrderType()==OP_SELL) {
            if (OrderOpenPrice()-Ask > TrailingAct*Point && TrailPrice ==0) {
               TrailPrice=Ask+TrailingStep*Point;
               Print("TRAIL PRICE MODIFIED: ",TrailPrice);
            }
            if (TrailPrice>0 && TrailPrice > Ask+TrailingStep*Point){
               TrailPrice=Ask+TrailingStep*Point;
               Print("TRAIL PRICE MODIFIED: ",TrailPrice);
            }
            if (TrailPrice >0 && TrailPrice <= Ask+TrailingStep*Point){
               CloseOrder(2);
            }   
         }
      }
   }
}}

void CloseOrder(int ord){
    for(int i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);    
      if (OrderType()==OP_BUY && OrderMagicNumber()==OrderID){
         if (ord==1){
         int res = OrderClose(OrderTicket(),OrderLots(),Bid,3,White); // close 
         TrailPrice=0;
         if(res<0){
            int error=GetLastError();
            Print("Error = ",ErrorDescription(error));
         }
      }}     
      
      if (OrderType()==OP_SELL && OrderMagicNumber()==OrderID ){
         if (ord==2) {                          // MA BUY signals
            res = OrderClose(OrderTicket(),OrderLots(),Ask,3,White); // close 
            TrailPrice=0;
            if(res<0){
               error=GetLastError();
               Print("Error = ",ErrorDescription(error));
            }
         }     
      }  
   }    
 }  

int start(){
   

   if(Bars<100 || IsTradeAllowed()==false) return;

   if(CalculateCurrentOrders()==0) {
      TrailPrice=0;
      if(UseTimeFilter && TimeFilter()==1)return;
      CheckForOpen();
   }else{
      CheckForClose();
   }

  // if(UseTrail){TrailingPositions();}
 //  if(UseEmailAlerts){MailAlert();}
   
   return(0);
}  
//------------------------------------------------------------+

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.48
Total Trades 3225
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -1.12
Gross Profit 3330.00
Gross Loss -6952.10
Total Net Profit -3622.10
-100%
-50%
0%
50%
100%

Comments