open_close&stochastic_strategy

Author: Copyright � 2008, MetaQuotes Software Corp.
Profit factor:
0.70
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Stochastic oscillator
11 Views
0 Downloads
0 Favorites
open_close&stochastic_strategy
//+------------------------------------------------------------------+
//|                                      èñïðàâëåííàÿ åâðîäîëëàð.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots               = 0.1;
extern double MaximumRisk        = 0.3;
extern double DecreaseFactor     = 100;
double  st1,st2;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,3);
//---- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
         //----
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//---- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
  int res;
 if(Volume[0]>1) return;

//---- ïîêóïàåì -----------------------
  
  if ( (iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_SIGNAL,0))) 
     if  ((Open[0]<Open[1])&&(Close[0]<Close[1])) 
    
  //  
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,15,0,"",0,0,Blue);
      return;
     }
//---- ïðîäàåì ------------------------
if ((iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_MAIN,0)<iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_SIGNAL,0)))  
    if((Open[0]>Open[1])&&(Close[0]>Close[1]))
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,15,0,"",0,0,Red);
      return;
     }
     
  }
//------------Çàêðûòèå ïîçèöèé----------------------------------------
void CheckForClose2()
{
 if(OrderType()==OP_BUY)  OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
 if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue);
//CheckForOpen();
}  

//
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose1()
  {
   if(Volume[0]>1) return;
//ïðîâåðêà íà ïðîèãðûø   
if ((AccountProfit()<0)&&(MathAbs(AccountProfit())>=(AccountMargin()*MaximumRisk))) 
   { 
   CheckForClose2();
   Print(" óáûòîê", AccountProfit());
   }/**/
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if ((iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_MAIN,0)<iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_SIGNAL,0)))
         if ((Open[0]>Open[1])&&(Close[0]>Close[1]))
         CheckForClose2();  
        }
      if(OrderType()==OP_SELL)
        {
         if ((iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,9,3,3,MODE_SMA,0,MODE_SIGNAL,0)))
             if ((Open[0]<Open[1])&&(Close[0]<Close[1]))
          CheckForClose2();
        }

  }
  
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+

void start()
 {

//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose1();
//---
  }
//+-----------------------------------------------+

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
1.85
Total Trades 52
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 190.05
Gross Profit 21559.71
Gross Loss -11676.86
Total Net Profit 9882.85
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
1.31
Total Trades 53
Won Trades 16
Lost trades 37
Win Rate 30.19 %
Expected payoff 337.03
Gross Profit 75795.29
Gross Loss -57932.93
Total Net Profit 17862.36
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.19
Total Trades 60
Won Trades 21
Lost trades 39
Win Rate 35.00 %
Expected payoff 43.71
Gross Profit 16444.19
Gross Loss -13821.65
Total Net Profit 2622.54
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.14
Total Trades 100
Won Trades 37
Lost trades 63
Win Rate 37.00 %
Expected payoff 63.23
Gross Profit 49987.92
Gross Loss -43664.97
Total Net Profit 6322.95
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
1.13
Total Trades 60
Won Trades 24
Lost trades 36
Win Rate 40.00 %
Expected payoff 55.57
Gross Profit 28582.45
Gross Loss -25248.15
Total Net Profit 3334.30
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
1.00
Total Trades 47
Won Trades 19
Lost trades 28
Win Rate 40.43 %
Expected payoff 0.86
Gross Profit 11564.09
Gross Loss -11523.51
Total Net Profit 40.58
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.97
Total Trades 45
Won Trades 19
Lost trades 26
Win Rate 42.22 %
Expected payoff -10.44
Gross Profit 14148.53
Gross Loss -14618.12
Total Net Profit -469.59
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.93
Total Trades 51
Won Trades 16
Lost trades 35
Win Rate 31.37 %
Expected payoff -19.07
Gross Profit 13341.36
Gross Loss -14314.14
Total Net Profit -972.78
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.93
Total Trades 80
Won Trades 21
Lost trades 59
Win Rate 26.25 %
Expected payoff -15.34
Gross Profit 17177.86
Gross Loss -18405.28
Total Net Profit -1227.42
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.76
Total Trades 111
Won Trades 35
Lost trades 76
Win Rate 31.53 %
Expected payoff -38.74
Gross Profit 13339.85
Gross Loss -17639.90
Total Net Profit -4300.05
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.69
Total Trades 51
Won Trades 10
Lost trades 41
Win Rate 19.61 %
Expected payoff -45.72
Gross Profit 5115.53
Gross Loss -7447.21
Total Net Profit -2331.68
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.68
Total Trades 110
Won Trades 26
Lost trades 84
Win Rate 23.64 %
Expected payoff -64.17
Gross Profit 15168.23
Gross Loss -22227.02
Total Net Profit -7058.79
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.63
Total Trades 61
Won Trades 9
Lost trades 52
Win Rate 14.75 %
Expected payoff -79.33
Gross Profit 8264.84
Gross Loss -13103.75
Total Net Profit -4838.91
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.62
Total Trades 121
Won Trades 25
Lost trades 96
Win Rate 20.66 %
Expected payoff -73.19
Gross Profit 14470.34
Gross Loss -23326.42
Total Net Profit -8856.08
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.60
Total Trades 119
Won Trades 30
Lost trades 89
Win Rate 25.21 %
Expected payoff -57.21
Gross Profit 10065.81
Gross Loss -16874.27
Total Net Profit -6808.46
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.60
Total Trades 128
Won Trades 45
Lost trades 83
Win Rate 35.16 %
Expected payoff -47.34
Gross Profit 9018.92
Gross Loss -15077.93
Total Net Profit -6059.01
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.60
Total Trades 78
Won Trades 27
Lost trades 51
Win Rate 34.62 %
Expected payoff -76.00
Gross Profit 8750.34
Gross Loss -14678.27
Total Net Profit -5927.93
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.55
Total Trades 53
Won Trades 13
Lost trades 40
Win Rate 24.53 %
Expected payoff -100.98
Gross Profit 6574.83
Gross Loss -11926.72
Total Net Profit -5351.89
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.55
Total Trades 87
Won Trades 22
Lost trades 65
Win Rate 25.29 %
Expected payoff -53.39
Gross Profit 5744.70
Gross Loss -10390.00
Total Net Profit -4645.30
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.45
Total Trades 136
Won Trades 35
Lost trades 101
Win Rate 25.74 %
Expected payoff -70.31
Gross Profit 7840.35
Gross Loss -17403.02
Total Net Profit -9562.67
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.43
Total Trades 89
Won Trades 26
Lost trades 63
Win Rate 29.21 %
Expected payoff -60.83
Gross Profit 4019.66
Gross Loss -9433.35
Total Net Profit -5413.69
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.41
Total Trades 125
Won Trades 22
Lost trades 103
Win Rate 17.60 %
Expected payoff -78.64
Gross Profit 6746.55
Gross Loss -16576.76
Total Net Profit -9830.21
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.30
Total Trades 103
Won Trades 20
Lost trades 83
Win Rate 19.42 %
Expected payoff -63.92
Gross Profit 2857.11
Gross Loss -9441.14
Total Net Profit -6584.03
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.28
Total Trades 59
Won Trades 10
Lost trades 49
Win Rate 16.95 %
Expected payoff -118.98
Gross Profit 2789.42
Gross Loss -9809.51
Total Net Profit -7020.09
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.17
Total Trades 122
Won Trades 18
Lost trades 104
Win Rate 14.75 %
Expected payoff -79.79
Gross Profit 2015.50
Gross Loss -11749.35
Total Net Profit -9733.85
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.00
Total Trades 41
Won Trades 10
Lost trades 31
Win Rate 24.39 %
Expected payoff -46690.50
Gross Profit 7749.59
Gross Loss -1922060.12
Total Net Profit -1914310.53
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.00
Total Trades 7
Won Trades 2
Lost trades 5
Win Rate 28.57 %
Expected payoff -476602.41
Gross Profit 2136.90
Gross Loss -3338353.67
Total Net Profit -3336216.77
-100%
-50%
0%
50%
100%

Comments