Choosing one cross out of 72 realtime, based on an indicator value, and trade it: is it possible?

 

Hi,

My provider allows me to trade on 72 crosses.

I want to trade one of them only at the given time, based on the value of an indicator, using 1 minute bars (M1).

To give a better explanation, this is the flow:

1) A new bar does open (every minute)

2) When the bar open I have to calculate the value of the indicator (let’s call it MyInd) for all the 72 crosses.

3) I have to pick up the cross that have the maximum value for MyInd (only one cross… can be EURUSD or GBPJPY, ecc.). Let’s say EURUSD has the maximum value at the given bar.

4) If MyInd is gather than a threshold (MyInd >= 10) then enter a new trade on the chosen cross.

That’s all.

5) After a minute a new bar enters and everything repeat again: choosing the cross with the best MyInd and trade it if it is above the threshold.

And so on

Is it possible with MT4?

How would you code this? With a script? With an EA? Where would you compare the indicators value and choose the cross out?

Must I have 72 charts open concurrently? Is it affordable?

Thank you very much

Best regards

Stefano

 
spronti:

Hi,

1. Is it possible with MT4?

2. How would you code this? With a script? With an EA? Where would you compare the indicators value and choose the cross out?

3. Must I have 72 charts open concurrently? Is it affordable?

Thank you very much

Best regards

Stefano

1. Yes.

2. An EA for certain. Can't say much more without any information on the Indicator, for example does it use buffers ? or is it purely visual using Objects ?

3. No need to have all charts open, only the Instrument you have the EA placed on.

 

Thanks for your answer.

I understand you would need more information to properly answer, that’s my fault… the fact is that I have to migrate my C# code into MT4 and I don’t have clear the overall picture yet.
So, I will be back with this later next days when I will have the info you need.

For now, let me try to simplify the scenario a bit more… let’s forget about the indicators and let’s assume the following flow:

- assume that I’ve already chosen which is the cross to trade (from outside MT4, from my C# program) and that I’ve written the cross name and the price limits in a file.
- assume that, from within MT4, every minute when a new bar comes in, I have to open that file and read which is the cross to trade and prices (for example EURUSD, with SL, TP etc..)
- after reading the file, I want to enter a BUY order (or a SELL order) for the chosen cross.

1) Where do I put the code for reading the file? In a Script?
2) Once the cross has been read, where do I code the lines for entering the order on that cross, and how do I execute it?

One non elegant and non performing solution I can think of, is:
- Code an EA and from there read the file
- Open 72 charts and attach the EA to all of them
- if the cross red from the file coincide with the cross of the current chart, then enter the trade.

But this would mean concurrently open 72 charts with 72 EA instances running: is it affordable?
Also, 72 instances of the EA will read into the file at the same time (not good).
Do you see a more elegant any performing solution?

I think somehow the file should be read only once (per minute) and the content put in a global variable… and then the trade should be entered on the given cross without the need of having 72 EA instances running…
.. but I cannot think how to achieve this.

Thanks
Stefano

 

Well you're in luck because I've done something similar. Read my post here on page2. Check out this template.

The solution would be to perform the Algorithm which decides which symbol to trade first. Then make the Fx__Symbol / My_Symbol [symbol you'll be working with] the one with the highest value [or whatever]. Simple as that.

Just remember you cannot use stuff like Symbol() [My_Symbol Instead], or Ask [MarketInfo(My_Symbol,Mode_Ask) Instead]. Etc.

The Algorithm could be a C# dll. A Custom Indicator [Provided it has Buffers], [Or can distinguish a Symbol() parameter]. Certainly Object only indicators cannot do-this. Lastly, the way I prefer was to place the custom-indicator code within the Expert. I just rather work with one file.

Does anyone know how to make a link jump to a particular location upon another post?? I've seen examples like https://forum.mql4.com/51197#123456 <---How can I do this and make it jump to my post? Thank You.

 
ubzen:

Does anyone know how to make a link jump to a particular location upon another post?? I've seen examples like https://forum.mql4.com/51197#123456 <---How can I do this and make it jump to my post? Thank You.


I use Chrome and view the page source, you will find the bookmark to jump to there, I think there is an easier way if you use FriedFox.
 

Thank you very much ubzen!

Seems quite easy... I will try.

So, you put your code on an EA and this EA will first get the cross symbol from an external variable and then will use the OrderSend function using that cross symbol as input parameter:

OrderSend(MySymb_FromExtern, .., ..)

But, where do you attach your EA?

Does you just open a chart on whatever cross and attach the EA to it?

Thanks

Stefano

 
spronti: But, where do you attach your EA?

I attach the EA on EURUSD.

So, you put your code on an EA and this EA will first get the cross symbol from an external variable and then will use the OrderSend function using that cross symbol as input parameter:

Something like that. Here's one way you could do it.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
    string  My_Symbol=Symbol_HiMacd();
    //OrderSend(My_Symbol);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
string Symbol_HiMacd(){
    /*Fuction Returns The Symbol With Highest Macd Value*/
    string Symbol_Ray[72]={"EURUSD","USDJPY","GBPUSD",
    "USDCHF","AUDUSD","USDCAD"};//...All The Way to 72
    double Symbol_Macd[72];
    for(int i=ArraySize(Symbol_Macd)-1; i>=0; i--){
        //Symbol_Macd[i]=iMACD(Symbol_Ray[i])
    }
    i=ArrayMaximum(Symbol_Macd);
    return(Symbol_Ray[i]);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The function Symbol_HiMacd() could be a C# dll which returns a String. In the above example I choose Macd which is a built-in indicator. If the indicator I wanted was a custom indicator I could also just call it using iCustom instead of iMACD. But then again I would not use dll because I don't wanna bother with C nor would I use the iCustom because i don't wanna bother with storing custom indicator alongside Expert code.

Does you just open a chart on whatever cross and attach the EA to it?

Yeah, thats the idea.

 

There are Easier ways of providing Symbol Names to an Expert instead of Explicitly writing them out. Try using the search with something like All Symbols From My Broker. This should help solve problems if Broker calls EURUSD something like EURUSDxx [Or Whatever].

Also be Warned, mql4 Strategy Tester Does-Not support Multi-Currency Back-Testing. Only the Symbol the Tester is Attached to can place orders. Or use Marketinfo for that matter. Also Note you cannot access Bar[0] information for other Symbols. Only iOpen(0) {Upon M1 Resolution} will be accurate and rest would be in-accurate within the Back-tester.

So you could Test the Expert on EURUSD for example. But tell the program to Return if ( isTesting() && My_Symbol != Symbol() ){ Return; }. Therefore the program will only work with EURUSD within the tester when EURUSD is the Highest Symbol. You can use this technique and merge results from different Symbols as a form of multi-currency back-testing.

However be warned any such logic such as: if ( EurUsd_Profit>GbpUsd_Profit ){ Do_This(); } Will Just Fail. So to summarize, you can look at other symbols prices [anything Left_orEqual iOpen(OtherSymbol,Period_M1,0)] within the back-tester, you can make the test symbol do-something based upon what's happening to those prices. But you cannot make one symbol do-something based on whats happening to another symbol's Orders [withing the Strategy Tester]. Everything else should work Live.

 
RaptorUK:

I use Chrome and view the page source, you will find the bookmark to jump to there, I think there is an easier way if you use FriedFox.
Thank You. You're Awesome!!
 
spronti: 1) Where do I put the code for reading the file? In a Script?
2) Once the cross has been read, where do I code the lines for entering the order on that cross, and how do I execute it?

1) I would just use an Ea. A Script is something I'd use if needed 2-Ea where one of them acted like a Clock. Then I'd use a Script in Endless Loop to provide Time Sensitive Info instead of the usual Tick-Driven Info.

If you already have the Symbol's name you want-to use within a file then that makes matters even easier. Just assign My_Symbol to the String read from file. Use mql4 file functions, you can check the document and get familiar with them there.

2) We already cover this. Just use the My_Symbol variable [or whatever u wanna call it]. When you think Symbol() put that one in there instead.

*I know there's allot of information in here. . . So Good-Speed.

 

You have been very clear and helpfull... I will now take my time to code and test my strategies with your suggestion.

Thank you very much.

Best regards

Stefano

Reason: