SymbolName/Symbol. OrderSend

 

Hello everyone,

I'm experiencing problems with the my first part of the code isn't interacting with the second part. How could it be possible to change the String to a OrderSend?

// First Part
  string Pair;                       // New Symbol
  int New_Pair =11;                  // EUR/USD is the eleventh pair in Watch window
 Pair = SymbolName(New_Pair,true);   // string = symbol name

// Second Part
  double S=MarketInfo(Symbol(),MODE_STOPLEVEL); 
  double stoploss=NormalizeDouble(Bid-S*Point,Digits); 
  double takeprofit=NormalizeDouble(Bid+S*Point,Digits);
  int ticket=OrderSend(Symbol(),OP_BUY,Amount,Ask,3,stoploss,takeprofit,"EA Order",0,0,clrBlue); 
  if(ticket<1) 
  { 
   Print("Debug",GetLastError()); 
  } 
 else 
   Print("Order successfully"); 
  }   
 
GrumpyDuckMan:

Hello everyone,

I'm experiencing problems with the my first part of the code isn't interacting with the second part. How could it be possible to change the String to a OrderSend?


If you're placing an order on a symbol that is different from the chart's symbol, you can't use the pre-defined variables of Bid, Ask, Point or Digits, or the current symbol's stoplevel. You need to retrieve them using MarketInfo or SymbolInfoDouble.

e.g.

   string symbol = "EURUSD";
   double ask    = SymbolInfoDouble(symbol,SYMBOL_ASK),
          bid    = SymbolInfoDouble(symbol,SYMBOL_BID),
          pnt    = SymbolInfoDouble(symbol,SYMBOL_POINT);
   int    digits = (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS);

When you do the OrderSend():

   int ticket = OrderSend(symbol, OP_BUY, lots, ask,...

Also, although it is very unlikely to get a ticket number of 0, it is arguably possible. An OrderSend() failure would return -1:

//if(ticket<1) 
if(ticket<0) 
  { 
   Print("Debug",GetLastError()); 
  } 
 

My wishfully idea  to do something like this:

 input ENUM_NAME_SYMBOL NEW_SELECTION =MODE_TRADES;

NEW_SELECTION = MODE_TRADES;

Pair_1,

Pair_2,

Pair_3...

 
GrumpyDuckMan:

My wishfully idea  to do something like this:

NEW_SELECTION = MODE_TRADES;

Pair_1,

Pair_2,

Pair_3...


I'm sorry, I'm not 100% following.

MODE_TRADES is actually a term used for a pool in OrderSelect.  You'll probably want to choose another name.

Do you mean something like this?

Dropdown list in inputs:

enum symbols { EURUSD,USDJPY,AUDCAD };
input symbols symbol = EURUSD;


You'll need to convert that back to a string (enumerations aren't strings):

   string sym = EnumToString(symbol);
   // you'll also need to deal with broker suffix / prefix

Then you can place your orders:

   double ask    = SymbolInfoDouble(sym,SYMBOL_ASK),
          bid    = SymbolInfoDouble(sym,SYMBOL_BID),
          pnt    = SymbolInfoDouble(sym,SYMBOL_POINT);
   int    digits = (int)SymbolInfoInteger(sym,SYMBOL_DIGITS);
   int ticket = OrderSend(sym,OP_BUY,lots,ask,...


Or have I missed your point entirely?

 
honest_knave:


I'm sorry, I'm not 100% following.

MODE_TRADES is actually a term used for a pool in OrderSelect.  You'll probably want to choose another name.

Do you mean something like this?

Dropdown list in inputs:


You'll need to convert that back to a string (enumerations aren't strings):

Then you can place your orders:


Or have I missed your point entirely?

Thank you, honest_knave

That Enum has been doing my head in for weeks. 

 
GrumpyDuckMan: I'm experiencing problems with the my first part of the code isn't interacting with the second part. How could it be possible to change the String to a OrderSend?
  1. You can do this if you really want to but remember the admonition:
    honest_knave: If you're placing an order on a symbol that is different from the chart's symbol, you can't use the pre-defined variables of Bid, Ask, Point or Digits, or the current symbol's stoplevel. You need to retrieve them using MarketInfo or SymbolInfoDouble.
  2. This is why I recommend
    Do not trade multiple currencies in one EA
 

Hello again,

I am just experimenting  writing EA's at the moment. 

To whroeder1, I don't plan on trading any more than three different currencies on a single EA.

To  honest_knave, I don't know what you mean by "you'll also need to deal with broker suffix/prefix"

I have tried this code below.


void StartBuyOrders()
  { 
    string sym = EnumToString(symbol);
   // you'll also need to deal with broker suffix / prefix
   double ask    = SymbolInfoDouble(sym,SYMBOL_ASK),
          bid    = SymbolInfoDouble(sym,SYMBOL_BID),
          pnt    = SymbolInfoDouble(sym,SYMBOL_POINT);
   int    digits = (int)SymbolInfoInteger(sym,SYMBOL_DIGITS);

  int ticket=OrderSend(sym,OP_BUY,Amount,MODE_ASK,4,MODE_STOPLEVEL,MODE_SPREAD ,"EA Order",0,0,clrBlue); 
  if(ticket<1) 
  { 
   Print("Debug",GetLastError()); 
  } 
 else 
   Print("Order successfully"); 
  }  

The Terminal Log reads:

order buy 0.03 USDJPY opening at market sl: 14.000 tp: 13.000 failed [Market is closed]

 The SL and TP have me a bit confused atm.

 
GrumpyDuckMan:

To  honest_knave, I don't know what you mean by "you'll also need to deal with broker suffix/prefix"


Some brokers use a suffix on their symbols. For example, EURUSD might be EURUSDm or EURUSD-sb

In these situations, trying to open an order on "EURUSD" is going to fail. You would need to open the order using exact name of the symbol for that particular broker.

GrumpyDuckMan:

 The SL and TP have me a bit confused atm.


You have to set your TP and SL as a price, not a distance. So if you enter short at 1.10000 and you want a 10 pip SL you would need to set 1.10100 (not 10).

You also should remember that on most forex brokers these days, 10 pips = 100 points. MQL4 uses points not pips.

Take a look at the OrderSend documentation which gives an example that you can then modify.

GrumpyDuckMan:

The Terminal Log reads:

order buy 0.03 USDJPY opening at market sl: 14.000 tp: 13.000 failed [Market is closed]


You would need to use strategy tester over the weekend when the market is closed if you want to test your logic.
OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSend - Trade Functions - MQL4 Reference
 

Thank you, honest_knave 

I am still learning how to trade successfully using MQL4.

Does MQL5 use both pips & points?


 

 
honest_knave: Some brokers use a suffix on their symbols. For example, EURUSD might be EURUSDm or EURUSD-sb
  1. Not just suffix
    Broker's use a variety of naming patterns: EURUSD, EURUSDm, EURUSDi, "EURUSD.", "EURUSD..", "EUR.USD", "EUR/USD", "EURUSD.stp", EURUSDct, "EURUSD.G", "EURUSD+", EURUSDc, and EURUSDpro at least.
  2. Attached is a class to help with adornments.
Files:
adornment.mq4  4 kb
 
whroeder1:
  1. Not just suffix
  2. Attached is a class to help with adornments.

Thank you, whroeder1,

Just a bit advanced for me.

for the attached file. Would you be able to comment on the "class" ?

I'm not sure this is thread related...