Download MetaTrader 5

Problem with OrderSend for my first EA in mql4

To add comments, please log in or register
oekosimon
19
oekosimon  

Hi guys, 

I'm trying to make the OrderSend function work for my first EA, but for some reason it's not executed, 

can anyone tell me what I need to change?

Update:

I can see that it works on forex, but I need it to work in stock indexes through spreadbetting. 

For some reason it works in GBPUSD, but not GER30 - how do I change that?

extern double lots = 1.00;

extern int takeprofit = 40; 

extern int stoploss = 40;

extern int magic = 33545;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

  OrderSend (Symbol(), OP_SELL, lots, Bid, 3, Bid+stoploss*Point, Bid-takeprofit*Point, "Sell trade by expert", magic, NULL, clrBlue ); 

//---

   return(INIT_SUCCEEDED);

  }
Eleni Anna Branou
Moderator
5716
Eleni Anna Branou  

Please use the </< button to insert your code above.


oekosimon
19
oekosimon  
Eleni Anna Branou:

Please use the </< button to insert your code above.


thanks Eleni, that answered half of the questions. 

Do you know why the code doesn't work? 

Eleni Anna Branou
Moderator
5716
Eleni Anna Branou  
oekosimon:

thanks Eleni, that answered half of the questions. 

Do you know why the code doesn't work? 

Rudeness won't help you.

oekosimon
19
oekosimon  
Eleni Anna Branou:

Rudeness won't help you.

Sorry, it wasn't meant to be rude, I was actually greatful for your answer
Konstantin Nikitin
6202
Konstantin Nikitin  

Minimum. Need to check STOPS_LEVEL

int stopLevel = (int)SymbolInfoInteger( _Symbol, SYMBOL_TRADE_STOPS_LEVEL )+1;
int ticket = OrderSend( _Symbol, OP_SELL, lots, Bid, 3,
                        Bid+(stopLevel>stoploss ? stopLevel : stoploss)*Point,
                        Bid-(stopLevel>takeprofit ? stopLevel : takeprofit)*Point,
                        "Sell trade by expert",
                        magic, NULL, clrBlue );
It can be more. Specified by you.
oekosimon
19
oekosimon  
Konstantin Nikitin:

Minimum. Need to check STOPS_LEVEL

It can be more. Specified by you.
ok, I just learned that it works ok in Forex, but just not in stock indexes such as Ger30
whroeder1
17951
whroeder1  
OrderSend (Symbol(), OP_SELL, lots, Bid, 3, Bid+stoploss*Point, Bid-takeprofit*Point
  1. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  2. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is usually wrong.

oekosimon
19
oekosimon  
whroeder1:
  1. You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

thanks, you were rigth, the issue was with the lot size
To add comments, please log in or register