Author: by klopka
Profit factor:
0.55
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicatorCommodity channel indexStochastic oscillator
Miscellaneous
It issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
Kloss
//+------------------------------------------------------------------+
//|                                                         Kloss.mq4 |
//|                                                  Copyright © 2008|
//|                                                        k59@op.pl |
//+------------------------------------------------------------------+
#property copyright "by klopka"
#property link      "k59@op.pl"
extern double Lots       =0;   
extern double Prots      =0.2;
extern double max_lot = 5;                                   
extern double StopLoss   =48;     
extern double TakeProfit =152;           
bool Work=true;                    
string Symb;                       
int start()
  {
   int
   Total,Tip=-1,Ticket;                          
   double                         
   MA_2_t,linia_CCI_1,Stoch,Period_MA_2,Lot,Lts,Min_Lot,Step,Free,One_Lot,Price,SL,TP;                              
   bool
   Ans  =false,Cls_B=false,Cls_S=false,Opn_B=false,Opn_S=false;                     
   
   if(Bars < Period_MA_2)                       
     {
      Alert("<bars.EA does not work.");
      return;                                   
     }
   if(Work==false)                              
     {
      Alert("critical error.");
      return;                                   
     }
   
   Symb=Symbol();                               
   Total=0;                                     
   for(int i=1; i<=OrdersTotal(); i++)          
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) 
        {                                       
         if (OrderSymbol()!=Symb)continue;      
         if (OrderType()>1)                     
           {
            Alert("Open order was found. EA does not work.");
            return;                             
           }
         Total++;                               
         if (Total>1)                           
           {
            Alert("A few open orders. EA does not work.");
            return;                             
           }
         Ticket=OrderTicket();                  
         Tip   =OrderType();                    
         Price =OrderOpenPrice();               
         SL    =OrderStopLoss();                
         TP    =OrderTakeProfit();              
         Lot   =OrderLots();                    
        }
     }
   /*Indicators*/
   
  MA_2_t=iMA(NULL,PERIOD_M5,1,0,MODE_LWMA,PRICE_TYPICAL,5); 
  linia_CCI_1=iCCI(NULL,PERIOD_M5,10,PRICE_WEIGHTED,0);
  Stoch=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
   
   
   // buy
   if(linia_CCI_1<-120 && Stoch < 30 && Open[1]>MA_2_t)
      
     {                                          
      Opn_B=true;                               
      Cls_S=true;                               
     }
    // sell
     if(linia_CCI_1>120 && Stoch > 70 && Close[1]<MA_2_t)
            
     {                                          
      Opn_S=true;                               
      Cls_B=true;                               
     }
//-----------------------------------------------------------------
   // close
   while(true)                                  
     {
      if (Tip==0 && Cls_B==true)                
        {                                       
         Alert("The test of lock the Buy",Ticket,"Expectation on answer");
         RefreshRates();                        
         Ans=OrderClose(Ticket,Lot,Bid,2,White);      
         if (Ans==true)                         
           {
            Alert ("Close buy",Ticket);
            break;                              
           }
         if (Fun_Error(GetLastError())==1)      
            continue;                           
         return;                                
        }

      if (Tip==1 && Cls_S==true)                
        {                                       
         Alert("The test of lock the sell",Ticket,"Expectation on answer");
         RefreshRates();                        
         Ans=OrderClose(Ticket,Lot,Ask,2,White);      
         if (Ans==true)                         
           {
            Alert ("closed Sell",Ticket);
            break;                              
           }
         if (Fun_Error(GetLastError())==1)      
            continue;                           
         return;                                
        }
      break;                                    
     }
   // amount orders
   RefreshRates();                              
   Min_Lot=MarketInfo(Symb,MODE_MINLOT);        
   Free   =AccountFreeMargin();                 
   One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);
   Step   =MarketInfo(Symb,MODE_LOTSTEP);       

   if (Lots > 0)                                
      Lts =Lots;                                
   else                                         
      Lts=MathFloor(Free*Prots/One_Lot/Step)*Step;

   if(Lts < Min_Lot) Lts=Min_Lot;
   else  if(Lts>max_lot) Lts=max_lot;               
   if (Lts*One_Lot > Free)                      
     {
      Alert("no money", Lts," lot");
      return;                                   
     }
//-----------------------------------------------------------------
   // Open orders
   while(true)                                  
     {
      if (Total==0 && Opn_B==true)              
        {                                       
         RefreshRates();                        
         SL=Bid - New_Stop(StopLoss)*Point;     
         TP=Bid + New_Stop(TakeProfit)*Point;   
         Alert("The test open Buy. Expectation on answer");
         Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP,"buy",0,0,Green);
         if (Ticket > 0)                        
           {
            Alert ("open buy",Ticket);
            return;                             
           }
         if (Fun_Error(GetLastError())==1)      
            continue;                           
         return;                                
        }
      if (Total==0 && Opn_S==true)              
        {                                       
         RefreshRates();                        
         SL=Ask + New_Stop(StopLoss)*Point;     
         TP=Ask - New_Stop(TakeProfit)*Point;   
         Alert("The test open Sell. Expectation on answer");
         Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP,"sell",0,0,Red);
              
         if (Ticket > 0)                        
           {
            Alert ("Open Sell ",Ticket);
            return;                             
           }
         if (Fun_Error(GetLastError())==1)      
            continue;                           
         return;                                
        }
      break;                                    
     }
   return;                                      
  }
// errors

int Fun_Error(int Error)                        
  {
   switch(Error)
     {                                                    
      case  4: Alert("error 4");
         Sleep(3000);                           
         return(1);                             
      case 135:Alert("error 135");
         RefreshRates();                        
         return(1);                             
      case 136:Alert("error 136");
         while(RefreshRates()==false)           
            Sleep(1);                           
         return(1);                             
      case 137:Alert("error 137");
         Sleep(3000);                           
         return(1);                             
      case 146:Alert("error 146");
         Sleep(500);                            
         return(1);                             
         // Bledy krytyczne
      case  2: Alert("error 2");
         return(0);                             
      case  5: Alert("error 5");
         Work=false;                            
         return(0);                             
      case 64: Alert("error 64");
         Work=false;                            
         return(0);                             
      case 133:Alert("error 133");
         return(0);                             
      case 134:Alert("error 134");
         return(0);                             
      default: Alert("error",Error);   
         return(0);                             
     }
  }
int New_Stop(int Parametr)                      
  {
   int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);
   if (Parametr<Min_Dist)                       
     {
      Parametr=Min_Dist;                        
      Alert("> distance stop limit");
     }
   return(Parametr);                            
  }

Profitability Reports

NZD/USD Jul 2025 - Sep 2025
0.53
Total Trades 422
Won Trades 166
Lost trades 256
Win Rate 39.34 %
Expected payoff -23.69
Gross Profit 11274.59
Gross Loss -21272.84
Total Net Profit -9998.25
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.67
Total Trades 341
Won Trades 106
Lost trades 235
Win Rate 31.09 %
Expected payoff -27.72
Gross Profit 19289.86
Gross Loss -28741.03
Total Net Profit -9451.17
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.01
Total Trades 145
Won Trades 23
Lost trades 122
Win Rate 15.86 %
Expected payoff -68.94
Gross Profit 143.74
Gross Loss -10140.01
Total Net Profit -9996.27
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.43
Total Trades 502
Won Trades 136
Lost trades 366
Win Rate 27.09 %
Expected payoff -19.91
Gross Profit 7463.07
Gross Loss -17459.33
Total Net Profit -9996.26
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.73
Total Trades 1366
Won Trades 502
Lost trades 864
Win Rate 36.75 %
Expected payoff -7.31
Gross Profit 26665.38
Gross Loss -36654.20
Total Net Profit -9988.82
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.57
Total Trades 770
Won Trades 338
Lost trades 432
Win Rate 43.90 %
Expected payoff -12.98
Gross Profit 13348.54
Gross Loss -23346.55
Total Net Profit -9998.01
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.51
Total Trades 623
Won Trades 219
Lost trades 404
Win Rate 35.15 %
Expected payoff -16.05
Gross Profit 10269.38
Gross Loss -20266.88
Total Net Profit -9997.50
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.76
Total Trades 1061
Won Trades 339
Lost trades 722
Win Rate 31.95 %
Expected payoff -9.42
Gross Profit 31993.41
Gross Loss -41989.66
Total Net Profit -9996.25
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.75
Total Trades 569
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -17.57
Gross Profit 30484.90
Gross Loss -40483.15
Total Net Profit -9998.25
-100%
-50%
0%
50%
100%

Comments