Open Buy Code issue.

 

Dear All,

I'm very new in here. I have read a few things about EA code and very interested to learn. I have background in C++, however there a lot of things new in here.

For the first time, i try to create my first code with the basic open buy order as below. But this code is not working. can anyone help me and can someone suggest me where i can learn the MT4 code

 

extern   double StopLoss = 400; // StopLoss

extern   double TakeProfit = 200; //Takeprofit

extern   double LotSize = 0.01;   //LotSize

extern   int Slippage = 2;

int start()

{

   //Opening SELL

   int ticket=OrderSend ("GBPUSD",OP_SELL,LotSize,Ask,Slippage,Ask+StopLoss*Point,Ask-TakeProfit*Point,NULL,0,0);

   return(ticket);

}
 
zaharulrizal:

Dear All,

I'm very new in here. I have read a few things about EA code and very interested to learn. I have background in C++, however there a lot of things new in here.

For the first time, i try to create my first code with the basic open buy order as below. But this code is not working. can anyone help me and can someone suggest me where i can learn the MT4 code

 

extern   double StopLoss = 400; // StopLoss

extern   double TakeProfit = 200; //Takeprofit

extern   double LotSize = 0.01;   //LotSize

extern   int Slippage = 2;

int start()

{

   //Opening SELL

   int ticket=OrderSend ("GBPUSD",OP_SELL,LotSize,Ask,Slippage,Ask+StopLoss*Point,Ask-TakeProfit*Point,NULL,0,0);

   return(ticket);

}

"GBPUSD"

 Ask

    return(ticket);

 

1) Sell order opens by Bid

2) You want to open gbpusd by price of current symbol. 2 variants:  Symbol() Bid   OR    "GBPUSD" MarketInfo("GBPUSD",MODE_BID)

3) return(0) must be

4) To get error write like this  

 int ticket=OrderSend (...);

if(ticket==-1) Alert(GetLastError()); 

 
Vasyl Nosal:

"GBPUSD"

 Ask

    return(ticket);

 

1) Sell order opens by Bid

2) You want to open gbpusd by price of current symbol. 2 variants:  Symbol() Bid   OR    "GBPUSD" MarketInfo("GBPUSD",MODE_BID)

3) return(0) must be

4) To get error write like this  

 int ticket=OrderSend (...);

if(ticket==-1) Alert(GetLastError()); 

Vasyl Nosal:

"GBPUSD"

 Ask

    return(ticket);

 

1) Sell order opens by Bid

2) You want to open gbpusd by price of current symbol. 2 variants:  Symbol() Bid   OR    "GBPUSD" MarketInfo("GBPUSD",MODE_BID)

3) return(0) must be

4) To get error write like this  

 int ticket=OrderSend (...);

if(ticket==-1) Alert(GetLastError()); 

Thanks for your concern,

Frankly, I dont understand how to put what you have told me, can you please rewrite my code so i can easily understand. 

 
zaharulrizal:

Thanks for your concern,

Frankly, I dont understand how to put what you have told me, can you please rewrite my code so i can easily understand. 

  int ticket=OrderSend (Symbol(),OP_SELL,LotSize,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,0,0);
if(ticket==-1) Alert(GetLastError());

return(0);

 

 
Vasyl Nosal:

Hello Sir,

Still not working.

 

 extern   double StopLoss = 400; // StopLoss

extern   double TakeProfit = 200; //Takeprofit

extern   double LotSize = 0.01;   //LotSize

extern   int Slippage = 2;


int start()

{

   //Opening SELL

   

   int ticket = OrderSend (Symbol(),OP_SELL,LotSize,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,0,0);

   if(ticket==-1) Alert(GetLastError());


   return(0);

}

 
Still not working.
What that means ? What is the error reported ?
 
zaharulrizal:

Hello Sir,

Still not working.

 

 extern   double StopLoss = 400; // StopLoss

extern   double TakeProfit = 200; //Takeprofit

extern   double LotSize = 0.01;   //LotSize

extern   int Slippage = 2;


int start()

{

   //Opening SELL

   

   int ticket = OrderSend (Symbol(),OP_SELL,LotSize,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,0,0);

   if(ticket==-1) Alert(GetLastError());


   return(0);

}

What Alert shows?
 
Comments that do not relate to this topic, have been moved to "Multiple orders issue".
 
Vasyl Nosal:
What Alert shows?

Thanks sir, its work now. The issue is my StopLoss and Takeprofit is to small for 5 digit. change the value and now my code is working.

Thanks for your help and guide. 

 
zaharulrizal:

Thanks sir, its work now. The issue is my StopLoss and Takeprofit is to small for 5 digit. change the value and now my code is working.

Thanks for your help and guide. 

To small? You trade with scamm broker?

Go to ecn/stp account. 

 
Vasyl Nosal:

To small? You trade with scamm broker?

Go to ecn/stp account. 

Owh sorry, its actually Lot size is to small changing from 0.01 to 0.1. I try it with MT4 only. No real forex account used. My concern is to learn how this code work with market. Still do some math work to built my own EA trading forex.

 

Another question is, how to control this order to make its only open one order in one time, after this order hit TP or SL then it open to another other. 

Reason: