Three moving averagesEsteban

Author: Copyright � 2008, TradingSytemForex
Profit factor:
0.79
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Indicators Used
Moving average indicator
5 Views
0 Downloads
0 Favorites
Three moving averagesEsteban
//+------------------------------------------------------------------+
//|                                         Three moving averages EA |
//|                              Copyright © 2008, TradingSytemForex |
//|                                http://www.tradingsystemforex.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2008, TradingSytemForex"
#property link "http://www.tradingsystemforex.com"

#define OrSt "Three moving averages EA"

extern string IS="---------------- Indicator Settings";
extern double Short_Period=7;
extern double Middle_Period=10;
extern double Long_Period=12;
extern double Mode_MA=1; //0=simple, 1=exponential, 2=smoothed, 3=linea weighted
extern string LM="---------------- Lot Management";
extern double Lots=0.1;
extern bool MM=false; //money management
extern double Risk=10; //risk in percentage
extern string TSTB="---------------- TP SL TS BE";
bool RealSL_Enabled=false;
int RealSL=5; //stop loss under 15 pîps
bool RealTP_Enabled=false;
int RealTP=10; //take profit under 10 pîps
extern int SL=0; //stop loss
extern int TP=0; //take profit
extern int TS=0; //trailing stop
extern int TS_Step=1; //trailing stop step
extern int BE=0; //breakeven
extern string EXT="---------------- Extras";
extern bool Reverse=false;
extern bool Add_Positions=true; //positions cumulated
extern int MaxOrders=100; //maximum number of orders
extern int Magic=0;

int Slip=3;static int TL=0;double MML=0;

// expert start function
int start(){int j=0,limit=1;double BV=0,SV=0;BV=0;SV=0;double SMA1a,SMA1b,SMA2a,SMA2b,SMA3a,SMA3b;
  if(CntO(OP_BUY,Magic)>0) TL=1;if(CntO(OP_SELL,Magic)>0) TL=-1;for(int i=1;i<=limit;i++){
  
  SMA1a=iMA(Symbol(),0,Short_Period,0,Mode_MA,PRICE_CLOSE,i+1);
  SMA1b=iMA(Symbol(),0,Short_Period,0,Mode_MA,PRICE_CLOSE,i);
  SMA2a=iMA(Symbol(),0,Middle_Period,0,Mode_MA,PRICE_CLOSE,i+1);
  SMA2b=iMA(Symbol(),0,Middle_Period,0,Mode_MA,PRICE_CLOSE,i);
  SMA3a=iMA(Symbol(),0,Long_Period,0,Mode_MA,PRICE_CLOSE,i+1);
  SMA3b=iMA(Symbol(),0,Long_Period,0,Mode_MA,PRICE_CLOSE,i);

  if((SMA1a<SMA3a && SMA1b>SMA3b)||(SMA1a<SMA2a && SMA1b>SMA2b && SMA2b>SMA3b)){if(Reverse) SV=1; else BV=1; break;}
  if((SMA1a>SMA3a && SMA1b<SMA3b)||(SMA1a>SMA2a && SMA1b<SMA2b && SMA2b<SMA3b)){if(Reverse) BV=1; else SV=1; break;}}

// expert money management
if(MM){if(Risk<0.1 || Risk>100) {Comment("Invalid Risk Value."); return(0);}
   else {MML=MathFloor((AccountFreeMargin() *AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT )))*MarketInfo(Symbol(),MODE_MINLOT );}}
if(MM==false){MML=Lots;}

// expert init positions
int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0; cnt<OrdersTotal();cnt++) {OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if((OrderType()==OP_SELL || OrderType()==OP_BUY) && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) OP=OP+1;}
if(OP>=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0;

// expert conditions to open position
if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}

// expert conditions to close position
if((SV>0) || (RealSL_Enabled && (OrderOpenPrice()-Bid)/Point>=RealSL)||(RealTP_Enabled && (Ask-OrderOpenPrice())/Point>=RealTP)){CB=1;}
if((BV>0) || (RealSL_Enabled && (Ask-OrderOpenPrice())/Point>=RealSL)||(RealTP_Enabled && (OrderOpenPrice()-Bid)/Point>=RealTP)){CS=1;}
for(cnt=0;cnt<OrdersTotal();cnt++){OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
	if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){if (CB==1){OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red); return(0);}}
	if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)){
	if(CS==1){OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);return(0);}}}double SLI=0,TPI=0;int TK=0;

