EA with crossing moving average

 

Hi,

I´m looking for an EA that works with the simples signal : cross of 2 moving averages (simple, or exponencial)....I ve tried to download many of the EA that are in the MQL4 community, but no one seems to work, because no orders are sent in my metatrader...Can anybody post this EA if possible? Thank you

 
I ´ve find this EA...but it don t send orders... I ve tried in EURUSD- 1 minute but no orders sent ..can somebody help me?
Files:
2ma.mq4  10 kb
 

https://www.mql5.com/en/code/8463

Haven't tried it but it looks as though it fits the bill.,


Joao142:

....I ve tried to download many of the EA that are in the MQL4 community, but no one seems to work, because no orders are sent in my metatrader...


Just worth checking... I assume you've got "Enable EA's" and "Allow live trading" options both ticked

V

 
Viffer:

https://www.mql5.com/en/code/8463

Haven't tried it but it looks as though it fits the bill.,


Just worth checking... I assume you've got "Enable EA's" and "Allow live trading" options both ticked

V



enable EA and allow live trading ok, but no orders are sent...
 
The linked EA traded for me (admitedly not very well) in backtest so there must be a problem with your terminal settings somewhere.
 
Viffer:
The linked EA traded for me (admitedly not very well) in backtest so there must be a problem with your terminal settings somewhere.

in backtest it runs...and in demonstration account? 1 min GBPUSD...does it work?
 

Alpari demo GBPUSD traded fine on 5 min... I don't have the 1 min data history for that pair 'cos my terminal is offline while i'm running tests. Traded on 1 min EURUSD though

 
Viffer:

Alpari demo GBPUSD traded fine on 5 min... I don't have the 1 min data history for that pair 'cos my terminal is offline while i'm running tests. Traded on 1 min EURUSD though



I ve just detected that my EA onlu send orders if I put the option : ask manual confirmation.... but so that not more automatic anymore...any suggestion????
 
Joao142:

Hi,

I´m looking for an EA that works with the simples signal : cross of 2 moving averages (simple, or exponencial)....I ve tried to download many of the EA that are in the MQL4 community, but no one seems to work, because no orders are sent in my metatrader...Can anybody post this EA if possible? Thank you


Hi Joao142,

Im new undere R8ed R. I have a EA MA cross but it only works on IBFX. Every other broker gives me a "invalid stop" in the expert field. Again i have not problems in IBFX. Could you help me with getting it to work on MBtrading?

#property copyright "Copyright - Interbank FX, LLC."
#property link "http://www.ibfx.com/"
#include "include\stderror.mqh"
//+------------------------------------------------------------------+
//| Global Variables / Includes |
//+------------------------------------------------------------------+
datetime CurrTime = 0;
datetime PrevTime = 0;
string Sym = "";
int TimeFrame = 0;
int Shift = 1;
int SymDigits = 5;
double SymPoints = 0.0001;

int MA1ArraySelected = 0;
int MA2ArraySelected = 0;
int MA1MethodSelected = 0;
int MA2MethodSelected = 0;
//+------------------------------------------------------------------+
//| Expert User Inputs |
//+------------------------------------------------------------------+
extern bool UseCompletedBars = true;

// Create any user input for the indicators you will use here
// For example:
extern string MA1Array = "Close";
extern string MA2Array = "Close";
extern int MA1Periods = 12;
extern int MA2Periods = 26;
extern string MA1Method = "Simple";
extern string MA2Method = "Simple";

extern double Lots = 0.01;
extern int MagicNumber = 1235;
extern int ProfitTarget = 100;
extern int StopLoss = 100;
extern int Slippage = 3;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
Sym = Symbol();
TimeFrame = Period();
SymPoints = MarketInfo( Sym, MODE_POINT );
SymDigits = MarketInfo( Sym, MODE_DIGITS );
//---
if( SymPoints == 0.001 ) { SymPoints = 0.01; SymDigits = 3; }
else if( SymPoints == 0.00001 ) { SymPoints = 0.0001; SymDigits = 5; }

//------------------ CLOSE -------------------------
if(MA1Array == "C") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "CLOSE") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "Close") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "c") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "close") {MA1ArraySelected = PRICE_CLOSE;}
//------------------ LOW -------------------------
else if(MA1Array == "L") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "LOW") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "Low") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "l") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "low") {MA1ArraySelected = PRICE_LOW;}
//------------------ HIGH -------------------------
else if(MA1Array == "H") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "HIGH") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "High") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "h") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "high") {MA1ArraySelected = PRICE_HIGH;}
//------------------ OPEN-------------------------
else if(MA1Array == "O") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "OPEN") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "Open") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "o") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "open") {MA1ArraySelected = PRICE_OPEN;}
//------------------ Typical -------------------------
else if(MA1Array == "TYPICAL") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "Typical") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "typical") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "T") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "t") {MA1ArraySelected = PRICE_TYPICAL;}
//------------------ MEDIAN -------------------------------
else if(MA1Array == "MEDIAN") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "Median") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "median") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "M") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "m") {MA1ArraySelected = PRICE_MEDIAN;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid array in open, high, Low, Close, Typical, Median" );
return(-1);
}

//------------------ CLOSE -------------------------
if(MA2Array == "C") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "CLOSE") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "Close") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "c") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "close") {MA2ArraySelected = PRICE_CLOSE;}
//------------------ LOW -------------------------
else if(MA2Array == "L") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "LOW") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "Low") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "l") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "low") {MA2ArraySelected = PRICE_LOW;}
//------------------ HIGH -------------------------
else if(MA2Array == "H") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "HIGH") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "High") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "h") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "high") {MA2ArraySelected = PRICE_HIGH;}
//------------------ OPEN-------------------------
else if(MA2Array == "O") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "OPEN") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "Open") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "o") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "open") {MA2ArraySelected = PRICE_OPEN;}
//------------------ Typical -------------------------
else if(MA2Array == "TYPICAL") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "Typical") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "typical") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "T") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "t") {MA2ArraySelected = PRICE_TYPICAL;}
//------------------ MEDIAN -------------------------------
else if(MA2Array == "MEDIAN") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "Median") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "median") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "M") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "m") {MA2ArraySelected = PRICE_MEDIAN;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid array in open, high, Low, Close, Typical, Median" );
return(-1);
}
//------------------ CLOSE -------------------------
if(MA1Method == "Simple") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "SIMPLE") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "S") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "s") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "simple") {MA1MethodSelected = MODE_SMA; }
//------------------ LOW -------------------------
else if(MA1Method == "Exponential") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "EXPONENTIAL") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "E") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "e") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "exponential") { MA1MethodSelected = MODE_EMA;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid Method: Simple or Exponential" );
return(-1);
}
//------------------ CLOSE -------------------------
if(MA2Method == "Simple") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "SIMPLE") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "S") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "s") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "simple") {MA2MethodSelected = MODE_SMA; }
//------------------ LOW -------------------------
else if(MA2Method == "Exponential") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "EXPONENTIAL") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "E") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "e") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "exponential") { MA2MethodSelected = MODE_EMA;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid Method: Simple or Exponential" );
return(-1);
}

//----
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() { return(0); }

//+------------------------------------------------------------------+
//| Expert start function |
//+------------------------------------------------------------------+
int start()
{
int RealTime = 0;
if( UseCompletedBars )
{
CurrTime = iTime(Sym, TimeFrame, 1 );
if( CurrTime == PrevTime )
{
return(0);
}
//---- Update Vars
PrevTime = CurrTime;
RealTime = 1;
}

//---- Need to chek for a new Signal?
if( CountAll( Sym, MagicNumber) == 0)
{
//---- Indicator 1 Values
double Indicator1CurrentValue = iMA(NULL,0,MA1Periods,0,MA1MethodSelected, MA1ArraySelected,0+RealTime);
double Indicator1PreviousValue = iMA(NULL,0,MA1Periods,0,MA1MethodSelected, MA1ArraySelected,1+RealTime);
//---- Indicator 2 Values
double Indicator2CurrentValue = iMA(NULL,0,MA2Periods,0,MA2MethodSelected, MA2ArraySelected,0+RealTime);
double Indicator2PreviousValue = iMA(NULL,0,MA2Periods,0,MA2MethodSelected, MA2ArraySelected,1+RealTime);

//---- Moving Average Cross System
if( Indicator1CurrentValue > Indicator2CurrentValue && Indicator1PreviousValue <= Indicator2PreviousValue ) { EnterLong(Sym, Lots, ""); }
else if( Indicator1CurrentValue < Indicator2CurrentValue && Indicator1PreviousValue >= Indicator2PreviousValue ) { EnterShrt(Sym, Lots, ""); }
}
//----

//----
return(0);
}

//+------------------------------------------------------------------+
//| Expert Custom Functions |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| CountAll() |
//+------------------------------------------------------------------+
int CountAll( string Symbole, int Magic )
{
//----
int count = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ( OrderMagicNumber() != Magic ) continue;
if ( OrderSymbol() != Symbole ) continue;

if ( OrderType() == OP_BUY ) { count++; }
else if ( OrderType() == OP_SELL ) { count++; }
}
//----
return(count);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Stop Long |
//+------------------------------------------------------------------+
double StopLong(double price,double stop,double point,double SymDgts )
{
if(stop==0) { return(0); }
else { return(NormalizeDouble( price-(stop*point),SymDgts)); }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Stop Short |
//+------------------------------------------------------------------+
double StopShrt(double price,double stop,double point,double SymDgts )
{
if(stop==0) { return(0); }
else { return(NormalizeDouble( price+(stop*point),SymDgts)); }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Profit Target Long |
//+------------------------------------------------------------------+
double TakeLong(double price,double take,double point,double SymDgts )
{
if(take==0) { return(0);}
else { return(NormalizeDouble( price+(take*point),SymDgts));}
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Profit Target Long |
//+------------------------------------------------------------------+
double TakeShrt(double price,double take,double point,double SymDgts )
{
if(take==0) { return(0);}
else { return(NormalizeDouble( price-(take*point),SymDgts));}
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Place Long Order |
//+------------------------------------------------------------------+
int EnterLong( string FinalSymbol, double FinalLots, string EA_Comment )
{
int Ticket = -1; int err = 0; bool OrderLoop = False; int TryCount = 0;

while( !OrderLoop )
{
while( IsTradeContextBusy() ) { Sleep( 10 ); }

RefreshRates();
double SymAsk = NormalizeDouble( MarketInfo( FinalSymbol, MODE_ASK ), SymDigits );
double SymBid = NormalizeDouble( MarketInfo( FinalSymbol, MODE_BID ), SymDigits );

Ticket = OrderSend( FinalSymbol, OP_BUY, FinalLots, SymAsk, 0, StopLong(SymBid,StopLoss, SymPoints,SymDigits), TakeLong(SymAsk,ProfitTarget, SymPoints,SymDigits), EA_Comment, MagicNumber, 0, CLR_NONE );

int Err=GetLastError();

switch (Err)
{
//---- Success
case ERR_NO_ERROR: OrderLoop = true; break;

//---- Retry Error
case ERR_SERVER_BUSY:
case ERR_NO_CONNECTION:
case ERR_INVALID_PRICE:
case ERR_OFF_QUOTES:
case ERR_BROKER_BUSY:
case ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
case ERR_PRICE_CHANGED:
case ERR_REQUOTE: continue;

//---- Fatal known Error
case ERR_INVALID_STOPS: OrderLoop = true; Print( "Invalid Stops" ); break;
case ERR_INVALID_TRADE_VOLUME: OrderLoop = true; Print( "Invalid Lots" ); break;
case ERR_MARKET_CLOSED: OrderLoop = true; Print( "Market Close" ); break;
case ERR_TRADE_DISABLED: OrderLoop = true; Print( "Trades Disabled" ); break;
case ERR_NOT_ENOUGH_MONEY: OrderLoop = true; Print( "Not Enough Money" ); break;
case ERR_TRADE_TOO_MANY_ORDERS: OrderLoop = true; Print( "Too Many Orders" ); break;

//---- Fatal Unknown Error
case ERR_NO_RESULT:
default: OrderLoop = true; Print( "Unknown Error - " + Err ); break;
//----
}
// end switch
if( TryCount > 10) { OrderLoop = true; }
}
//----
return(Ticket);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Place Shrt Order |
//+------------------------------------------------------------------+
int EnterShrt( string FinalSymbol, double FinalLots, string EA_Comment )
{
int Ticket = -1; int err = 0; bool OrderLoop = False; int TryCount = 0;

while( !OrderLoop )
{
while( IsTradeContextBusy() ) { Sleep( 10 ); }

RefreshRates();
double SymAsk = NormalizeDouble( MarketInfo( FinalSymbol, MODE_ASK ), SymDigits );
double SymBid = NormalizeDouble( MarketInfo( FinalSymbol, MODE_BID ), SymDigits );

Ticket = OrderSend( FinalSymbol, OP_SELL, FinalLots, SymBid, 0, StopShrt(SymAsk,StopLoss, SymPoints,SymDigits), TakeShrt(SymBid,ProfitTarget, SymPoints,SymDigits), EA_Comment, MagicNumber, 0, CLR_NONE );

int Err=GetLastError();

switch (Err)
{
//---- Success
case ERR_NO_ERROR: OrderLoop = true; break;

//---- Retry Error
case ERR_SERVER_BUSY:
case ERR_NO_CONNECTION:
case ERR_INVALID_PRICE:
case ERR_OFF_QUOTES:
case ERR_BROKER_BUSY:
case ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
case ERR_PRICE_CHANGED:
case ERR_REQUOTE: continue;

//---- Fatal known Error
case ERR_INVALID_STOPS: OrderLoop = true; Print( "Invalid Stops" ); break;
case ERR_INVALID_TRADE_VOLUME: OrderLoop = true; Print( "Invalid Lots" ); break;
case ERR_MARKET_CLOSED: OrderLoop = true; Print( "Market Close" ); break;
case ERR_TRADE_DISABLED: OrderLoop = true; Print( "Trades Disabled" ); break;
case ERR_NOT_ENOUGH_MONEY: OrderLoop = true; Print( "Not Enough Money" ); break;
case ERR_TRADE_TOO_MANY_ORDERS: OrderLoop = true; Print( "Too Many Orders" ); break;

//---- Fatal Unknown Error
case ERR_NO_RESULT:
default: OrderLoop = true; Print( "Unknown Error - " + Err ); break;
//----
}
// end switch
if( TryCount > 10) { OrderLoop = true; }
}
//----
return(Ticket);
}
//+------------------------------------------------------------------+

 
arkdavisllc:


Hi Joao142,

Im new undere R8ed R. I have a EA MA cross but it only works on IBFX. Every other broker gives me a "invalid stop" in the expert field. Again i have not problems in IBFX. Could you help me with getting it to work on MBtrading?

#property copyright "Copyright - Interbank FX, LLC."
#property link "http://www.ibfx.com/"
#include "include\stderror.mqh"
//+------------------------------------------------------------------+
//| Global Variables / Includes |
//+------------------------------------------------------------------+
datetime CurrTime = 0;
datetime PrevTime = 0;
string Sym = "";
int TimeFrame = 0;
int Shift = 1;
int SymDigits = 5;
double SymPoints = 0.0001;

int MA1ArraySelected = 0;
int MA2ArraySelected = 0;
int MA1MethodSelected = 0;
int MA2MethodSelected = 0;
//+------------------------------------------------------------------+
//| Expert User Inputs |
//+------------------------------------------------------------------+
extern bool UseCompletedBars = true;

// Create any user input for the indicators you will use here
// For example:
extern string MA1Array = "Close";
extern string MA2Array = "Close";
extern int MA1Periods = 12;
extern int MA2Periods = 26;
extern string MA1Method = "Simple";
extern string MA2Method = "Simple";

extern double Lots = 0.01;
extern int MagicNumber = 1235;
extern int ProfitTarget = 100;
extern int StopLoss = 100;
extern int Slippage = 3;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
Sym = Symbol();
TimeFrame = Period();
SymPoints = MarketInfo( Sym, MODE_POINT );
SymDigits = MarketInfo( Sym, MODE_DIGITS );
//---
if( SymPoints == 0.001 ) { SymPoints = 0.01; SymDigits = 3; }
else if( SymPoints == 0.00001 ) { SymPoints = 0.0001; SymDigits = 5; }

//------------------ CLOSE -------------------------
if(MA1Array == "C") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "CLOSE") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "Close") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "c") {MA1ArraySelected = PRICE_CLOSE;}
else if(MA1Array == "close") {MA1ArraySelected = PRICE_CLOSE;}
//------------------ LOW -------------------------
else if(MA1Array == "L") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "LOW") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "Low") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "l") {MA1ArraySelected = PRICE_LOW;}
else if(MA1Array == "low") {MA1ArraySelected = PRICE_LOW;}
//------------------ HIGH -------------------------
else if(MA1Array == "H") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "HIGH") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "High") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "h") {MA1ArraySelected = PRICE_HIGH;}
else if(MA1Array == "high") {MA1ArraySelected = PRICE_HIGH;}
//------------------ OPEN-------------------------
else if(MA1Array == "O") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "OPEN") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "Open") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "o") {MA1ArraySelected = PRICE_OPEN;}
else if(MA1Array == "open") {MA1ArraySelected = PRICE_OPEN;}
//------------------ Typical -------------------------
else if(MA1Array == "TYPICAL") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "Typical") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "typical") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "T") {MA1ArraySelected = PRICE_TYPICAL;}
else if(MA1Array == "t") {MA1ArraySelected = PRICE_TYPICAL;}
//------------------ MEDIAN -------------------------------
else if(MA1Array == "MEDIAN") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "Median") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "median") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "M") {MA1ArraySelected = PRICE_MEDIAN;}
else if(MA1Array == "m") {MA1ArraySelected = PRICE_MEDIAN;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid array in open, high, Low, Close, Typical, Median" );
return(-1);
}

