Download MetaTrader 5

Open Buy Code issue.

To add comments, please log in or register
They are already making profit from their signals. Publish your signal and join them!
zaharulrizal
72
zaharulrizal 2016.02.17 09:52 

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);

}
Vasyl Nosal
18554
Vasyl Nosal 2016.02.17 10:22  
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()); 

zaharulrizal
72
zaharulrizal 2016.02.17 11:21  
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. 

Vasyl Nosal
18554
Vasyl Nosal 2016.02.17 11:51  
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);

 

zaharulrizal
72
zaharulrizal 2016.02.18 08:12  
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);

}

Alain Verleyen
Moderator
30746
Alain Verleyen 2016.02.18 08:18  
Still not working.
What that means ? What is the error reported ?
Vasyl Nosal
18554
Vasyl Nosal 2016.02.18 12:36  
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?
Alain Verleyen
Moderator
30746
Alain Verleyen 2016.02.18 21:47  
Comments that do not relate to this topic, have been moved to "Multiple orders issue".
zaharulrizal
72
zaharulrizal 2016.02.19 09:08  
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. 

Vasyl Nosal
18554
Vasyl Nosal 2016.02.19 09:18  
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. 

zaharulrizal
72
zaharulrizal 2016.02.19 09:54  
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. 

To add comments, please log in or register