Author: Copyright � 2007, Tinytjan
Profit factor:
0.92
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
11 Views
0 Downloads
0 Favorites
Kloss_
//+------------------------------------------------------------------+
//|                                                       Kloss_.mq4 |
//|                                       Copyright © 2007, Tinytjan |
//|                                                 tinytjan@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Tinytjan"
#property link      "tinytjan@mail.ru"

#define STUPID 0x60BE57

extern string     Lots_Desc         =  "if 0 dynamic lot is applied";
extern double     Lots              =  0;

extern string     RiskPercentage_Desc =  "actual only of Lots == 0, percentage of the risk for opening order";
extern int        RiskPercentage    =  0;

extern int        Slippage          =  2;

extern string     Target_Desc       =  "Take Profit -- none if 0";
extern int        Target            =  152;

extern string     Loss_Desc         =  "Stop Loss -- none if 0";
extern int        Loss              =  48;

extern int        MA                =  1;

extern int        CCI               =  10;

extern int        StochasticK       =  5;

extern int        StochasticD       =  3;

extern int        StochasticS       =  3;

extern string     CCIDiffer_Desc    =  "CCIDiffer and -CCIDiffer are signal levels";
extern int        CCIDiffer         =  120;

extern string     StochDiffer_Desc  =  "50 + StochDiffer and 50 - StochDiffer are signal levels";
extern int        StochDiffer       =  20;

extern string     MaxOrders_Desc    =  "no limit if 0";
extern int        MaxOrders         =  3;

double LotsToBid;
string symbol;

void CloseBuys(int MagicNumber, int Slippage)
{
   for(int i = 0; i < OrdersTotal(); i++)
   {
      // already closed
      if(OrderSelect(i, SELECT_BY_POS) == false) continue;
      // not current symbol
      if(OrderSymbol() != Symbol()) continue;
      // order was opened in another way
      if(OrderMagicNumber() != MagicNumber) continue;
      
      if(OrderType() == OP_BUY)
      {
         if(OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Blue))
         {
            i--;
         }
         RefreshRates();
      }
   }
}

void CloseSells(int MagicNumber, int Slippage)
{
   for(int i = 0; i < OrdersTotal(); i++)
   {
      // already closed
      if(OrderSelect(i, SELECT_BY_POS) == false) continue;
      // not current symbol
      if(OrderSymbol() != Symbol()) continue;
      // order was opened in another way
      if(OrderMagicNumber() != MagicNumber) continue;
      
      if(OrderType() == OP_SELL)
      {
         if (OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red))
         {
            i--;
         }
         RefreshRates();
      }
   }
}

int GetOrdersCount(int MagicNumber, int Type)
{
   int count = 0;
   
   for(int i = 0; i < OrdersTotal(); i++)
   {
      // already closed
      if(OrderSelect(i, SELECT_BY_POS) == false) continue;
      // not current symbol
      if(OrderSymbol() != Symbol()) continue;
      // order was opened in another way
      if(OrderMagicNumber() != MagicNumber) continue;
      
      if(OrderType() == Type)
      {
         count++;
      }
   }
   
   return (count);
}

double GetLotsToBid(int RiskPercentage)
{
   double margin = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double minLot = MarketInfo(Symbol(), MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
   double account = AccountFreeMargin();
   
   double percentage = account*RiskPercentage/100;
   
   double lots = MathRound(10*percentage/margin)/10;
   
   if(lots < minLot)
   {
      lots = minLot;
   }
   
   if(lots > maxLot)
   {
      lots = maxLot;
   }

   return (lots);
}

void OpenBuy()
{
   double TP = 0;
   if (Target > 0)
   {
      TP = Bid + Target*Point;
   }

   double SL = 0;
   if (Loss > 0)
   {
      SL = Bid - Loss*Point;
   }
   
   if (Lots == 0) LotsToBid = GetLotsToBid(RiskPercentage);
   
   OrderSend(Symbol(), OP_BUY, LotsToBid, Ask, Slippage, SL, TP, NULL, STUPID, 0, Blue);
}

void OpenSell()
{
   double TP = 0;
   if (Target > 0)
   {
      TP = Ask - Target*Point;
   }

   double SL = 0;
   if (Loss > 0)
   {
      SL = Ask + Loss*Point;
   }
   
   if (Lots == 0) LotsToBid = GetLotsToBid(RiskPercentage);
   
   OrderSend(Symbol(), OP_SELL, LotsToBid, Bid, Slippage, SL, TP, NULL, STUPID, 0, Red);
}

void Check()
{
   double ma = iMA(symbol, 0, MA, 0, MODE_LWMA, PRICE_TYPICAL, 5);
   double cci = iCCI(symbol, 0, CCI, PRICE_WEIGHTED, 0);
   double stoch = iStochastic(symbol, 0, StochasticK, StochasticD, StochasticS, MODE_SMA, 0, MODE_MAIN, 0);
   
   if (cci < -CCIDiffer && stoch < 50 - StochDiffer && Open[1] > ma)
   {
      if (GetOrdersCount(STUPID, OP_SELL) > 0)
      {
         CloseSells(STUPID, Slippage);
         return;
      }
      if (GetOrdersCount(STUPID, OP_BUY) < MaxOrders || MaxOrders == 0) 
      {
         OpenBuy();
      }
   }

   if (cci > CCIDiffer && stoch > 50 + StochDiffer && Close[1] < ma)
   {
      if (GetOrdersCount(STUPID, OP_BUY) > 0)
      {
         CloseBuys(STUPID, Slippage);
         return;
      }
      if (GetOrdersCount(STUPID, OP_SELL) < MaxOrders || MaxOrders == 0) 
      {
         OpenSell();
      }
   }
}

int init()
{
   LotsToBid = Lots;
   symbol = Symbol();
}

datetime LastTime = 0;

int start()
{
   if (LastTime == 0)
   {
      LastTime = TimeCurrent();
      return (0);
   }
   
   // Trading only when tick is opening
   //if (TimeCurrent() - LastTime > 20)
   {
      // Check for open new orders and close current ones
      Check();
      LastTime = TimeCurrent();
   }

   return(0);
}

Profitability Reports

EUR/USD Jul 2025 - Sep 2025
5.75
Total Trades 1555
Won Trades 1107
Lost trades 448
Win Rate 71.19 %
Expected payoff 0.82
Gross Profit 1544.85
Gross Loss -268.80
Total Net Profit 1276.05
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.84
Total Trades 674
Won Trades 189
Lost trades 485
Win Rate 28.04 %
Expected payoff -0.07
Gross Profit 247.39
Gross Loss -295.85
Total Net Profit -48.46
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.72
Total Trades 411
Won Trades 105
Lost trades 306
Win Rate 25.55 %
Expected payoff -0.13
Gross Profit 137.43
Gross Loss -189.72
Total Net Profit -52.29
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.71
Total Trades 691
Won Trades 177
Lost trades 514
Win Rate 25.62 %
Expected payoff -0.14
Gross Profit 225.34
Gross Loss -318.68
Total Net Profit -93.34
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.67
Total Trades 561
Won Trades 130
Lost trades 431
Win Rate 23.17 %
Expected payoff -0.16
Gross Profit 179.11
Gross Loss -267.22
Total Net Profit -88.11
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.65
Total Trades 505
Won Trades 126
Lost trades 379
Win Rate 24.95 %
Expected payoff -0.12
Gross Profit 117.25
Gross Loss -179.05
Total Net Profit -61.80
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.65
Total Trades 565
Won Trades 151
Lost trades 414
Win Rate 26.73 %
Expected payoff -0.22
Gross Profit 232.73
Gross Loss -357.14
Total Net Profit -124.41
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.62
Total Trades 666
Won Trades 146
Lost trades 520
Win Rate 21.92 %
Expected payoff -0.18
Gross Profit 201.48
Gross Loss -322.40
Total Net Profit -120.92
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.59
Total Trades 325
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -0.20
Gross Profit 95.18
Gross Loss -160.65
Total Net Profit -65.47
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.58
Total Trades 438
Won Trades 104
Lost trades 334
Win Rate 23.74 %
Expected payoff -0.20
Gross Profit 122.18
Gross Loss -209.84
Total Net Profit -87.66
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.57
Total Trades 264
Won Trades 57
Lost trades 207
Win Rate 21.59 %
Expected payoff -0.16
Gross Profit 54.48
Gross Loss -95.65
Total Net Profit -41.17
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.55
Total Trades 970
Won Trades 197
Lost trades 773
Win Rate 20.31 %
Expected payoff -0.15
Gross Profit 183.03
Gross Loss -330.70
Total Net Profit -147.67
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.46
Total Trades 312
Won Trades 57
Lost trades 255
Win Rate 18.27 %
Expected payoff -0.29
Gross Profit 76.20
Gross Loss -165.75
Total Net Profit -89.55
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.41
Total Trades 800
Won Trades 211
Lost trades 589
Win Rate 26.37 %
Expected payoff -0.26
Gross Profit 146.95
Gross Loss -356.56
Total Net Profit -209.61
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.03
Total Trades 611
Won Trades 179
Lost trades 432
Win Rate 29.30 %
Expected payoff -0.89
Gross Profit 16.64
Gross Loss -558.89
Total Net Profit -542.25
-100%
-50%
0%
50%
100%

Comments