//------------------ CLOSE -------------------------
if(MA2Array == "C") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "CLOSE") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "Close") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "c") {MA2ArraySelected = PRICE_CLOSE;}
else if(MA2Array == "close") {MA2ArraySelected = PRICE_CLOSE;}
//------------------ LOW -------------------------
else if(MA2Array == "L") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "LOW") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "Low") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "l") {MA2ArraySelected = PRICE_LOW;}
else if(MA2Array == "low") {MA2ArraySelected = PRICE_LOW;}
//------------------ HIGH -------------------------
else if(MA2Array == "H") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "HIGH") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "High") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "h") {MA2ArraySelected = PRICE_HIGH;}
else if(MA2Array == "high") {MA2ArraySelected = PRICE_HIGH;}
//------------------ OPEN-------------------------
else if(MA2Array == "O") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "OPEN") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "Open") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "o") {MA2ArraySelected = PRICE_OPEN;}
else if(MA2Array == "open") {MA2ArraySelected = PRICE_OPEN;}
//------------------ Typical -------------------------
else if(MA2Array == "TYPICAL") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "Typical") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "typical") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "T") {MA2ArraySelected = PRICE_TYPICAL;}
else if(MA2Array == "t") {MA2ArraySelected = PRICE_TYPICAL;}
//------------------ MEDIAN -------------------------------
else if(MA2Array == "MEDIAN") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "Median") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "median") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "M") {MA2ArraySelected = PRICE_MEDIAN;}
else if(MA2Array == "m") {MA2ArraySelected = PRICE_MEDIAN;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid array in open, high, Low, Close, Typical, Median" );
return(-1);
}
//------------------ CLOSE -------------------------
if(MA1Method == "Simple") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "SIMPLE") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "S") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "s") {MA1MethodSelected = MODE_SMA; }
else if(MA1Method == "simple") {MA1MethodSelected = MODE_SMA; }
//------------------ LOW -------------------------
else if(MA1Method == "Exponential") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "EXPONENTIAL") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "E") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "e") { MA1MethodSelected = MODE_EMA;}
else if(MA1Method == "exponential") { MA1MethodSelected = MODE_EMA;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid Method: Simple or Exponential" );
return(-1);
}
//------------------ CLOSE -------------------------
if(MA2Method == "Simple") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "SIMPLE") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "S") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "s") {MA2MethodSelected = MODE_SMA; }
else if(MA2Method == "simple") {MA2MethodSelected = MODE_SMA; }
//------------------ LOW -------------------------
else if(MA2Method == "Exponential") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "EXPONENTIAL") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "E") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "e") { MA2MethodSelected = MODE_EMA;}
else if(MA2Method == "exponential") { MA2MethodSelected = MODE_EMA;}
//------------------ DEFAULT -------------------------------
else
{
Alert("Please select a valid Method: Simple or Exponential" );
return(-1);
}

//----
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() { return(0); }

//+------------------------------------------------------------------+
//| Expert start function |
//+------------------------------------------------------------------+
int start()
{
int RealTime = 0;
if( UseCompletedBars )
{
CurrTime = iTime(Sym, TimeFrame, 1 );
if( CurrTime == PrevTime )
{
return(0);
}
//---- Update Vars
PrevTime = CurrTime;
RealTime = 1;
}

//---- Need to chek for a new Signal?
if( CountAll( Sym, MagicNumber) == 0)
{
//---- Indicator 1 Values
double Indicator1CurrentValue = iMA(NULL,0,MA1Periods,0,MA1MethodSelected, MA1ArraySelected,0+RealTime);
double Indicator1PreviousValue = iMA(NULL,0,MA1Periods,0,MA1MethodSelected, MA1ArraySelected,1+RealTime);
//---- Indicator 2 Values
double Indicator2CurrentValue = iMA(NULL,0,MA2Periods,0,MA2MethodSelected, MA2ArraySelected,0+RealTime);
double Indicator2PreviousValue = iMA(NULL,0,MA2Periods,0,MA2MethodSelected, MA2ArraySelected,1+RealTime);

//---- Moving Average Cross System
if( Indicator1CurrentValue > Indicator2CurrentValue && Indicator1PreviousValue <= Indicator2PreviousValue ) { EnterLong(Sym, Lots, ""); }
else if( Indicator1CurrentValue < Indicator2CurrentValue && Indicator1PreviousValue >= Indicator2PreviousValue ) { EnterShrt(Sym, Lots, ""); }
}
//----

//----
return(0);
}

//+------------------------------------------------------------------+
//| Expert Custom Functions |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| CountAll() |
//+------------------------------------------------------------------+
int CountAll( string Symbole, int Magic )
{
//----
int count = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if ( OrderMagicNumber() != Magic ) continue;
if ( OrderSymbol() != Symbole ) continue;

if ( OrderType() == OP_BUY ) { count++; }
else if ( OrderType() == OP_SELL ) { count++; }
}
//----
return(count);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Stop Long |
//+------------------------------------------------------------------+
double StopLong(double price,double stop,double point,double SymDgts )
{
if(stop==0) { return(0); }
else { return(NormalizeDouble( price-(stop*point),SymDgts)); }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Stop Short |
//+------------------------------------------------------------------+
double StopShrt(double price,double stop,double point,double SymDgts )
{
if(stop==0) { return(0); }
else { return(NormalizeDouble( price+(stop*point),SymDgts)); }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Profit Target Long |
//+------------------------------------------------------------------+
double TakeLong(double price,double take,double point,double SymDgts )
{
if(take==0) { return(0);}
else { return(NormalizeDouble( price+(take*point),SymDgts));}
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Calculate Profit Target Long |
//+------------------------------------------------------------------+
double TakeShrt(double price,double take,double point,double SymDgts )
{
if(take==0) { return(0);}
else { return(NormalizeDouble( price-(take*point),SymDgts));}
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Place Long Order |
//+------------------------------------------------------------------+
int EnterLong( string FinalSymbol, double FinalLots, string EA_Comment )
{
int Ticket = -1; int err = 0; bool OrderLoop = False; int TryCount = 0;

while( !OrderLoop )
{
while( IsTradeContextBusy() ) { Sleep( 10 ); }

RefreshRates();
double SymAsk = NormalizeDouble( MarketInfo( FinalSymbol, MODE_ASK ), SymDigits );
double SymBid = NormalizeDouble( MarketInfo( FinalSymbol, MODE_BID ), SymDigits );

Ticket = OrderSend( FinalSymbol, OP_BUY, FinalLots, SymAsk, 0, StopLong(SymBid,StopLoss, SymPoints,SymDigits), TakeLong(SymAsk,ProfitTarget, SymPoints,SymDigits), EA_Comment, MagicNumber, 0, CLR_NONE );

int Err=GetLastError();

switch (Err)
{
//---- Success
case ERR_NO_ERROR: OrderLoop = true; break;

//---- Retry Error
case ERR_SERVER_BUSY:
case ERR_NO_CONNECTION:
case ERR_INVALID_PRICE:
case ERR_OFF_QUOTES:
case ERR_BROKER_BUSY:
case ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
case ERR_PRICE_CHANGED:
case ERR_REQUOTE: continue;

//---- Fatal known Error
case ERR_INVALID_STOPS: OrderLoop = true; Print( "Invalid Stops" ); break;
case ERR_INVALID_TRADE_VOLUME: OrderLoop = true; Print( "Invalid Lots" ); break;
case ERR_MARKET_CLOSED: OrderLoop = true; Print( "Market Close" ); break;
case ERR_TRADE_DISABLED: OrderLoop = true; Print( "Trades Disabled" ); break;
case ERR_NOT_ENOUGH_MONEY: OrderLoop = true; Print( "Not Enough Money" ); break;
case ERR_TRADE_TOO_MANY_ORDERS: OrderLoop = true; Print( "Too Many Orders" ); break;

//---- Fatal Unknown Error
case ERR_NO_RESULT:
default: OrderLoop = true; Print( "Unknown Error - " + Err ); break;
//----
}
// end switch
if( TryCount > 10) { OrderLoop = true; }
}
//----
return(Ticket);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Place Shrt Order |
//+------------------------------------------------------------------+
int EnterShrt( string FinalSymbol, double FinalLots, string EA_Comment )
{
int Ticket = -1; int err = 0; bool OrderLoop = False; int TryCount = 0;

while( !OrderLoop )
{
while( IsTradeContextBusy() ) { Sleep( 10 ); }

RefreshRates();
double SymAsk = NormalizeDouble( MarketInfo( FinalSymbol, MODE_ASK ), SymDigits );
double SymBid = NormalizeDouble( MarketInfo( FinalSymbol, MODE_BID ), SymDigits );

Ticket = OrderSend( FinalSymbol, OP_SELL, FinalLots, SymBid, 0, StopShrt(SymAsk,StopLoss, SymPoints,SymDigits), TakeShrt(SymBid,ProfitTarget, SymPoints,SymDigits), EA_Comment, MagicNumber, 0, CLR_NONE );

int Err=GetLastError();

switch (Err)
{
//---- Success
case ERR_NO_ERROR: OrderLoop = true; break;

//---- Retry Error
case ERR_SERVER_BUSY:
case ERR_NO_CONNECTION:
case ERR_INVALID_PRICE:
case ERR_OFF_QUOTES:
case ERR_BROKER_BUSY:
case ERR_TRADE_CONTEXT_BUSY: TryCount++; break;
case ERR_PRICE_CHANGED:
case ERR_REQUOTE: continue;

//---- Fatal known Error
case ERR_INVALID_STOPS: OrderLoop = true; Print( "Invalid Stops" ); break;
case ERR_INVALID_TRADE_VOLUME: OrderLoop = true; Print( "Invalid Lots" ); break;
case ERR_MARKET_CLOSED: OrderLoop = true; Print( "Market Close" ); break;
case ERR_TRADE_DISABLED: OrderLoop = true; Print( "Trades Disabled" ); break;
case ERR_NOT_ENOUGH_MONEY: OrderLoop = true; Print( "Not Enough Money" ); break;
case ERR_TRADE_TOO_MANY_ORDERS: OrderLoop = true; Print( "Too Many Orders" ); break;

//---- Fatal Unknown Error
case ERR_NO_RESULT:
default: OrderLoop = true; Print( "Unknown Error - " + Err ); break;
//----
}
// end switch
if( TryCount > 10) { OrderLoop = true; }
}
//----
return(Ticket);
}
//+------------------------------------------------------------------+



I apologize arkdavisllc but I m not an expert in programation and can t help you...I take the EA that I post but It don t sent orders automaticaly in MetaTrader from Fx pro or Broco trader and I don t understand why...

It just send orders il I put manual confirmation...Can Anybody help me?

 

  1. For large blocks of code, use the Attach file

  2. Do you have a smiley face in the top right corner of the chart?
Reason: