SymbolSelect() - page 2

 

I have already explained

String pair="EURUSD";
OrderSend(pair,OP_buy,....); 

 .

 
GumRai:

I have already explained

 .


Ok thanks
 
Mahmood000:
So here my ea should select eurusd symbol in order to run orderSend function on that pair

All symbols i need are already exist on market watch, i need to select a specified one to make an order on

As GumRai wrote, you don't "select" a pair before using OrderSend... There is no need to use SymbolSelect()

 

OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",12345,0); // Opens a Buy on the current chart symbol

  

 OrderSend("EURUSD",OP_BUY,1,Ask,3,0,0,"",12345,0); // Opens a Buy on EURUSD (irrespective of chart symbol)

 Or if you want to use a variable:

   string sym="EURUSD";
   OrderSend(sym,OP_BUY,1,Ask,3,0,0,"",12345,0);
 
honest_knave Or if you want to use a variable:
 OrderSend("EURUSD",OP_BUY,1,Ask,3,0,0,"",12345,0); // Opens a Buy on EURUSD (irrespective of chart symbol)
This fails when the chart is not EURUSD. If you are not trading the current chart's pair, you can not use any predefined Variables - MQL4 Documentation
 
honest_knave:

As GumRai wrote, you don't "select" a pair before using OrderSend... There is no need to use SymbolSelect()

 

  

 Or if you want to use a variable:

 

 


Thanks honest 
If i use this code

OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,...


It opens a trade with current symbol (which for me is usdchf by default) 

Seems i have to use 2nd and 3rd code in order to open a trade with a specified symbol not a default one


 
WHRoeder:
This fails when the chart is not EURUSD. If you are not trading the current chart's pair, you can not use any predefined Variables - MQL4 Documentation





Really?  Thats bad let me tell you about my ea
It doesn't work on charts, it read trade signals from a txt file and open them, in fact when I open meta trader there is no opened chart
Now do what do you recommend about how to opening a trade, how do i use orderSend, SymbolSelect...?
This is an example of trade signals which my EA reads
EURUSD  BUY stopLose: 1.1000   takeProfit: 1.1111
Now tell me how do i select symbol eurusd and use OrderSend  to open the trade
Or as honest said, i don't need to select it and all i need to do orderSend("eurusd",....
 
WHRoeder:
This fails when the chart is not EURUSD. If you are not trading the current chart's pair, you can not use any predefined Variables - MQL4 Documentation



Quite right WHRoeder, I was guilty of a quick reply without giving too much thought to the rest of the code.

string sym="EURUSD";
MqlTick tick;
SymbolInfoTick(sym,tick);
OrderSend(sym,OP_BUY,1,tick.ask,3,0,0); // Opens a Buy on EURUSD (irrespective of chart symbol)

 or

string sym="EURUSD";
OrderSend(sym,OP_BUY,1,SymbolInfoDouble(sym,SYMBOL_ASK),3,0,0); // Opens a Buy on EURUSD (irrespective of chart symbol)
 

Mahmood you need to use marketinfo() to get the price data for a pair differnent to the EA attached chart

https://docs.mql4.com/marketinformation/marketinfo

 
jasonxfield:

Mahmood you need to use marketinfo() to get the price data for a pair differnent to the EA attached chart

https://docs.mql4.com/marketinformation/marketinfo

Or SymbolInfoDouble()

Or SymbolInfoTick()

Many ways to skin the proverbial cat. Bear in mind that MarketInfo() is restricted to MQL4, whereas the other methods are also compatible with MQL5.

 
jasonxfield:

Mahmood you need to use marketinfo() to get the price data for a pair differnent to the EA attached chart

https://docs.mql4.com/marketinformation/marketinfo


It is getting difficult to me but I'm ok with reverse engineering ;-)
So give me a complete code which open a EURUSD trade but note that ALL CHARTS ARE CLOSED, other parameters could be anything you like..(stop loss, take profit,color etc)
Reason: