MQL4 Learning - page 75

 
luxinterior:
I'm not too clear on your question but if you're trying to phsyically change an external variable so that it will show up in your paramenters as changed then you can't do that. However if you change the value of an external variable from within your EA it stays changed until you recall the init function by either changing time frames, re-entering your external variables by looking them and pusing SAVE etc.

Not sure what you want to achieve but maybe take a look at global variables or consider writing values to a file.

Good luck

Lux

you got it right lux, sorry for not so clear... im not programmer and just learning to code this

Yes i'm trying to write the Extern variable

thank you for the save idea i like it... i'll try to make the EA save then load it nice.

 

previous indicator data

hi all just learning to write an ea and am using 2 moving averages my second moving average on my chart will aloow me to apply price from previous indicator data but i cant find a way to do this in the code. any help here would be greatly appreciated.

 

MA Levels put into EA code?

I can set MA Levels on my charts in the dialog box settings,

so how do I put the MA Levels into an EA line of code?

 

help: back testing unexpected behaviour

I'm trying to write a very simple EA to execute one sell order at 09:00 hrs each day. When I backtest, it seems to execute multiple orders each day at 09:00hrs, between 1-7 orders per day. I was anticipating 1 order per day of the backtest data. I am testing against H1 data. Any help would be much appreciated:

extern double StopLossPips=100.0;

extern double TakeProfitPips=100.0;

extern double Lots=0.1;

int ticket;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

if (TimeHour(TimeCurrent()) == 09 && TimeMinute(TimeCurrent()) == 00)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLossPips,Bid-TakeProfitPips*Point,"My EA",12345,0,Red);

}

//----

return(0);

}

//+------------------------------------------------------------------+

example output - why isn't it just one order for 2009.07.08?

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #87 sell 0.10 EURUSD at 1.3936 sl: 101.3936 tp: 1.3836 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #86 sell 0.10 EURUSD at 1.3934 sl: 101.3934 tp: 1.3834 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #85 sell 0.10 EURUSD at 1.3935 sl: 101.3935 tp: 1.3835 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #84 sell 0.10 EURUSD at 1.3934 sl: 101.3934 tp: 1.3834 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #83 sell 0.10 EURUSD at 1.3935 sl: 101.3935 tp: 1.3835 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #82 sell 0.10 EURUSD at 1.3936 sl: 101.3936 tp: 1.3836 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #81 sell 0.10 EURUSD at 1.3935 sl: 101.3935 tp: 1.3835 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #80 sell 0.10 EURUSD at 1.3936 sl: 101.3936 tp: 1.3836 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #79 sell 0.10 EURUSD at 1.3935 sl: 101.3935 tp: 1.3835 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #78 sell 0.10 EURUSD at 1.3936 sl: 101.3936 tp: 1.3836 ok

2009.07.08 11:23:28 2009.07.07 09:00 aa_dev_eurchf_1400 EURUSD,H1: open #77 sell 0.10 EURUSD at 1.3935 sl: 101.3935 tp: 1.3835 ok

 

You need to count the number of total orders for the current symbol that have the same magic number as the EA and if it's more than one don't open any more. Take a look in some EA's you already have and you'll find numerous examples of counting orders.

Good luck

Lux

 

open/close position on EMA's

Hi everyone

I'm newbie and I have another question about EA, i learned all lesson from codersguru and change a code a little bit for not using Trailing Stop, just open / close position when short EMA crosses long EMA, and I have one problem because the EA does not reverse the position. How to make code which would at the same time close Buy and open Sell ? ?

Modified code in attachment

Thanks in advance for help !

Files:
 
Smith23:
Hi everyone

I'm newbie and I have another question about EA, i learned all lesson from codersguru and change a code a little bit for not using Trailing Stop, just open / close position when short EMA crosses long EMA, and I have one problem because the EA does not reverse the position. How to make code which would at the same time close Buy and open Sell ? ?

Modified code in attachment

Thanks in advance for help !

Read these articles very helpful.

MQL4 Language for Newbies. Introduction - MQL4 Articles

MQL4 Language for Newbies. Difficult Questions in Simple Phrases. - MQL4 Articles

& follow the link there are 3-4 more grate articles

 

MQL4 Programming Help

Hey Guys,

Been lurking here now for a while, really nice forum you've put together.

I was wondering if anyone can point me to someplace ie: a forum, website etc., or to someone who can help me with some small programming issues?

I've submitted my question on several forums and even the mql4.com website but I can't seem to find any programmers that are willing to help anyone.

If someone could point me in the right direction, or if anyone is willing to answer a couple programming questions please PM me.

Thanks a bunch.

TS

 

Building on the previous post

Yes, I too would like to either (a) learn how to write indicators/EA's in MT4 or (b) tell someone what I need and get them written. The main issue is that I tend to use about 6 major indicators over the main currencies. It would be helpful if instead of sounds, I could get a visual alert telling me the pair and necessary action, better would be switching to the chart concerned. Most mistakes are made because you either miss the activator or you forget the entry procedure. Any help welcome

 

You have this section (current) and this section Metatrader Programming - Forex Trading. For both, make questions and to learn

Reason: