how put one order if have signal

 
//+------------------------------------------------------------------+
//|                                              phiiiiiiiiiiiii.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//--------------tham so dau vao
extern double MovingPeriod       = 100;
extern double MovingShift        = 0;
extern double MovingPeriod1       = 50;
extern double MovingShift1        = 0;
extern double Lots = 0.1;
extern double TakeProfit = 20;
extern double StopLoss = 30;
extern double TrailingStop = 50;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  double ma ;
   double ma1 ;
  int cnt, ticket, total;
//-------- get duong trung binh 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_EMA,PRICE_CLOSE,0);
   ma1=iMA(NULL,0,MovingPeriod1,MovingShift1,MODE_EMA,PRICE_CLOSE,0);
//+------------------------------------------------------------------+
//| dieu kien Sell                              
//+------------------------------------------------------------------+
   if ( ma1 < ma )
   { 
   ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Ask + StopLoss*Point, 
                               Bid - TakeProfit*Point, "adx sample", 16384, 0, Red);
    return(0); }
                               
   
   
  //+------------------------------------------------------------------+
//| dieu kien BUY                          
//+------------------------------------------------------------------+
 if ( ma1  > ma )
 {
 ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Bid - StopLoss*Point, 
                               Ask + TakeProfit*Point, "adx sample", 16384, 0, Green);
  return(0) ; 
  }


//----
   return(0);
  }
//+------------------------------------------------------------------+
 
phipho:

how put one order if have signal
How do you know when the signal has gone ?
 

phipho:

how put one order if have signal 


Do this :

On top of your code, add this 

#property link      "http://www.metaquotes.net"

#include <stdlib.mqh>

//--------------tham so dau vao
extern double MovingPeriod       = 100;

and on every OrderSend add this

ticket = OrderSend(Symbol(),

if (ticket < -1)
   {
   Print ("Order Send error : ",ErrorDescription(GetLastError()));
   }

Attach the EA on demo account and read the error print in expert tab.

 
phi.nuts:

and on every OrderSend add this

Attach the EA on demo account and read the error print in expert tab.

Or do this instead . . .

ticket = OrderSend(Symbol(),

if (ticket < 0)    // -1 is returned on error . . . < -1 will never happen 
   {
   Print ("Order Send error : ",ErrorDescription(GetLastError()));
   }
 
ok thank i will try :D
 
RaptorUK:

Or do this instead . . .

 

 


Oh dear, what was I thinking ?

You are right.

 
phi.nuts:


Oh dear, what was I thinking ?

You were trying to help,  nothing wrong with that :-)
 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_EMA,PRICE_CLOSE,0);
   ma1=iMA(NULL,0,MovingPeriod1,MovingShift1,MODE_EMA,PRICE_CLOSE,0);
//+------------------------------------------------------------------+
//| dieu kien Sell                              
//+------------------------------------------------------------------+
   if ( ma1 < ma ){ ticket = OrderSend...
This will open multiple orders per bar as the moving averages repeatedly cross as price moves.
 

have a problem. It say 'ErrorDescription' - function is not defined C:\MetaTrader 4 - Admiral Markets\experts\phiiiiiiiiiiiii.mq4 (57, 32)

when ai write that 

//+------------------------------------------------------------------+
//|                                              phiiiiiiiiiiiii.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//--------------tham so dau vao
extern double MovingPeriod       = 100;
extern double MovingShift        = 0;
extern double MovingPeriod1       = 50;
extern double MovingShift1        = 0;
extern double Lots = 0.1;
extern double TakeProfit = 20;
extern double StopLoss = 30;
extern double TrailingStop = 50;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  double ma ;
   double ma1 ;
  int cnt, ticket, total;
//-------- get duong trung binh 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_EMA,PRICE_CLOSE,0);
   ma1=iMA(NULL,0,MovingPeriod1,MovingShift1,MODE_EMA,PRICE_CLOSE,0);
//+------------------------------------------------------------------+
//| dieu kien Sell                              
//+------------------------------------------------------------------+
   if ( ma1 < ma )
   { 
   ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Ask + StopLoss*Point, 
                               Bid - TakeProfit*Point, "adx sample", 16384, 0, Red);
   if (ticket < 0)    // -1 is returned on error . . . < -1 will never happen 
   {
   Print ("Order Send error : ",ErrorDescription(GetLastError()));
   }
    return(0); }
                               
   
   
  //+------------------------------------------------------------------+
//| dieu kien BUY                          
//+------------------------------------------------------------------+
 if ( ma1  > ma )
 {
 ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Bid - StopLoss*Point, 
                               Ask + TakeProfit*Point, "adx sample", 16384, 0, Green);
                               if (ticket < 0)    // -1 is returned on error . . . < -1 will never happen 
   {
   Print ("Order Send error : ",ErrorDescription(GetLastError()));
   }
  return(0) ; 
  }


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

 


 
phipho:

have a problem. It say 'ErrorDescription' - function is not defined C:\MetaTrader 4 - Admiral Markets\experts\phiiiiiiiiiiiii.mq4 (57, 32)

when ai write that 

Well obviously you don't have the ErrorDescription( )  function defined . . . 
 
RaptorUK:
Rõ ràng là bạn không có ErrorDescription () chức năng xác định. . . 

Can you do for example about ErrorDescription ()  because i don't know how to write this 
Reason: