using expert id and magic numbers to run experts on two charts of same symbol and time frame

 

This is a challenge for me but maybe someone out there knows how to get around a couple of tricky scenarios.

If I want to run two different experts on two separate charts, both charts having the same symbol and time frames, how do I achieve this so that they do not interfere with each other?

Also can I write an EA that generates a buy or sell condition by recognizing a trade generated by an EA on a separate chart?

Hope this makes sense.

David

 
  • You have Magic#. Example: myMagic=0;
  • if( WindowExpertName( )=="myExpert1" ){ myMagic=1; }
  • if( WindowExpertName( )=="myExpert2" ){ myMagic=2; }

  • You have OrderComment(),
  • Example: myOComment=WindowExpertName().
  • OrderSend(..................................myOComment......);
  • for(blah...blah...blah){
  • if( OrderSelect() )
  • if( OrderComment()=="myExpert1" ){ do_something=1; }
  • if( OrderComment()=="myExpert2" ){ do_something=2; } 
  • ****Careful using comments as some Brokers overwrite them *Rare.
 
newton.dj: having the same symbol and time frames, how do I achieve this so that they do not interfere with each other?
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 forum
 

Thanks Guys.

This is helpful stuff for the first part of my problem. I knew that the answer was in magic numbers. Its interesting to see how you have applied them in your codes.

The second part of my problem was to obtain a buy/sell signal from an order placed by a separate EA attached to another chart. Another possible solution would be to have an EA create duplicate trades (say trade A and trade B) on the same chart and be able to differentiate between them. There would be 2 concurrent trades with separate close conditions applied to them. I believe that this would be much more difficult (and longer) to write code for than to link one EA to another, or at least to its trades. Just not sure how to achieve this.
 
newton.dj:

Thanks Guys.

This is helpful stuff for the first part of my problem. I knew that the answer was in magic numbers. Its interesting to see how you have applied them in your codes.

The second part of my problem was to obtain a buy/sell signal from an order placed by a separate EA attached to another chart. Another possible solution would be to have an EA create duplicate trades (say trade A and trade B) on the same chart and be able to differentiate between them. There would be 2 concurrent trades with separate close conditions applied to them. I believe that this would be much more difficult (and longer) to write code for than to link one EA to another, or at least to its trades. Just not sure how to achieve this.

My Opinion, just create a different Expert with a different Magic_Number. The Magic_Number is pretty much the mechanism provided by design to distinguish/label orders. Should Expert_B want to know whats happening in Expert_A, just check_for the Magic# of Expert_A.

Example: Expert_B does Nothing but wait. Expert_A places order based on Algorithm. Expert_B gets Tick, Searches to see if there's any OpenOrders with Expert_A's Magic#. Expert_B attempts placing order like A but with B's Magic# (Obviously there's some Synchronization issues && No_Guarantees on OpenPrice). B is responsible for Closing her own orders. A is responsible for Closing her own orders. They recognize their orders through [yep] Magic#.

For association, you have allot of different options to choose from. Examples: Magic_Numner_PreFix, OrderComments(), GlobalVariableSet(), File. All having advantages and dis-advantages. If you're still confused then perhaps you should practice allot of Simple Experts before attempting complex Experts.

 

Perfect! That's exactly what I wanted my EA to do. My code writing is not fantastic but I'm up for a challenge. What you've given me is enough to start from. Now I've just got to turn my ideas into an EA (or two EA's)

Thanks heaps.

I'm definitely not a computer geek. Never thought I would be doing this.

 
newton.dj: I'm definitely not a computer geek. Never thought I would be doing this.
Me neither. But I didn't want to give my trading ideas to someone else. Therefore, I was forced to learn programming through mql4. Been a nice experience tho :)
Reason: