Download MetaTrader 5

how to edit Symbol()

To add comments, please log in or register
Brian
498
Brian 2016.04.29 12:36 

Hi,

I am editing an old EA that was coded for so I can try learn to code. 

I assume Symbol() in the code below means the EA will work with any symbol.

 

RefreshRates();               
         if (takeprofit != 0)          ticket_buy = OrderSend(Symbol(),OP_BUY,lotsize,Ask,slippage,Ask-atp*pp*Point,Ask+takeprofit*pp*Point,"buy",magic_number,0,Aqua);
         else                          ticket_buy = OrderSend(Symbol(),OP_BUY,lotsize,Ask,slippage,Ask-atp*pp*Point,0,"buy",magic_number,0,Aqua);
      }

I was wondering how to change this so that this EA will only run on a specific symbol or symbols? 

I'm assuming I need to create a symbol "input" where I could choose my symbol?

Could someone perhaps show me how this would be done?

This particular EA was coded BEFORE the big MT4 upgrade.

Appreciate any help.

Regards,

Marco vd Heijden
Moderator
4727
Marco vd Heijden 2016.04.29 13:26  
Symbol()

Always refers to the chart symbol.

If you want to use another symbol

Replace

Symbol()

with

SymbolName(X,1)

Where X is the symbol integer from Marketwatch position.

Also realize that you can not use Ask and Bid because these also relate to the chart Symbol so use

MarketInfo(SymbolName(X,1),MODE_ASK)
MarketInfo(SymbolName(X,1),MODE_BID)

Instead.

Daniela Bluemel
597
Daniela Bluemel 2016.04.29 13:27  
The EA runs on that chart you put it to. So when you put it only on EURUSD chart it only trades on that symbol.
Brian
498
Brian 2016.04.29 15:04  
Daniela Bluemel:
The EA runs on that chart you put it to. So when you put it only on EURUSD chart it only trades on that symbol.

Hi Daniela,

Thanks for your reply.

I actually want it not to run on any chart. I would like to restrict it to charts that I select.

 Thanks.

Regards,

Brian
498
Brian 2016.04.29 15:05  
Daniela Bluemel:
The EA runs on that chart you put it to. So when you put it only on EURUSD chart it only trades on that symbol.

Thanks Marco,

Will try that and let you know how I do:)

 

Cheers,

Brian 

Brian
498
Brian 2016.04.29 15:05  
Marco vd Heijden:

Always refers to the chart symbol.

If you want to use another symbol

Replace

with

Where X is the symbol integer from Marketwatch position.

Also realize that you can not use Ask and Bid because these also relate to the chart Symbol so use

Instead.

Thanks Marco,

Will try that and let you know how I do:)

 

Cheers,

Brian 

Brian
498
Brian 2016.04.29 15:09  
Marco vd Heijden:

Always refers to the chart symbol.

If you want to use another symbol

Replace

with

Where X is the symbol integer from Marketwatch position.

Also realize that you can not use Ask and Bid because these also relate to the chart Symbol so use

Instead.

Hi Marco,

Just to be clear, anywhere that Symbol() appears in the code will have to be changed in the way that you suggest or is there a way to do a single change that will apply to all instances of Symbol() in the EA

Thanks again. Excuse my rookie question.

Regards,

Marco vd Heijden
Moderator
4727
Marco vd Heijden 2016.04.29 17:15  
Press Ctrl+H
Osama Shaban
1463
Osama Shaban 2016.04.29 17:25  
input ...
input ...
input ...

string symb = "EURUSD"; //This will not shown in the EA external settings !

int start(){

   if(Symbol() != symb)
      return(0);

   ...
   ...
   ...

}

I believe the above code will to what you are looking for ...

Just be sure that symbol between " " is the same as used by your broker.

Brian
498
Brian 2016.05.01 05:53  
Osama Shaban:

I believe the above code will to what you are looking for ...

Just be sure that symbol between " " is the same as used by your broker.

Hi Osama,

Thanks for your reply.

So in my original example above it would loook like this:

RefreshRates();               
         if (takeprofit != 0)          ticket_buy = OrderSend(Symbol()!=symb,OP_BUY,lotsize,Ask,slippage,Ask-atp*pp*Point,Ask+takeprofit*pp*Point,"buy",magic_number,0,Aqua);
         else                          ticket_buy = OrderSend(Symbol()!=symb,OP_BUY,lotsize,Ask,slippage,Ask-atp*pp*Point,0,"buy",magic_number,0,Aqua);
      }

 I have done this everywhere in the code where Symbol() appears and then ran Strategy Tester. The EA should open the first order when it hits a trend line but it stops as soon as it hits the trend line.

I also used this as the input:

string symb = "EURUSD";

Can you perhaps see where I made a mistake?

Thanks. 

Regards,

Brian 

Daniela Bluemel
597
Daniela Bluemel 2016.05.01 08:57  
Maybe you should learn the basics before you want to write an EA...
12
To add comments, please log in or register