Profit factor:
0.69
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Indicator of the average true rangeMovement directional indexParabolic Stop and Reverse system
10 Views
0 Downloads
0 Favorites
preBar
//+------------------------------------------------------------------+
//|         4/8/2007                                     preBar.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
int MAGICMA=20070705;


extern double  Lots           =  0.1;
extern double  MaximumRisk    =  0.03;
extern double  stopFactor = 1;

extern double  TakeProfit1 = 150;
double  Stoploss1;

extern bool takeProfit = true;
extern bool sartrail = true;
extern bool MoneyManagement = true;

extern bool trendFilter = true;
extern int trendThreshold = 15;
extern int adxPeriod = 2;
//+------------------------------------------------------------------+
//| 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 && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }

//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }


double LotsOptimized()
  {
//---- select lot size
   double lot;
 lot = NormalizeDouble( (AccountFreeMargin()*MaximumRisk)/( iATR(NULL,0,20,0)*(1/Point)  )*0.1,1);
 
 
//---- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
  
  if(!NewBar())
  return;
  int    res;
  if(MoneyManagement)
   Lots = LotsOptimized();
 
  double close1 = Close[1];
  double open1 = Open[1];
  
  double trendLine =  iADX(NULL,0,adxPeriod,PRICE_WEIGHTED,MODE_MAIN,0);
  bool trendFilterRes = true;
  
  if(trendFilter==true)
  {
  if(trendLine>trendThreshold)
         trendFilterRes = true;
   else
         trendFilterRes = false;
  } 
  
 if ( Close[2]>Open[2] && close1< open1  &&trendFilterRes)
     {
      openSell();
      return;
     }
  
     
   
//---- buy conditions
   if (Close[2]<Open[2] && close1> open1  && trendFilterRes)
     {
      openBuy();   
    
      return;
     }
  
//----
  }
  
  void openBuy(){
  Print("Lots "+Lots);
  Stoploss1 = stopFactor * iATR(NULL,0,20,0)+ MarketInfo (Symbol(), MODE_SPREAD) * Point;
  int res;
  if(takeProfit)
         res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss1,Ask+TakeProfit1*Point,"preBar",MAGICMA,0,Blue);
     else
          res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss1,0,"preBar",MAGICMA,0,Blue); 
      if(res>0)
      {
      if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES))
         Print("SELL order opened : ",OrderOpenPrice());
      Comment("preBar opened buy order " + Ask);
      }
       else Print("Error opening SELL order : ",GetLastError()); 
  
  }
  
  void openSell(){
  Print("Lots "+Lots);
  Stoploss1 = stopFactor * iATR(NULL,0,20,0)+ MarketInfo (Symbol(), MODE_SPREAD) * Point;
  int res;
  if(takeProfit)
         res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss1,Bid-TakeProfit1*Point,"preBar",MAGICMA,0,Red);
     else
         res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss1,0,"preBar",MAGICMA,0,Red); 
     if(res>0)
      {
      if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES))
         Print("SELL order opened : ",OrderOpenPrice());
      Comment("preBar opened sell order " + Bid);
      }
       else Print("Error opening SELL order : ",GetLastError()); 
  
  }
  
  
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {

 
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
           if(!takeProfit &&  NewBar() && Open[1]> Close[1]) 
            {   OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
                openSell();
            }
            // should it be closed?
          // Function version check Sell condition to exit Buy
       
       // check for trailing stop
         if (  sartrail && (iSAR(NULL,0,0.02,0.2,1) > OrderStopLoss()) && (Bid > iSAR(NULL,0,0.02,0.2,1)) && (OrderOpenPrice() < iSAR(NULL,0,0.02,0.2,1)) && (iSAR(NULL,0,0.02,0.2,1) > iSAR(NULL,0,0.02,0.2,2)))
         {
          OrderModify(OrderTicket(),OrderOpenPrice(),iSAR(NULL,0,0.02,0.2,1),OrderTakeProfit(),0,Blue);
          Print("Order # ",OrderTicket()," updated at ",Hour(),":",Minute(),":",Seconds());
          return(0);
         }
            
       }
        if(OrderType()==OP_SELL)
           {
         if(!takeProfit && NewBar() && Open[1]< Close[1])
           { OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
             openBuy();
           }
           
   
            // should it be closed?
       // Function version check Buy condition to exit Sell
   
        if (sartrail && (iSAR(NULL,0,0.02,0.2,1) < OrderStopLoss()) && (Ask < iSAR(NULL,0,0.02,0.2,1)) && (OrderOpenPrice() > iSAR(NULL,0,0.02,0.2,1)) && (iSAR(NULL,0,0.02,0.2,1) < iSAR(NULL,0,0.02,0.2,2)))
         {
          OrderModify(OrderTicket(),OrderOpenPrice(),iSAR(NULL,0,0.02,0.2,1),OrderTakeProfit(),0,Blue);
          Print("Order # ",OrderTicket()," updated at ",Hour(),":",Minute(),":",Seconds());
          return(0);
         }  
              
        }
        }
     }
   return(0);
  }
// the end.
//----

//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
 
   setVariables(Symbol());
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----
  }
//+--------------------------------------------------------------

bool NewBar()
{
static datetime lastbar; 
datetime curbar = Time[0]; 
if(lastbar!=curbar){
   lastbar=curbar; 
   return (true); 
}   else 
{  return(false);   }

}

void setVariables(string symbol){

//if ( symbol=="AUDNZD") {MAGICMA =550001; tragetProfit = 4; stopLossFactor = 3.5; bandSD = 3.6; pipCross = 30; ratioTarget = 0.4; TrailingStop   = 50; TrailingStep   = 20; }
if ( symbol=="CHFJPY") {MAGICMA =240002; MaximumRisk   =  0.01;stopFactor = 4;TakeProfit1 = 120;trendThreshold = 20;adxPeriod = 3; }
if ( symbol=="GBPUSD") {MAGICMA =240003;  MaximumRisk   =  0.01;stopFactor = 3.2;TakeProfit1 = 350;trendThreshold =37;adxPeriod = 13; }
//if ( symbol=="EURGBP") {MAGICMA =550003; tragetProfit = 9; stopLossFactor = 4;bandSD = 5; pipCross = 55; ratioTarget = 0.3; TrailingStop   = 120; TrailingStep   = 5; }


 
}




Profitability Reports

GBP/USD Oct 2024 - Jan 2025
1.17
Total Trades 56
Won Trades 36
Lost trades 20
Win Rate 64.29 %
Expected payoff 2.96
Gross Profit 1162.00
Gross Loss -996.50
Total Net Profit 165.50
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.91
Total Trades 698
Won Trades 339
Lost trades 359
Win Rate 48.57 %
Expected payoff -1.03
Gross Profit 7100.83
Gross Loss -7816.46
Total Net Profit -715.63
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.86
Total Trades 1090
Won Trades 679
Lost trades 411
Win Rate 62.29 %
Expected payoff -1.11
Gross Profit 7259.32
Gross Loss -8463.90
Total Net Profit -1204.58
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.86
Total Trades 296
Won Trades 123
Lost trades 173
Win Rate 41.55 %
Expected payoff -3.54
Gross Profit 6362.12
Gross Loss -7409.18
Total Net Profit -1047.06
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.85
Total Trades 51
Won Trades 29
Lost trades 22
Win Rate 56.86 %
Expected payoff -3.07
Gross Profit 867.50
Gross Loss -1024.30
Total Net Profit -156.80
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.82
Total Trades 106
Won Trades 67
Lost trades 39
Win Rate 63.21 %
Expected payoff -4.38
Gross Profit 2146.80
Gross Loss -2610.70
Total Net Profit -463.90
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.79
Total Trades 586
Won Trades 216
Lost trades 370
Win Rate 36.86 %
Expected payoff -4.15
Gross Profit 9350.20
Gross Loss -11782.30
Total Net Profit -2432.10
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.78
Total Trades 425
Won Trades 229
Lost trades 196
Win Rate 53.88 %
Expected payoff -2.13
Gross Profit 3133.96
Gross Loss -4041.33
Total Net Profit -907.37
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.78
Total Trades 79
Won Trades 43
Lost trades 36
Win Rate 54.43 %
Expected payoff -3.72
Gross Profit 1071.70
Gross Loss -1365.40
Total Net Profit -293.70
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.78
Total Trades 452
Won Trades 160
Lost trades 292
Win Rate 35.40 %
Expected payoff -3.68
Gross Profit 6007.73
Gross Loss -7673.09
Total Net Profit -1665.36
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.77
Total Trades 775
Won Trades 382
Lost trades 393
Win Rate 49.29 %
Expected payoff -2.64
Gross Profit 7005.87
Gross Loss -9050.17
Total Net Profit -2044.30
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.76
Total Trades 770
Won Trades 343
Lost trades 427
Win Rate 44.55 %
Expected payoff -4.33
Gross Profit 10676.57
Gross Loss -14011.71
Total Net Profit -3335.14
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.75
Total Trades 852
Won Trades 415
Lost trades 437
Win Rate 48.71 %
Expected payoff -3.51
Gross Profit 8945.20
Gross Loss -11932.50
Total Net Profit -2987.30
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.73
Total Trades 363
Won Trades 160
Lost trades 203
Win Rate 44.08 %
Expected payoff -3.78
Gross Profit 3769.15
Gross Loss -5141.79
Total Net Profit -1372.64
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.71
Total Trades 678
Won Trades 272
Lost trades 406
Win Rate 40.12 %
Expected payoff -5.03
Gross Profit 8384.80
Gross Loss -11794.20
Total Net Profit -3409.40
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.70
Total Trades 354
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -5.68
Gross Profit 4598.60
Gross Loss -6608.70
Total Net Profit -2010.10
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.70
Total Trades 681
Won Trades 275
Lost trades 406
Win Rate 40.38 %
Expected payoff -5.22
Gross Profit 8260.80
Gross Loss -11813.40
Total Net Profit -3552.60
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.70
Total Trades 926
Won Trades 504
Lost trades 422
Win Rate 54.43 %
Expected payoff -2.94
Gross Profit 6253.69
Gross Loss -8972.45
Total Net Profit -2718.76
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.67
Total Trades 298
Won Trades 108
Lost trades 190
Win Rate 36.24 %
Expected payoff -5.08
Gross Profit 3058.11
Gross Loss -4572.19
Total Net Profit -1514.08
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.66
Total Trades 406
Won Trades 118
Lost trades 288
Win Rate 29.06 %
Expected payoff -7.44
Gross Profit 5971.50
Gross Loss -8992.00
Total Net Profit -3020.50
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.64
Total Trades 1013
Won Trades 591
Lost trades 422
Win Rate 58.34 %
Expected payoff -3.28
Gross Profit 5926.91
Gross Loss -9246.99
Total Net Profit -3320.08
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.64
Total Trades 275
Won Trades 89
Lost trades 186
Win Rate 32.36 %
Expected payoff -7.89
Gross Profit 3779.80
Gross Loss -5948.60
Total Net Profit -2168.80
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.63
Total Trades 402
Won Trades 210
Lost trades 192
Win Rate 52.24 %
Expected payoff -3.72
Gross Profit 2495.42
Gross Loss -3992.63
Total Net Profit -1497.21
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.63
Total Trades 408
Won Trades 116
Lost trades 292
Win Rate 28.43 %
Expected payoff -8.96
Gross Profit 6216.50
Gross Loss -9871.60
Total Net Profit -3655.10
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.59
Total Trades 261
Won Trades 83
Lost trades 178
Win Rate 31.80 %
Expected payoff -9.71
Gross Profit 3606.90
Gross Loss -6140.40
Total Net Profit -2533.50
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.54
Total Trades 378
Won Trades 163
Lost trades 215
Win Rate 43.12 %
Expected payoff -6.14
Gross Profit 2775.27
Gross Loss -5096.86
Total Net Profit -2321.59
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.39
Total Trades 313
Won Trades 87
Lost trades 226
Win Rate 27.80 %
Expected payoff -14.08
Gross Profit 2770.30
Gross Loss -7176.00
Total Net Profit -4405.70
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.39
Total Trades 568
Won Trades 215
Lost trades 353
Win Rate 37.85 %
Expected payoff -8.54
Gross Profit 3116.50
Gross Loss -7965.15
Total Net Profit -4848.65
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.29
Total Trades 355
Won Trades 151
Lost trades 204
Win Rate 42.54 %
Expected payoff -17.11
Gross Profit 2490.00
Gross Loss -8562.60
Total Net Profit -6072.60
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.20
Total Trades 421
Won Trades 115
Lost trades 306
Win Rate 27.32 %
Expected payoff -16.41
Gross Profit 1731.01
Gross Loss -8638.56
Total Net Profit -6907.55
-100%
-50%
0%
50%
100%

Comments