TradersPowerExpert_v1.2_usdchf

Author: Copyright � 2006, Forex-TSD.com
Profit factor:
14462.13

This script is designed to automatically trade on the Forex market using the MetaTrader platform. Here's how it works, explained in a way that's easy to understand:

Overall Strategy:

The script aims to identify potential trading opportunities at the start of each trading day based on the previous days' price movements. It calculates expected high and low price ranges and places pending "buy stop" and "sell stop" orders accordingly. The ultimate goal is to enter trades that capitalize on anticipated price breakouts. It also implements money management and risk mitigation strategies.

Key Steps:

  1. Initialization: When the script starts, it sets up its basic parameters, like an identification number for its trades, acceptable price slippage, default trade sizes and imports external libraries.

  2. Money Management (Optional): It can optionally adjust the trade size ("Lots") based on your account balance and a risk percentage. If activated it determines the trade size based on how much of your account you're willing to risk losing on a single trade, and a maximum loss amount.

  3. Determining Trading Opportunities:

    • Daily Range Calculation: The script looks back at the previous few days (defined by "TradersPeriod") to calculate the average price movement ("range") for both buying and selling. It does this by calculating the average "bullish" (price increase) and "bearish" (price decrease) movements.
    • Opening Price: It determines the current day's opening price using hourly data.
    • Buy/Sell Levels: It calculates potential "Buy Stop" and "Sell Stop" order prices. These prices are based on the day's opening price, plus or minus a percentage (defined by "BuyPercent" and "SellPercent") of the average daily range (calculated previously). The calculation also takes into account the current spread (the difference between the buy and sell price).
  4. Order Placement:

    • Pending Orders: The script places pending orders to either buy if the price goes up to the calculated "Buy Stop" level, or sell if the price drops to the calculated "Sell Stop" level.
    • Stop Loss: It also sets an initial stop-loss order to limit potential losses if the price moves against the trade. The stop-loss level is determined as a percentage ("StopPercent") of the average daily range.
  5. Trade Management:

    • Time-Based Closing: The script can be configured to automatically close any open trades after a certain number of days ("TradePeriod") have passed, or when a profit is detected, useful for preventing trades from staying open indefinitely.
    • Break-Even Stop (Optional): If enabled, this feature automatically moves the stop-loss order to the trade's entry price (plus a small buffer) after the trade has reached a certain profit level ("BreakEven"). This guarantees that the trade will not result in a loss.
    • Trailing Stop (Optional): If enabled, this feature continuously adjusts the stop-loss order as the price moves in a favorable direction, locking in profits. The stop-loss will 'trail' the price.
    • Deleting Extra Orders: It checks for and deletes any extra pending orders that might have been left over from a previous day if a trade has already been triggered in the opposite direction.
  6. Day-of-Week Control: The script allows you to specify which days of the week it should be active (Monday through Friday).

In Summary:

This script is an automated trading system that attempts to profit from daily price fluctuations. It uses past price data to predict likely breakout levels, places pending orders at those levels, and manages the trades with stop-loss and profit-taking features. It is customizable with parameters to control risk, trade timing, and money management.

Price Data Components
Series array that contains open time of each bar
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
1 Downloads
0 Favorites
TradersPowerExpert_v1.2_usdchf
//+------------------------------------------------------------------+
//|                                        TradersPowerExpert_v1.mq4 |
//|                                  Copyright © 2006, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#include <stdlib.mqh>
//#include <Tracert.mqh>

//---- input parameters
extern string     Expert_Name = "---- TradersPowerExpert_v1 ----";

extern int        Magic=1007;
extern int        Slippage=6;

extern bool       Trace = false;           // Trace Switch

extern string     Main_Parameters = " Trade Volume & Trade Method";
extern double     Lots = 1;
extern bool       TrailingStop   = false;     // Trailing Stop Switch   
extern bool       InitialStop    = true;      // Initial Stop Switch
extern int        TimeZone       = 1;   

extern string     Data = " Input Data ";
extern int        TradersPeriod  = 4; 
extern double     BuyPercent     = 160;      // Percent from Daily Range for BUY 	
extern double     SellPercent    = 160;      // Percent from Daily Range for SELL
extern double     StopPercent    = 100;      // Percent from Daily Range for StopLoss
extern int        TradePeriod    = 5;       // Max days in trade 
extern double     BreakEven      = 85;       // BreakEven Level in pips
extern double     BreakEvenGap   = 8;       // Pips when BreakEven will be reached

extern string     Trade   =  " Trade Days of Week";
extern int        Monday         = 1;      // Day of the Week for Trade
extern int        Tuesday        = 1;
extern int        Wednesday      = 1;
extern int        Thursday       = 1;
extern int        Friday         = 1;

extern string     MM_Parameters = " MoneyManagement by L.Williams ";
extern bool       MM=false;                 // ÌÌ Switch
extern double     MMRisk=0.1;              // Risk Factor
extern double     LossMax=1466;             // Maximum Loss by 1 Lot


int      i,k,cnt=0, ticket, mode=0, digit=0, wenum=0, OrderOpenDay, Kz;
double   high,low, close[], open, range, Bulls,Bears,
         AvgBulls,AvgBears, SumBulls,SumBears,TodayOpen,spread=0, Profit=0;
double   smin=0, smax=0, BuyStop=0, SellStop=0, Lotsi=0, rates_h1[][6];
bool     BuyInTrade=false, SellInTrade=false;
datetime StartTime, prevwe=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 

//----
   return(0);
  }
// ---- Money Management
double MoneyManagement ( bool flag, double Lots, double risk, double maxloss)
{
   double Lotsi=Lots;
	    
   if ( flag ) Lotsi=NormalizeDouble(Lots*AccountFreeMargin()*risk/maxloss,1);   
     
   if (Lotsi<0.1) Lotsi=0.1;  
   return(Lotsi);
}   

// Closing of Pending Orders      
void PendOrdDel()
{
    int total=OrdersTotal();
    for (int cnt=total-1;cnt>=0;cnt--)
    { 
      OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);   
      
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic  )     
        {
        int mode=OrderType();
        
        bool result = false;
          switch(mode)
          {
            
            case OP_BUYSTOP   : {result = OrderDelete( OrderTicket() ); Print(" PendBUY"); }
          
            case OP_SELLSTOP  : {result = OrderDelete( OrderTicket() ); Print(" PendSELL"); }
          if(!result)
            {
            Print("OrderSend failed with error #",GetLastError());
            return(0);
            }
          //Print(" cnt=",cnt, " total=",total," MODE = ",mode," Ticket=",OrderTicket()  );                       
          }
         }
      } 
  return;
  }    

// 

void CloseOrdbyTime()
{
     int total=OrdersTotal();
     
     for (cnt=0;cnt<total;cnt++)
     { 
        OrderSelect(cnt, SELECT_BY_POS);   
        mode=OrderType();
        if ( mode <= OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        { 
          datetime OpenTime=StrToTime(TimeToStr(OrderOpenTime(),TIME_DATE));
          datetime CurnTime=StrToTime(TimeToStr(CurTime(),TIME_DATE)); 
          int weekday=TimeDayOfWeek(OrderOpenTime());
          if (weekday <=5 && DayOfWeek()==1 && CurnTime > prevwe && CurnTime > OpenTime) {wenum =wenum + 1; prevwe = CurnTime;}      
          //if (OrderOpenDay <= 5 && DayOfWeek()>0) 
          int CalcBars=TradePeriod+2*wenum; 
          //else CalcBars=TradePeriod;
         
            if ((CurTime()-OpenTime)>=PERIOD_D1*CalcBars*60 || OrderProfit()>0)
            {
              if (mode==OP_BUY )
			     OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);
			     if (mode==OP_SELL)
			     OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);
            }
        }
    }

}       
 
// ---- 
void TrailStops()
{        
    int total=OrdersTotal();
    for (cnt=0;cnt<total;cnt++)
    { 
     OrderSelect(cnt, SELECT_BY_POS);   
     mode=OrderType();    
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic ) 
        {
            if ( mode==OP_BUY && smin > OrderStopLoss() )
            {
            Profit=0;
			   OrderModify(OrderTicket(),OrderOpenPrice(),smin,Profit,0,LightGreen);
			   return(0);
            }
           if ( mode==OP_SELL && smax < OrderStopLoss())
            {
            Profit=0;
   		   OrderModify(OrderTicket(),OrderOpenPrice(),smax,Profit,0,Yellow);	    
            return(0);
            }    
        }
    }   
} 

void SellOrdOpen()
{		     

		  double SellPrice=TodayOpen - AvgBears * SellPercent/100.0 - spread;
		  
		  if (InitialStop) SellStop=SellPrice + StopPercent*AvgBears/100.0; else SellStop=0;
        Profit=0;
	       
		  ticket = OrderSend(Symbol(),OP_SELLSTOP,Lotsi,
		                     NormalizeDouble(SellPrice,digit),
		                     Slippage,
		                     NormalizeDouble(SellStop,digit),
		                     Profit,"SELL",Magic,0,Red);
    

        OrderOpenDay  = DayOfWeek();   
        
        SellInTrade=false;            
        Kz=1;     
            if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            return(0);
            }
}

void BuyOrdOpen()
{		     

		  double BuyPrice =TodayOpen + AvgBulls*BuyPercent/100.0  + spread;
		  if (InitialStop) BuyStop = BuyPrice - StopPercent*AvgBulls/100.0; else BuyStop=0;
        Profit=0;
		 
		  ticket = OrderSend(Symbol(),OP_BUYSTOP ,Lotsi,
		                     NormalizeDouble(BuyPrice ,digit),
		                     Slippage,
		                     NormalizeDouble(BuyStop ,digit),
		                     Profit,"BUY",Magic,0,Blue);
                
        
        OrderOpenDay  = DayOfWeek();
        BuyInTrade=false;            
        Kz=1;    
            if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            return(0);
            }
}      

void ExtraOrdDel()
{
    int total = OrdersTotal();
    for (cnt=0;cnt<total;cnt++)
    { 
      OrderSelect(cnt, SELECT_BY_POS);   
      mode=OrderType();
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic )     
        {
            if (mode==OP_BUY  && !BuyInTrade ) BuyInTrade =true;
            if (mode==OP_SELL && !SellInTrade) SellInTrade=true;
            
            if (mode == OP_SELLSTOP && BuyInTrade )
            { OrderDelete(OrderTicket()); SellInTrade=false; Print(" ExtraSell"); }
            if (mode == OP_BUYSTOP && SellInTrade )
            { OrderDelete(OrderTicket()); BuyInTrade=false; Print(" ExtraBuy"); }
    
	     }
	 }        
}

// ---- Scan Trades
int ScanTrades()
{   
   int total = OrdersTotal();
   int numords = 0;
      
   for(cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() && OrderType()>=OP_BUY && OrderMagicNumber() == Magic) 
   numords++;
   }
   return(numords);
}

datetime OrderOpenDate()
{
   int total = OrdersTotal();
   datetime date;
   for(cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() && OrderType()>=OP_BUY && OrderMagicNumber() == Magic) 
   date = StrToTime(TimeToStr(OrderOpenTime(),TIME_DATE));
   }
   return(date);
}  

void BreakEvenStop()
{        
   
    for (cnt=0;cnt<OrdersTotal();cnt++)
    { 
     OrderSelect(cnt, SELECT_BY_POS);   
     int mode=OrderType();    
        if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) 
        {
            if ( mode==OP_BUY )
            {
               if ( Bid-OrderOpenPrice() > 0 ) 
               {Kz = MathFloor((Bid-OrderOpenPrice())/(BreakEven*Point));
                if (Kz < 1) Kz=1;} 
			         else Kz = 1;
			       // Print(" Buy Kz=",Kz); 
               //BuyStop = OrderStopLoss();
			         if (Bid-OrderOpenPrice() > Kz*BreakEven*Point) 
			            {
			            BuyStop=OrderOpenPrice()+((Kz-1)*BreakEven+BreakEvenGap)*Point;
			            
			            OrderModify(OrderTicket(),OrderOpenPrice(),
			                        NormalizeDouble(BuyStop, digit),
			                        OrderTakeProfit(),0,LightBlue);
			            
			            //Kz=Kz+1;
			            return(0);
			            }
			      
			   }
            if ( mode==OP_SELL )
            {
               if ( OrderOpenPrice()-Ask > 0 ) 
               {Kz = MathFloor((OrderOpenPrice()-Ask)/(BreakEven*Point));
                if (Kz < 1) Kz=1;}  
			         else Kz = 1;
			        // Print(" Sell Kz=",Kz);
               //SellStop = OrderStopLoss();
                  if (OrderOpenPrice()-Ask > Kz*BreakEven*Point) 
			            {
			            SellStop=OrderOpenPrice()-((Kz-1)*BreakEven+BreakEvenGap)*Point;
			            
			            OrderModify(OrderTicket(),OrderOpenPrice(),
			                        NormalizeDouble(SellStop, digit),
			                        OrderTakeProfit(),0,Orange);
			            
			            //DrawStops("SellStop",SellStop,Orange);
			            //Kz=Kz+1;
			            return(0);
			            }
               
            }
        }   
    } 
}	                    
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   if(Bars < 1) {Print("Not enough bars for this strategy"); return(0);}
  
   //if ( Trace ) SetTrace();
  
   string   TimeTrade = "00:00";
   StartTime  = StrToTime(TimeTrade) + TimeZone*3600;
  
   if(Hour() >= TimeZone && Hour() <= TimeZone+1)
   {
     if ( OrderOpenDate() < StrToTime(TimeToStr( StartTime,TIME_DATE))) 
     { PendOrdDel(); if( TradePeriod > 0 )CloseOrdbyTime(); }
        if(ScanTrades()<1)
        {
      
         spread= MarketInfo(Symbol(),MODE_SPREAD)*Point;
         digit  = MarketInfo(Symbol(),MODE_DIGITS);
         Lotsi = MoneyManagement ( MM, Lots, MMRisk, LossMax);
         if (TrailingStop) InitialStop=true; 
   
         ArrayCopyRates(rates_h1, Symbol(), PERIOD_H1);
         TodayOpen = rates_h1[0][1];
         SumBulls=0;SumBears=0;
            for (k=TradersPeriod;k>=1;k--)
            {
            open = rates_h1[k*24][1];
            high=0; low=10000000;
               for (i=24;i>=1;i--)
               {
               high = MathMax( high, rates_h1[i+(k-1)*24][3]);
               low  = MathMin( low , rates_h1[i+(k-1)*24][2]);      
               
               }   
               
            range =(high-low); 
            Bulls = high - open;
            Bears = open - low;
            SumBulls += Bulls;
            SumBears += Bears; 
            //Print(" Bulls=",high,"Bears=",low);
            }
      
         AvgBulls = SumBulls/TradersPeriod;
         AvgBears = SumBears/TradersPeriod;
         //Print(" high=",AvgBulls,"low=",AvgBears);
         smin = Bid - StopPercent*AvgBears/100.0;
         smax = Ask + StopPercent*AvgBulls/100.0;
      
   
         if ( Monday   == 1 ) if(DayOfWeek()==1){BuyOrdOpen(); SellOrdOpen();}
         if ( Tuesday  == 1 ) if(DayOfWeek()==2){BuyOrdOpen(); SellOrdOpen();}
         if ( Wednesday== 1 ) if(DayOfWeek()==3){BuyOrdOpen(); SellOrdOpen();} 
         if ( Thursday == 1 ) if(DayOfWeek()==4){BuyOrdOpen(); SellOrdOpen();} 
         if ( Friday   == 1 ) if(DayOfWeek()==5){BuyOrdOpen(); SellOrdOpen();}
        }
      
    }
   ExtraOrdDel();
   if (BreakEven > 0) BreakEvenStop(); 
   if (TrailingStop) TrailStops(); 
 return(0);
}//int start
//+------------------------------------------------------------------+





Profitability Reports

EUR/USD Jul 2025 - Sep 2025
159727.78
Total Trades 129
Won Trades 125
Lost trades 4
Win Rate 96.90 %
Expected payoff 866734.44
Gross Profit 111809445.00
Gross Loss -700.00
Total Net Profit 111808745.00
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
158220.72
Total Trades 128
Won Trades 124
Lost trades 4
Win Rate 96.88 %
Expected payoff 865264.13
Gross Profit 110754507.00
Gross Loss -700.00
Total Net Profit 110753807.00
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
187.98
Total Trades 61
Won Trades 43
Lost trades 18
Win Rate 70.49 %
Expected payoff 9349.13
Gross Profit 573347.00
Gross Loss -3050.00
Total Net Profit 570297.00
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
15.77
Total Trades 21
Won Trades 20
Lost trades 1
Win Rate 95.24 %
Expected payoff 168.46
Gross Profit 3777.26
Gross Loss -239.58
Total Net Profit 3537.68
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
2.29
Total Trades 25
Won Trades 19
Lost trades 6
Win Rate 76.00 %
Expected payoff 56.92
Gross Profit 2529.00
Gross Loss -1106.00
Total Net Profit 1423.00
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
1.88
Total Trades 55
Won Trades 43
Lost trades 12
Win Rate 78.18 %
Expected payoff 38.00
Gross Profit 4464.60
Gross Loss -2374.34
Total Net Profit 2090.26
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
1.85
Total Trades 23
Won Trades 16
Lost trades 7
Win Rate 69.57 %
Expected payoff 32.51
Gross Profit 1623.08
Gross Loss -875.37
Total Net Profit 747.71
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
1.45
Total Trades 35
Won Trades 30
Lost trades 5
Win Rate 85.71 %
Expected payoff 13.89
Gross Profit 1567.00
Gross Loss -1081.00
Total Net Profit 486.00
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.91
Total Trades 62
Won Trades 46
Lost trades 16
Win Rate 74.19 %
Expected payoff -6.18
Gross Profit 3962.00
Gross Loss -4345.00
Total Net Profit -383.00
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.85
Total Trades 63
Won Trades 44
Lost trades 19
Win Rate 69.84 %
Expected payoff -8.38
Gross Profit 2971.00
Gross Loss -3499.00
Total Net Profit -528.00
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
0.82
Total Trades 62
Won Trades 50
Lost trades 12
Win Rate 80.65 %
Expected payoff -11.78
Gross Profit 3384.76
Gross Loss -4115.34
Total Net Profit -730.58
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.73
Total Trades 23
Won Trades 15
Lost trades 8
Win Rate 65.22 %
Expected payoff -17.76
Gross Profit 1081.80
Gross Loss -1490.39
Total Net Profit -408.59
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.70
Total Trades 29
Won Trades 17
Lost trades 12
Win Rate 58.62 %
Expected payoff -15.05
Gross Profit 1002.17
Gross Loss -1438.58
Total Net Profit -436.41
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.63
Total Trades 27
Won Trades 16
Lost trades 11
Win Rate 59.26 %
Expected payoff -22.89
Gross Profit 1042.00
Gross Loss -1660.00
Total Net Profit -618.00
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.62
Total Trades 26
Won Trades 18
Lost trades 8
Win Rate 69.23 %
Expected payoff -18.96
Gross Profit 789.00
Gross Loss -1282.00
Total Net Profit -493.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.54
Total Trades 33
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -36.58
Gross Profit 1422.00
Gross Loss -2629.00
Total Net Profit -1207.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.41
Total Trades 68
Won Trades 57
Lost trades 11
Win Rate 83.82 %
Expected payoff -25.97
Gross Profit 1231.85
Gross Loss -2997.97
Total Net Profit -1766.12
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.32
Total Trades 31
Won Trades 22
Lost trades 9
Win Rate 70.97 %
Expected payoff -33.84
Gross Profit 492.00
Gross Loss -1541.00
Total Net Profit -1049.00
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.27
Total Trades 56
Won Trades 41
Lost trades 15
Win Rate 73.21 %
Expected payoff -60.60
Gross Profit 1233.86
Gross Loss -4627.64
Total Net Profit -3393.78
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.15
Total Trades 58
Won Trades 31
Lost trades 27
Win Rate 53.45 %
Expected payoff -113.40
Gross Profit 1205.57
Gross Loss -7782.90
Total Net Profit -6577.33
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.06
Total Trades 23
Won Trades 8
Lost trades 15
Win Rate 34.78 %
Expected payoff -120.35
Gross Profit 162.12
Gross Loss -2930.18
Total Net Profit -2768.06
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.05
Total Trades 29
Won Trades 20
Lost trades 9
Win Rate 68.97 %
Expected payoff -66.71
Gross Profit 105.57
Gross Loss -2040.26
Total Net Profit -1934.69
-100%
-50%
0%
50%
100%

Comments