If I attach an EA to say EURUSD chart and then call 'OrderSymbol()' to verify whether it is on EURUSD chart or not like this:
if (Order_Symbol()==EURUSD) // ?
Is this Valid?
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
Is this Valid?
No, that is not quite valid.Arav » Sun Mar 09, 2014 3:42 pm wrote:If I attach an EA to say EURUSD chart and then call 'OrderSymbol()' to verify whether it is on EURUSD chart or not like this:
if (Order_Symbol()==EURUSD) // ?
1. It should be Symbol() not Order_Symbol(). Btw. There is a function OrderSymbol() (without the underscore) that returns the name of the symbol previously selected with OrderSelect() ). From the question, I assume that you are not after this one.
2. EURUSD should be between double quotes: "EURUSD".
3. You should be aware that some br0kers use suffixes for their symbols, such as "EURUSD.m". If that is the case, Symbol() would return "EURUSD.m" and the if-statement would return false. You might get away with
Code: Select all
if ( StringSubstr( Symbol(), 0, 6 ) == "EURUSD" ) {}
-
Arav
- Trader
- Posts: 15
- Joined: Tue Jan 21, 2014 2:06 pm
Is this Valid?
Thanks for the reply.
No, that is not quite valid.
1. It should be Symbol() not Order_Symbol(). Btw. There is a function OrderSymbol() (without the underscore) that returns the name of the symbol previously selected with OrderSelect() ). From the question, I assume that you are not after this one.
2. EURUSD should be between double quotes: "EURUSD".
3. You should be aware that some br0kers use suffixes for their symbols, such as "EURUSD.m". If that is the case, Symbol() would return "EURUSD.m" and the if-statement would return false. You might get away with
R.Code: Select all
if ( StringSubstr( Symbol(), 0, 6 ) == "EURUSD" ) {}
Actually I messed up the code.
It had to be
if (OrderSymbol()=="EURUSD")
My requirement is that:
After selecting an order, EA will verify that whether it is the Pair it is attached with.
Code: Select all
BuyOrder_1=OrderSend("EURUSD", iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1,NULL,Magic_Number_3, 0,Blue);
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic_Number_3)
{
if (OrderSymbol()=="EURUSD")
{
if (OrderType()==OP_BUY)
{
Order Modifying function;
}
}
}
}
Code: Select all
extern string Chart_Symbol=EURUSD; //Would I have to put this with "" i.e. "EURUSD" ?
BuyOrder_1=OrderSend(Chart_Symbol, iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1,NULL,Magic_Number_3, 0,Blue);Code: Select all
extern string Chart_Symbol="EURUSDpro"/"EURUSD.m"; // ???- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
Is this Valid?
If you want your EA to do something specific if it is attached to the "EURUSD" chart, you would do something like:
Code: Select all
extern string chart_symbol = "EURUSD";
if ( StringFind( Symbol(), chart_symbol, 0 ) == 0 ) {
// Do something special for chart_symbol
}
-
Arav
- Trader
- Posts: 15
- Joined: Tue Jan 21, 2014 2:06 pm
Is this Valid?
No the EA wont do anything Specific while attached with a specific pair.renexxxx » Sun Mar 09, 2014 5:56 pm wrote:If you want your EA to do something specific if it is attached to the "EURUSD" chart, you would do something like:
Code: Select all
extern string chart_symbol = "EURUSD"; if ( StringFind( Symbol(), chart_symbol, 0 ) == 0 ) { // Do something special for chart_symbol }
Rather it'll do the same thing for every pair.
So I want that there will be single function for Buy & Sell.
The Symbol will be different while it'll open trades for different pairs.
Also can I do it for all pairs just attaching it to Only One pair?
Regards
- renexxxx
- Trader
- Posts: 860
- Joined: Sat Dec 31, 2011 3:48 am
Is this Valid?
Yes, you can.Arav » Sun Mar 09, 2014 10:25 pm wrote: Also can I do it for all pairs just attaching it to Only One pair?
Regards