Question

I've got an indicator that signals an action by sound and alert:

PlaySound("news.wav");
Alert(Symbol()," make an action"); 

I wanted to add there the OrderSend function to auto buy-sell and it looks this way:

int ticket;        
PlaySound("news.wav");
Alert(Symbol()," make an action"); 
ticket=OrderSend(Symbol(),OP_SELL,1.0,Bid,2,Bid+7*Point,Bid-7*Point,"Sell",0,0, Red); 

When the time comes, there is the signal, there is the alert but there are no orders.

It is said that Trading functions can be used in experts and scripts in documentation: Trading Functions but it has to be done in some way.

How can it be done?

Was it helpful?

Solution 2

You can't trade in an indicator. There is a quick dirty way to do this. You can set a GlobalVariable from the indicator and then have a separate EA that constantly monitors the global. When the global variable is set the EA can make the trade and then reset the variable value.

Use GlobalVariableSet() in the indicator and GlobalVariableGet() in the EA.

OTHER TIPS

You don't have permission to do trading in custom indicators, read below article.

http://docs.mql4.com/runtime/tradepermission

I think the easy way is to convert your custom indicator into an Expert Adviser. It won't take much time if you have the experience in MQL4 coding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top