¿Alguien me ayuda a programar un EA?

Espacio para compartir y debatir sobre Asesores Expertos de MetaTrader

Re: ¿Alguien me ayuda a programar un EA?

Notapor sergioandreslq » 29 Oct 2008, 03:04

ninpojutsu, expone tu sistema con CCI y estocastico, como tu dices en otro foro lo exponen solo con esos dos indicadores y si le agregamos las emas creo que puede ser muy bueno,

Por favor indicamos como serian las reglas, lo que yo entiendo hasta el momento es:
Ejm para compra:
Si EMA46< precio, solo entramos en compra
Si ema 7 cruza hacia arriba ema 18 posible compra, ahi se entra a mirar si: CCI(40)>0 y stocastico lento(5,1,2)>50 entramos en posición de venta con un Stop loss de 100 pips, eso es para H4, este valor depende de TF.
la señal de salida se da cuando CCI(40)<0 o cuando stocastico lento (5,1,2)<50, que opinas de esto, si es lo que buscamos?.

Hoy el SL me saco con 800 en EUR/USD y con 2374 en GBP/JPY, por eso digo del trailing stop se va yendo con la tendencía.

ninpojutsu, que opinas de la estrategia, me parece bien.. ahora es que Casaseno nos colabore con esto.. quien quieta y le peguemos al gordo...

Casaseno, tu dices que la tienes automatizada con AVA, como te ha ido con ella si ha funcionado, si es así en que TF la utilizas?
Adjuntos
señal de salida.JPG
Esta fue la señal de salida con el trailing stop, me saco antes que me limitará la ganancia, en la GBP/JPY me saco en 150.00 y ya el precio esta en 156.64 siempre son 664 pips bien duros de conseguir. ahora a esperar otra señal en 4H ya que quede fuera del mercado.
sergioandreslq
 
Mensajes: 49
Registrado: 01 Jul 2008, 01:41
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor cacaseno » 29 Oct 2008, 10:22

Hola,
Yo tengo el programa hecho para AVA, pero es programable, o sea, que podemos elegir el valor de las Ema. Lo estoy usando con el petroleo en 5 min, EMA 10 y EMA 50, EMA 250 para la tendencia. A veces compro contra la tendencia, cuando el cruce coincide despues de tocar un soporte importante. Va bastante bien, pero hay que salir con TP porque a veces se da la vuelta y si esperas al cruce puedes llegar a perder en una operación que antes iba ganando 200 pip.
Ahora una cuestión. Programar el cruce las Ema es bastante sencillo. Estoy buscando la formulación matematica del estocastico y la del cci para programarlas yo, ya que he estado viendo el codigo en mq4 y no acabo de entender la formulación matematica de los mismos.
Usando el CCi no se si es necesario usar tambien la ema 46, te hace perder buenas operaciones, por lo que yo veo el cci se anticipa algo mas. No se, que opinais. De todos modos lo podemos programar de las dos formas, y luego lo probamos con el strategy tester, a ver cual va mejor.
Un saludo
cacaseno
 
Mensajes: 79
Registrado: 01 Sep 2008, 17:43
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor ninpojutsu » 29 Oct 2008, 10:38

sergioandres tal y como lo comentas es correcto, es buena idea hacerlo así,
venga cacaseno haber como se te da, y podemos crearlo así y lo probamos, rtrader me envio uno pero nosé si está echo de esta manera, lo probaré hoy haber q tal.
Avatar de Usuario
ninpojutsu
 
Mensajes: 302
Registrado: 27 Feb 2008, 20:34
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor rtrader » 29 Oct 2008, 12:39

ninpojutsu escribió:sergioandres tal y como lo comentas es correcto, es buena idea hacerlo así,
venga cacaseno haber como se te da, y podemos crearlo así y lo probamos, rtrader me envio uno pero nosé si está echo de esta manera, lo probaré hoy haber q tal.


El que te envié compra cuando el CCI 40 está sobre cero(0) y el Stoch 5;3;2 sobre 50, y vende a la inversa. No toma cruces sino los niveles, es decir que si detecta que ambas condiciones se cumplen , CCI40 > y Stoch 5;3;2 > 50, compra con stop de 100 pips y un trailing stop de 10 pips, y un take profit de 600 pips, que lo puse por ponerlo nada más.

Si cierra una posición ganadora por alcanzar el trailing stop y las condiciones para comprar se mantiene, vuelve a comprar y así.

Me gustaría hacer una observación, en este caso para el CCI, aunque es válida para la mayoría de los ondicadores, si se inserta en la gráfica una media de cualquier período y el CCI del mismo período que la media, se observará que cuando los precios cruzan a la media el CCI también cruza el nivel cero volviéndose positivo o negativo según el caso.

Saludos
Avatar de Usuario
rtrader
 
Mensajes: 279
Registrado: 12 Feb 2008, 14:02
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor cacaseno » 29 Oct 2008, 13:04

Hola Rtrader

¿me prodria enviar el codigo de lo que tienes programado? Asi adelantamos trabajo, yo tengo el esqueleto del cruce de las EMA, que lo cuelgo aqui, aunque aun le falta meterle la función de trailing, y un comprobador de operaciones que lo estoy preparando aun (para que cierre correctamente). Si me envias la parte del CCi y del Stoch, me ahorras bastante trabajo.
Un saludo

//+------------------------------------------------------------------+
//| ninsajart.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

extern double account = 15000;
extern double TakeProfit = 50;
extern double Stoploss = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double EMA1period=3;
extern double EMA2period=2;
extern double EMAtrendperiod=26;
extern double cciperiod=40;
extern double stochk=5;
extern double stochd=1;
extern double stochs=2;
double fase=0;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{double EMA1, EMA2, EMA3, CCi, Stoch;
double fase;
int cnt, ticket, total;
//comprobacion de estado de grafica y magnitud de valores
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0); // check TakeProfit
}
//Obtencion de datos de indicadores
EMA1=iMA(NULL,0,EMA1Period,0,MODE_EMA,PRICE_CLOSE,0);
EMA2=iMA(NULL,0,EMA2Period,0,MODE_EMA,PRICE_CLOSE,0);
EMA3=iMA(NULL,0,EMA3Period,0,MODE_EMA,PRICE_CLOSE,0);

if fase=0 {if EMA2>EMA3 { if EMA1>EMA2 {fase=0}}};
if fase=0 {if EMA2>EMA3 { if EMA1<EMA2 {fase=1}}};
if fase=0 {if EMA2<EMA3 { if EMA1>EMA2 {fase=2}}};
if fase=0 {if EMA2<EMA3 { if EMA1<EMA2 {fase=0}}};

if fase=1 {if EMA1>EMA2 {
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"ninsajart",account,0,Green);
fase=3}};
if fase=1 {if EMA2<EMA3 { if EMA1>EMA2 {fase=2}}};
if fase=1 {if EMA2<EMA3 { if EMA1<EMA2 {
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"ninsajart",account,0,Green);
fase=4}}};

if fase=2 {if EMA1<EMA2 {
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"ninsajart",account,0,Green);
fase=4}}}
if fase=2 {if EMA2>EMA3 { if EMA1<EMA2 {fase=1}}};
if fase=2 {if EMA2>EMA3 { if EMA1>EMA2 {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"ninsajart",account,0,Green);
fase=3}}}

if fase=3 {if EMA1<EMA2 {
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
if EMA2<EMA3 {
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"ninsajart",account,0,Green);
fase=4};
if EMA2>EMA3 {fase=1}}};

if fase=4 {if EMA1>EMA2 {
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
if EMA2>EMA3 {
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"ninsajart",account,0,Green);
fase=3};
if EMA2<EMA3 {fase=2}}};
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
cacaseno
 
Mensajes: 79
Registrado: 01 Sep 2008, 17:43
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor rtrader » 29 Oct 2008, 15:21

Hola cacaseno

Yo no sé programar, lo hice con el Builder http://sufx.core.t3-ism.net/ExpertAdvis ... l#CloseBuy

De todas maneras esto es:

Código: Seleccionar todo
//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 1.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 100;
extern bool UseTakeProfit = True;
extern int TakeProfit = 600;
extern bool UseTrailingStop = True;
extern int TrailingStop = 10;

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;

   if (EachTickMode) Current = 0; else Current = 1;

   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;



   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+


double Buy1_1 = iCCI(NULL, 0, 40, PRICE_TYPICAL, Current + 0);
double Buy1_2 = 0;
double Buy2_1 = iStochastic(NULL, 0, 5, 3, 2, MODE_EMA, 0, MODE_MAIN, Current + 0);
double Buy2_2 = 50;

double Sell1_1 = iCCI(NULL, 0, 40, PRICE_TYPICAL, Current + 0);
double Sell1_2 = 0;
double Sell2_1 = iStochastic(NULL, 0, 5, 3, 2, MODE_EMA, 0, MODE_MAIN, Current + 0);
double Sell2_2 = 50;



   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

           

            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+

           

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+

   if (Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;

   if (Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;


   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
            Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
         } else {
            Print("Error opening BUY order : ", GetLastError());
         }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
            Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
         } else {
            Print("Error opening SELL order : ", GetLastError());
         }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   if (!EachTickMode) BarCount = Bars;

   return(0);
}
//+-----------------------------------------------------------
Avatar de Usuario
rtrader
 
Mensajes: 279
Registrado: 12 Feb 2008, 14:02
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor rtrader » 29 Oct 2008, 15:22

//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder |
//| http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//| |
//| In no event will author be liable for any damages whatsoever. |
//| Use at your own risk. |
//| |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Expert Advisor Builder"
#property link "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = False;
extern double Lots = 1.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 100;
extern bool UseTakeProfit = True;
extern int TakeProfit = 600;
extern bool UseTrailingStop = True;
extern int TrailingStop = 10;

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init() {
BarCount = Bars;

if (EachTickMode) Current = 0; else Current = 1;

return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start() {
int Order = SIGNAL_NONE;
int Total, Ticket;
double StopLossLevel, TakeProfitLevel;



if (EachTickMode && Bars != BarCount) TickCheck = False;
Total = OrdersTotal();
Order = SIGNAL_NONE;

//+------------------------------------------------------------------+
//| Variable Begin |
//+------------------------------------------------------------------+


double Buy1_1 = iCCI(NULL, 0, 40, PRICE_TYPICAL, Current + 0);
double Buy1_2 = 0;
double Buy2_1 = iStochastic(NULL, 0, 5, 3, 2, MODE_EMA, 0, MODE_MAIN, Current + 0);
double Buy2_2 = 50;

double Sell1_1 = iCCI(NULL, 0, 40, PRICE_TYPICAL, Current + 0);
double Sell1_2 = 0;
double Sell2_1 = iStochastic(NULL, 0, 5, 3, 2, MODE_EMA, 0, MODE_MAIN, Current + 0);
double Sell2_2 = 50;




//+------------------------------------------------------------------+
//| Variable End |
//+------------------------------------------------------------------+

//Check position
bool IsTrade = False;

for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
//Close

//+------------------------------------------------------------------+
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
} else {
//Close

//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+

if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}

//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+

if (Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;

if (Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;


//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+

//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

if (!EachTickMode) BarCount = Bars;

return(0);
}
//+-----------------------------------------------------------
Avatar de Usuario
rtrader
 
Mensajes: 279
Registrado: 12 Feb 2008, 14:02
Karma: 0

Re: ¿Alguien me ayuda a programar un EA?

Notapor cacaseno » 29 Oct 2008, 16:17

Muchas gracias, creo que servirá, aunque usa una estructura diferente.
cacaseno
 
Mensajes: 79
Registrado: 01 Sep 2008, 17:43
Karma: 0

AnteriorSiguiente

Volver a Expert Advisors

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados