Author: Copyright � 2005, Nick Bilak
Profit factor:
0.59
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Moving average indicatorMoving average indicator
6 Views
0 Downloads
0 Favorites
mandarine
//+------------------------------------------------------------------+
//|                                                    mandarine.mq4 |
//|                                     Copyright © 2005, Nick Bilak |
//|                                        http://www.forex-tsd.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property link      "http://www.forex-tsd.com/"

#include <stdlib.mqh>

extern double StopLoss = 100;  
extern double TakeProfit = 200;  
extern double TrailingStop = 100;  
extern int    T3Periods = 5;  
extern int    FastPeriod = 5;  
extern int    SlowPeriod = 20;  
extern double Lots = 0.1;
extern double MaximumRisk = 3;
extern bool   FixedLot = false;


extern int    slippage=2;   	//slippage for market order processing
extern int    shift=1;			//shift to current bar, 
extern int    MAGICNUM=187233;


bool   buysig,sellsig; 
int    ttime,total;
string TradeSymbol;

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders()
  {
   int ord;
//----
   total=OrdersTotal();
   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICNUM)
        {
         ord++;
        }
     }
//---- return orders volume
	return(ord);
  }

double LotsRisk(int StopLoss)  { 
   double lot=Lots;
//---- select lot size
   if (!FixedLot)
      lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk*0.001/StopLoss,1);
   else
      lot=Lots;
//---- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
}

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForSignals(string symbol) {
      //double buy =iCustom(NULL,0,"signals-mandarine",T3Periods,FastPeriod,SlowPeriod,shift,0,0);
      //double sell=iCustom(NULL,0,"signals-mandarine",T3Periods,FastPeriod,SlowPeriod,shift,1,0);

      double t3=t3ma(T3Periods);
      double emaf11=iMA(symbol,0,FastPeriod,0,MODE_EMA,PRICE_CLOSE,shift);
      double emaf12=iMA(symbol,0,FastPeriod,0,MODE_EMA,PRICE_CLOSE,shift+1);
      double emas21=iMA(symbol,0,SlowPeriod,0,MODE_EMA,PRICE_OPEN,shift);
      double emas22=iMA(symbol,0,SlowPeriod,0,MODE_EMA,PRICE_OPEN,shift+1);
		
      sellsig=false;
      buysig=false;
      //if (t3>0) Print(t3);
      //if (sell>0) {
      if (emaf11<emas21 && emaf12>=emas22 && emaf11<t3) {
         sellsig=true;
      }
      //if (buy>0) {
      if (emaf11>emas21 && emaf12<=emas22 && emaf11>t3) {
         buysig=true;
      }
}

void CheckForOpen(string symbol) {
   int    res;
//---- sell conditions
   if(sellsig && ttime!=Time[0])  {
      res=OrderSend(symbol,OP_SELL,LotsRisk(StopLoss),Bid,slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,"t3",MAGICNUM,0,Red);
   	if (res<0) Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
      ttime=Time[0];
      return;
   }
//---- buy conditions
   if(buysig && ttime!=Time[0])  {
      res=OrderSend(symbol,OP_BUY,LotsRisk(StopLoss),Ask,slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,"t3",MAGICNUM,0,Blue);
   	if (res<0) Print("Error opening BUY order : ",ErrorDescription(GetLastError()));
      ttime=Time[0];
      return;
   }
}
  
  
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose(string symbol)  {
	total=OrdersTotal();
   for(int i=0;i<total;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)  break;
      if(OrderMagicNumber()!=MAGICNUM || OrderSymbol()!=symbol) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if (sellsig) {
            OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White);
         }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if (buysig) {
            OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White);
         }
         break;
        }
     }
}


//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()  {


   //---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;

	TradeSymbol=Symbol();

   //---- check for signals
   CheckForSignals(TradeSymbol);

   //---- calculate open orders by current symbol
   if (CalculateCurrentOrders()==0) 
      CheckForOpen(TradeSymbol);
   else
      CheckForClose(TradeSymbol);
	
	TrailStop(TradeSymbol);
}
//+------------------------------------------------------------------+

void TrailStop(string mySymbol) {
   double StopLoss,trailing;
   if ( TrailingStop>=8 ) {
   	trailing=TrailingStop*Point;
      for (int i = 0; i < OrdersTotal(); i++) {
         if ( OrderSelect (i, SELECT_BY_POS) == false )  continue;
         if ( OrderSymbol() != mySymbol || OrderMagicNumber() != MAGICNUM )  continue;
         if ( OrderType() == OP_BUY ) {
            StopLoss = Bid-trailing;
            if ( StopLoss > OrderStopLoss() ) {
               OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);
            }
         }
   
         if ( OrderType() == OP_SELL ) {
            StopLoss = Ask+trailing;
            if ( StopLoss < OrderStopLoss() ) {
               OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold);
            }
         }
      }
   }
   return;
}


double t3ma(int Periods) {
	int i,limit=Periods*5;
	double e1[1],e2[1],e3[1],e4[1],e5[1],e6[1],e7[1];
	ArrayResize(e1,limit*4);
	ArrayResize(e2,limit*4);
	ArrayResize(e3,limit*4);
	ArrayResize(e4,limit*4);
	ArrayResize(e5,limit*4);
	ArrayResize(e6,limit*4);
	ArrayResize(e7,limit*4);
	ArraySetAsSeries(e1,true);
	ArraySetAsSeries(e2,true);
	ArraySetAsSeries(e3,true);
	ArraySetAsSeries(e4,true);
	ArraySetAsSeries(e5,true);
	ArraySetAsSeries(e6,true);
	ArraySetAsSeries(e7,true);
   for(i=limit+Periods*5; i>=0; i--) {
   	e1[i]=iMA(NULL,0,Periods,0,MODE_EMA,PRICE_CLOSE,i);
   }
   for(i=limit+Periods*4; i>=0; i--) {
   	e2[i]=iMAOnArray(e1,0,Periods,0,MODE_EMA,i);
   }
   for(i=limit+Periods*3; i>=0; i--) {
   	e3[i]=iMAOnArray(e2,0,Periods,0,MODE_EMA,i);
   }
   for(i=limit+Periods*2; i>=0; i--) {
   	e4[i]=iMAOnArray(e3,0,Periods,0,MODE_EMA,i);
   }
   for(i=limit+Periods; i>=0; i--) {
   	e5[i]=iMAOnArray(e4,0,Periods,0,MODE_EMA,i);
   }
	double a=0.8;
	double c1=-a*a*a;
	double c2=3*a*a+3*a*a*a;
	double c3=-6*a*a-3*a-3*a*a*a;
	double c4=1+3*a+a*a*a+3*a*a;
   for(i=limit; i>=0; i--) {
   	e6[i]=iMAOnArray(e5,0,Periods,0,MODE_EMA,i);
   	e7[i]=c1*e6[i]+c2*e5[i]+c3*e4[i]+c4*e3[i];
   }
   return(e7[0]);
}

Profitability Reports

GBP/CAD Jul 2025 - Sep 2025
0.47
Total Trades 59
Won Trades 17
Lost trades 42
Win Rate 28.81 %
Expected payoff -7.29
Gross Profit 382.95
Gross Loss -812.77
Total Net Profit -429.82
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.45
Total Trades 71
Won Trades 18
Lost trades 53
Win Rate 25.35 %
Expected payoff -6.23
Gross Profit 354.70
Gross Loss -796.87
Total Net Profit -442.17
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
1.48
Total Trades 59
Won Trades 28
Lost trades 31
Win Rate 47.46 %
Expected payoff 5.01
Gross Profit 909.00
Gross Loss -613.50
Total Net Profit 295.50
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.24
Total Trades 57
Won Trades 24
Lost trades 33
Win Rate 42.11 %
Expected payoff 2.84
Gross Profit 831.90
Gross Loss -670.20
Total Net Profit 161.70
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.80
Total Trades 142
Won Trades 43
Lost trades 99
Win Rate 30.28 %
Expected payoff -1.98
Gross Profit 1146.67
Gross Loss -1427.93
Total Net Profit -281.26
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.38
Total Trades 161
Won Trades 39
Lost trades 122
Win Rate 24.22 %
Expected payoff -10.60
Gross Profit 1063.80
Gross Loss -2771.00
Total Net Profit -1707.20
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.19
Total Trades 156
Won Trades 21
Lost trades 135
Win Rate 13.46 %
Expected payoff -14.62
Gross Profit 534.20
Gross Loss -2814.30
Total Net Profit -2280.10
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.20
Total Trades 184
Won Trades 31
Lost trades 153
Win Rate 16.85 %
Expected payoff -10.76
Gross Profit 492.48
Gross Loss -2472.88
Total Net Profit -1980.40
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.37
Total Trades 167
Won Trades 34
Lost trades 133
Win Rate 20.36 %
Expected payoff -8.20
Gross Profit 798.72
Gross Loss -2168.18
Total Net Profit -1369.46
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.43
Total Trades 143
Won Trades 33
Lost trades 110
Win Rate 23.08 %
Expected payoff -8.95
Gross Profit 949.80
Gross Loss -2229.00
Total Net Profit -1279.20
-100%
-50%
0%
50%
100%

Comments