Hans123MV1[1].2

Profit factor:
0.33
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
11 Views
0 Downloads
0 Favorites
Hans123MV1[1].2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                        Hans123MV |
//|                                     Copyright © 2005, Milan Volf |
//+------------------------------------------------------------------+

//---- input parameters
extern int       Start1=10;
extern int       Start2=14;
extern int       FirstSessionOnly=0;
extern int       Length=4;
extern int       EOD=24;
extern int       Pips=5;
extern int       StopLoss=50;
extern int       BreakEven=30;
extern int       TrailingStopStep=0;
extern int       TakeProfit=80;
extern double    Lots=1.0;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   //---- 
   int i,Ticket,LastOrderTime,StartTime,StartTime1,StartTime2,EODTime,MN;
   
   //Settings
   if (!IsTesting()){
      if (Symbol()=="EURUSD"){
         Start1=10;
         Start2=14;
         Length=4;
         EOD=24;
         Pips=5;
         StopLoss=50;
         BreakEven=30;
         TakeProfit=80;
      }   
      else if (Symbol()=="GBPUSD"){
         Start1=10;
         Start2=14;
         Length=4;
         EOD=24;
         Pips=5;
         StopLoss=70;
         BreakEven=40;
         TakeProfit=120;
      }
      else {
         Start1=10;
         Start2=14;
         Length=4;
         EOD=24;
         Pips=5;
         StopLoss=50;
         BreakEven=30;
         TakeProfit=80;
      }
   }

   //Count time
   if(CurTime()>=StrToTime(Start1+":00")-60){
      StartTime1=StrToTime(Start1+":00");
      StartTime2=StrToTime(Start2+":00");
      if(DayOfWeek()==5)   EODTime=MathMin(StrToTime("22:55"),StrToTime(EOD+":00"));
      else if (EOD==24)    EODTime=StrToTime("23:59");
      else                 EODTime=StrToTime(EOD+":00")-60;
   }
   
   //Set orders
   if(CurTime()>=StartTime1 && CurTime()<StartTime1+300){
      MN=1;
      StartTime=StartTime1;
      SetOrders(MN,StartTime);
   }
   if(CurTime()>=StartTime2 && CurTime()<StartTime2+300 && FirstSessionOnly==0){
      MN=2;
      StartTime=StartTime2;
      SetOrders(MN,StartTime);
   }
   
   //Manage of open orders
   for (i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(CurTime()<=GlobalVariableGet("LastOrderTime")+10) Sleep(10000);
      if(CurTime()>=EODTime){     //close open positions at EOD
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)      OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)     OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)  OrderDelete(OrderTicket());
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());
         GlobalVariableSet("LastOrderTime",CurTime());
      }   
      else {
         if(TrailingStopStep==0){    //move at BE if profit>BE
            if(OrderSymbol()==Symbol() && OrderType()==OP_BUY){
               if(High[0]-OrderOpenPrice()>=BreakEven*Point && OrderStopLoss()!=OrderOpenPrice()){
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
                  GlobalVariableSet("LastOrderTime",CurTime());
               }   
            }   
            if(OrderSymbol()==Symbol() && OrderType()==OP_SELL){
               if(OrderOpenPrice()-Low[0]>=BreakEven*Point && OrderStopLoss()!=OrderOpenPrice()){
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Green);
                  GlobalVariableSet("LastOrderTime",CurTime());
               }
            }
         }
         else {                  //use trailing stop
            if(OrderSymbol()==Symbol() && OrderType()==OP_BUY){
               if(High[0]-OrderStopLoss()>=(StopLoss+TrailingStopStep)*Point){
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+TrailingStopStep*Point,OrderTakeProfit(),0,Green);
                  GlobalVariableSet("LastOrderTime",CurTime());
               }   
            }   
            if(OrderSymbol()==Symbol() && OrderType()==OP_SELL){
               if(OrderStopLoss()-Low[0]>=(StopLoss+TrailingStopStep)*Point){
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-TrailingStopStep*Point,OrderTakeProfit(),0,Green);
                  GlobalVariableSet("LastOrderTime",CurTime());
               }
            }
         }
      }
   }
   
   //Reset global variables at EOD
   if(CurTime()>=EODTime) GlobalVariablesDeleteAll();
   
   return(0);
  }
//+------------------------------------------------------------------+

int SetOrders(int MN,int StartTime){
   int i,Ticket,LastOrderTime,Bought=0,Sold=0,ShiftToStart,ShiftToBeginOfRange;
   double EntryLong,EntryShort,SLLong,SLShort,TPLong,TPShort;
   
   //Determine range
   ShiftToStart=iBarShift(NULL,0,StartTime)+1;
   ShiftToBeginOfRange=iBarShift(NULL,0,StartTime-Length*3600);
   EntryLong   =High[Highest(NULL,0,MODE_HIGH,ShiftToBeginOfRange,ShiftToStart)]+(Pips/*+MarketInfo(Symbol(),MODE_SPREAD)*/)*Point;
   EntryShort  =Low [Lowest (NULL,0,MODE_LOW, ShiftToBeginOfRange,ShiftToStart)]-Pips*Point;
   SLLong      =MathMax(EntryLong-StopLoss*Point,EntryShort);
   SLShort     =MathMin(EntryShort+StopLoss*Point,EntryLong);
   TPLong      =EntryLong+TakeProfit*Point;
   TPShort     =EntryShort-TakeProfit*Point;
   
   //Check Orders
   for (i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUY) && OrderMagicNumber()==MN) Bought++;
      if(Bought>1){ //more than 1 buy order
         if(CurTime()<=GlobalVariableGet("LastOrderTime")+10) Sleep(10000);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)      OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)  OrderDelete(OrderTicket());
      }
      if(OrderSymbol()==Symbol() && (OrderType()==OP_SELLSTOP || OrderType()==OP_SELL) && OrderMagicNumber()==MN) Sold++;
      if(Sold>1){ //more than 1 sell order
         if(CurTime()<=GlobalVariableGet("LastOrderTime")+10) Sleep(10000);
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)     OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());
      }
   }
   if(Bought==0){ //no buy order
      if(CurTime()<=GlobalVariableGet("LastOrderTime")+10) Sleep(10000);
      Ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,EntryLong,3,SLLong,TPLong,NULL,MN,0,Green);
      if(Ticket<0 && GetLastError()==130)
         Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SLLong,TPLong,NULL,MN,0,Green);
      GlobalVariableSet("LastOrderTime",OrderOpenTime()); 
   }
   if(Sold==0){ //no sell order
      if(CurTime()<=GlobalVariableGet("LastOrderTime")+10) Sleep(10000);
      Ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,EntryShort,3,SLShort,TPShort,NULL,MN,0,Green);
      if(Ticket<0 && GetLastError()==130)
         Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,SLShort,TPShort,NULL,MN,0,Green);
      GlobalVariableSet("LastOrderTime",OrderOpenTime()); 
   }
}

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
0.84
Total Trades 175
Won Trades 97
Lost trades 78
Win Rate 55.43 %
Expected payoff -3.35
Gross Profit 3115.00
Gross Loss -3702.00
Total Net Profit -587.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.00
Total Trades 197
Won Trades 0
Lost trades 197
Win Rate 0.00 %
Expected payoff -48.91
Gross Profit 0.00
Gross Loss -9634.30
Total Net Profit -9634.30
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.01
Total Trades 267
Won Trades 3
Lost trades 264
Win Rate 1.12 %
Expected payoff -36.06
Gross Profit 61.21
Gross Loss -9689.35
Total Net Profit -9628.14
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.85
Total Trades 164
Won Trades 93
Lost trades 71
Win Rate 56.71 %
Expected payoff -3.16
Gross Profit 3038.00
Gross Loss -3557.00
Total Net Profit -519.00
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.25
Total Trades 217
Won Trades 77
Lost trades 140
Win Rate 35.48 %
Expected payoff -17.46
Gross Profit 1294.74
Gross Loss -5083.34
Total Net Profit -3788.60
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.39
Total Trades 200
Won Trades 96
Lost trades 104
Win Rate 48.00 %
Expected payoff -15.90
Gross Profit 2002.00
Gross Loss -5183.00
Total Net Profit -3181.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.16
Total Trades 230
Won Trades 86
Lost trades 144
Win Rate 37.39 %
Expected payoff -26.73
Gross Profit 1193.00
Gross Loss -7342.00
Total Net Profit -6149.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.68
Total Trades 192
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -7.14
Gross Profit 2931.00
Gross Loss -4301.00
Total Net Profit -1370.00
-100%
-50%
0%
50%
100%

Comments