// expert open position value
if((AddP() && Add_Positions && OP<=MaxOrders) || (OP==0 && !Add_Positions)) {
	if(OS==1){if (TP==0) TPI=0; else TPI=Bid-TP*Point;if (SL==0) SLI=0; else SLI=Bid+SL*Point;TK=OrderSend(Symbol(),OP_SELL,MML,Bid,Slip,SLI,TPI,OrSt,Magic,0,Red);OS=0;return(0);}	
	if(OB==1){if(TP==0) TPI=0; else TPI=Ask+TP*Point;if(SL==0) SLI=0; else SLI=Ask-SL*Point;TK=OrderSend(Symbol(),OP_BUY,MML,Ask,Slip,SLI,TPI,OrSt,Magic,0,Lime);OB=0; return(0);}}
for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS, MODE_TRADES)){if (OrderSymbol()==Symbol() && ((OrderMagicNumber()==Magic) || Magic==0)) {TrP();}}}return(0);}

// expert number of orders
int CntO(int Type,int Magic){int _CntO;_CntO=0;
for(int j=0;j<OrdersTotal();j++){OrderSelect(j, SELECT_BY_POS, MODE_TRADES);if(OrderSymbol()==Symbol()) {if((OrderType()==Type && (OrderMagicNumber()==Magic) || Magic==0)) _CntO++;}}return(_CntO);}

// expert trailing stop
void TrP(){double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if (OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID);

//expert breakeven
    if(BE>0){if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}}
    if(TS>0){if((pb-OrderOpenPrice())>TS*pp){if(OrderStopLoss()<pb-(TS+TS_Step-1)*pp){ModSL(pb-TS*pp);return;}}}}
  if(OrderType()==OP_SELL){pa=MarketInfo(OrderSymbol(),MODE_ASK);if(BE>0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}}
  if (TS>0){if (OrderOpenPrice()-pa>TS*pp){if (OrderStopLoss()>pa+(TS+TS_Step-1)*pp || OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}}

//expert stoploss
void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

//expert add positions function
bool AddP(){int _num=0; int _ot=0;
for (int j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()<3 && ((OrderMagicNumber()==Magic) || Magic==0)) {	
	 _num++;if(OrderOpenTime()>_ot) _ot=OrderOpenTime();}}
if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);}

Profitability Reports

GBP/USD Jul 2025 - Sep 2025
0.80
Total Trades 206
Won Trades 49
Lost trades 157
Win Rate 23.79 %
Expected payoff -2.22
Gross Profit 1836.00
Gross Loss -2294.00
Total Net Profit -458.00
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.32
Total Trades 226
Won Trades 39
Lost trades 187
Win Rate 17.26 %
Expected payoff -10.32
Gross Profit 1074.51
Gross Loss -3407.33
Total Net Profit -2332.82
-100%
-50%
0%
50%
100%
GBP/AUD Jul 2025 - Sep 2025
0.49
Total Trades 197
Won Trades 41
Lost trades 156
Win Rate 20.81 %
Expected payoff -7.11
Gross Profit 1335.91
Gross Loss -2736.82
Total Net Profit -1400.91
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
1.33
Total Trades 192
Won Trades 58
Lost trades 134
Win Rate 30.21 %
Expected payoff 546.89
Gross Profit 423291.30
Gross Loss -318287.70
Total Net Profit 105003.60
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.59
Total Trades 233
Won Trades 60
Lost trades 173
Win Rate 25.75 %
Expected payoff -2.89
Gross Profit 974.30
Gross Loss -1647.40
Total Net Profit -673.10
-100%
-50%
0%
50%
100%
USD/JPY Jul 2025 - Sep 2025
1.30
Total Trades 91
Won Trades 31
Lost trades 60
Win Rate 34.07 %
Expected payoff 3.64
Gross Profit 1437.79
Gross Loss -1106.98
Total Net Profit 330.81
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.70
Total Trades 99
Won Trades 28
Lost trades 71
Win Rate 28.28 %
Expected payoff -4.24
Gross Profit 971.59
Gross Loss -1391.35
Total Net Profit -419.76
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.98
Total Trades 100
Won Trades 29
Lost trades 71
Win Rate 29.00 %
Expected payoff -0.14
Gross Profit 772.18
Gross Loss -786.57
Total Net Profit -14.39
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
1.14
Total Trades 84
Won Trades 25
Lost trades 59
Win Rate 29.76 %
Expected payoff 1.13
Gross Profit 756.20
Gross Loss -661.00
Total Net Profit 95.20
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.82
Total Trades 107
Won Trades 27
Lost trades 80
Win Rate 25.23 %
Expected payoff -2.79
Gross Profit 1336.90
Gross Loss -1635.30
Total Net Profit -298.40
-100%
-50%
0%
50%
100%

Comments