MQL4 - automated forex trading   /  

Forum

Manage 5 pairs on 1 chart

Back to topics list To post a new topic, please log in or register

avatar
279
devilian1899 2008.02.26 14:07 
Hello,

I have a plan to manage 5 pairs on 1 chart. 1 order at a time. If some pairs give buy signal at the same time, it will choose pair with the lower spread to trade on.
I can make it with a large number of "if" for every possibility, but is there any better way to do this? I'm thinking to use an array, but I haven't use it before.
Any idea to help me?

Thank you.
article

Registration is Coming to Its End

So, it is the third time we open the registration, and it is coming to its end. In the behavior of potential Participants we managed to detect some regularities that repeat themselves from year to year.


avatar
1235
BarrowBoy 2008.02.26 14:27 

D

As ever, I admire your ambition!

You can indeed access any pair/s on any chart - the chart merely provides the ticks to drive your start() function

I quite like running an H4 EA on an H1 chart cos you get 4 easily controlled 'check points' per actual bar you are trading, but IMHO - 5 pairs means 5 EA's to me - by reasons:

  • Each will benefit from a different permutation of indicators &/or indicator settings
  • Effectiveness of debugging & testing
  • Less complex coding - in this plan, a single incorrect > or <, or a wrong && or || will be VERY difficult to spot
  • Efficiency in monitoring successes/failures in live trading
  • Its hard enough to get a long-term profitable EA going on one pair, let alone 5!

Does this correspond to a proven live trading system that you are coding up?

Generally, spread is not a big issue compared to position gain (or loss!), unless you have a mega-scalper - which will be built specifically for a low-ish spread pair anyway.

Also in general, a way to solve a difficult programming problem is to change the problem - to a larger number of simpler problems!


My 2c worth :)

-BB-


avatar
279
devilian1899 2008.02.26 15:09 
Hello BB,

Thanks for your respond and your insights. Honestly, it's a friend of mine who ask me to do it :)

Yes it's a scalping strategy, he says that it's a proven strategy and since he has to monitoring 5 pairs at the same time, he prefer to use an EA. For me, it will be a good knowledge. Well, that's it.

avatar
1235
BarrowBoy 2008.02.26 16:17 

D

Fair enough :)

Dont blame him for requesting an EA with 5 pairs to monitor!

For the both of you, you simply must read 'An Expert Advisor Made to Order. Manual for a Trader'

Made me sigh - and laugh til i cried :D

I've had 15 years experience of trying to get (complete or even... adequate) specifications from potential users of new proposed systems (in banking, health & telecomms).

I was once asked if I could program... 'maybe' & 'sometimes' :eek:


Seriously though, if your friend is an effective trader, his talents are not the same as a good programmer. He probably wont (consciously) know all he is doing...

It takes a lot of effort to bridge the gap between trader & programmer.

I see many great programmers working on here - not too sure how many of us are great traders - I know I'm not, I'm OK, but prefer to automate it, make a little less but no stress :)


Good Luck

-BB-


avatar
279
devilian1899 2008.02.26 18:32 
Thanks BB,
I guess he need to read that article :D

Personally I think I can do that, but with a lot of "if" statement, I thought we can do it better using array, well maybe.
Any idea everyone?

Thank you

avatar
279
devilian1899 2008.02.26 22:37 
Any other generous people? Phy? please?

Thanks

avatar
2462
phy 2008.02.26 23:38 

"I'm thinking to use an array, but I haven't use it before."


Arrays aren't difficult.

Take a time-out and play with them for a bit...

Write some litlle test scripts/indicators/experts to learn obout them.

---

... and you HAVE used them before... Close[i], High[i], etc, are arrays...


avatar
279
devilian1899 2008.02.27 04:50 
phy wrote:

"I'm thinking to use an array, but I haven't use it before."


Arrays aren't difficult.

Take a time-out and play with them for a bit...

Write some litlle test scripts/indicators/experts to learn obout them.

---

... and you HAVE used them before... Close[i], High[i], etc, are arrays...

I've been playing around with this code :

   double a=5;
   double b=6;
   double c=10;
   double d=4;
   double e=9;
   double ar[5];
   
   ar[1]=a;
   ar[2]=b;
   ar[3]=c;
   ar[4]=d;
   ar[5]=e;
   int max=ArrayMaximum(ar);
   Alert("Max = "+max+"  MaxValue = "+ar[max]+"");
a,b,c,d,and e will be dynamic variables, I make it constant in this example just for to make it simple.
The alert will be " Max = 3 MaxValue = 10", my question is how to make it to " Max = c MaxValue = 10"?

Thank you

avatar
2462
phy 2008.02.27 04:58 

Error

You are overwrting the end of the allocated storage:

double array[5] allocates memory for array[0] through array[4].

Writing into array[5] is illegal and may cause strange behavior in your tool,
but is not caught by the MT4 compiler.

You can overallocate without a problem, for instance:

double array[100] and only use a part of it, but not allocating enough space
leads to strange problems as other code or values get overwritten "by mistake"


avatar
279
devilian1899 2008.02.27 05:04 
phy wrote:

Error

You are overwrting the end of the allocated storage:

double array[5] allocates memory for array[0] through array[4].

Writing into array[5] is illegal and may cause strange behavior in your tool,
but is not caught by the MT4 compiler.


Thanks for that, I've change it and the alert is "Max = 2 MaxValue = 10" now. How to make it " Max = c MaxValue = 10".
I'll use a,b,c,d and e to choose a pair to trade.
I hope I don't asking anything obvious to make me looks stupid :)

Thank you

avatar
5
Bian_wu 2008.02.29 17:45 
You can try this:
   double a=5;
   double b=6;
   double c=10;
   double d=4;
   double e=9;
   double ar[5];
   string text [5]={"a","b","c","d","e"};

   ar[0]=a;
   ar[1]=b;
   ar[2]=c;
   ar[3]=d;
   ar[4]=e;
   int max=ArrayMaximum(ar);
   Alert("Max = "+text[max]+"  MaxValue = "+ar[max]+"");


Back to topics list  

To add comments, please log in or register