Author: Copyright � 2005, Nick Bilak
Profit factor:
0.60
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
7 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

NZD/USD Jul 2025 - Sep 2025
0.69
Total Trades 116
Won Trades 32
Lost trades 84
Win Rate 27.59 %
Expected payoff -4.35
Gross Profit 1130.40
Gross Loss -1635.00
Total Net Profit -504.60
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.67
Total Trades 151
Won Trades 43
Lost trades 108
Win Rate 28.48 %
Expected payoff -4.88
Gross Profit 1525.20
Gross Loss -2262.30
Total Net Profit -737.10
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.26
Total Trades 147
Won Trades 28
Lost trades 119
Win Rate 19.05 %
Expected payoff -9.46
Gross Profit 482.44
Gross Loss -1872.86
Total Net Profit -1390.42
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
0.94
Total Trades 135
Won Trades 48
Lost trades 87
Win Rate 35.56 %
Expected payoff -0.85
Gross Profit 1679.40
Gross Loss -1794.30
Total Net Profit -114.90
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.55
Total Trades 141
Won Trades 37
Lost trades 104
Win Rate 26.24 %
Expected payoff -6.27
Gross Profit 1059.00
Gross Loss -1942.50
Total Net Profit -883.50
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
0.84
Total Trades 57
Won Trades 19
Lost trades 38
Win Rate 33.33 %
Expected payoff -1.64
Gross Profit 473.80
Gross Loss -567.31
Total Net Profit -93.51
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.84
Total Trades 79
Won Trades 28
Lost trades 51
Win Rate 35.44 %
Expected payoff -2.85
Gross Profit 1139.57
Gross Loss -1364.36
Total Net Profit -224.79
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.52
Total Trades 56
Won Trades 16
Lost trades 40
Win Rate 28.57 %
Expected payoff -5.54
Gross Profit 334.15
Gross Loss -644.23
Total Net Profit -310.08
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
0.00
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.86
Total Trades 64
Won Trades 25
Lost trades 39
Win Rate 39.06 %
Expected payoff -2.09
Gross Profit 839.70
Gross Loss -973.20
Total Net Profit -133.50
-100%
-50%
0%
50%
100%

Comments