How to code? - page 131

 

EA variable values lost when closing MT4

Hello All,

I have searched and tried a number of solutions to my question, but can't find any that work.

I am programming an EA and the trades are handled by their ticket numbers. Ticket numbers are stored in an int variable. This runs fine in Strategy Tester or on a continuous uninterrupted MT4, however if you close MT4, ofcourse the tickets are lost and when MT4 reloads, the ticket numbers have been lost, hence the EA doesn't know which trades are currently open and starts to open new ones. Even if the pending or open orders are already trading.

I hope this makes sense.

I have tried static variables and I do know about global variables, but I would prefer not to use them, as each ticket number and variable wants to be individual to the chart TF and Symbol the EA is running on.

Does anyone have a simple solution. I do know that you could probably export the ticket numbers to a file that the EA can then open and read, but this seems a long way around. A not so neat way I am currently testing is on program start to use the SELECT_BY_POS function, looking for each trade with a Magic number the same, but this doesn't allow the full functionality of the EA I as I sometimes run 2 buys at the same time and identifiying which is which is hard.

Thanks for any replies.

 
mach_one_man:
Hello All,

I have searched and tried a number of solutions to my question, but can't find any that work.

I am programming an EA and the trades are handled by their ticket numbers. Ticket numbers are stored in an int variable. This runs fine in Strategy Tester or on a continuous uninterrupted MT4, however if you close MT4, ofcourse the tickets are lost and when MT4 reloads, the ticket numbers have been lost, hence the EA doesn't know which trades are currently open and starts to open new ones. Even if the pending or open orders are already trading.

I hope this makes sense.

I have tried static variables and I do know about global variables, but I would prefer not to use them, as each ticket number and variable wants to be individual to the chart TF and Symbol the EA is running on.

Does anyone have a simple solution. I do know that you could probably export the ticket numbers to a file that the EA can then open and read, but this seems a long way around. A not so neat way I am currently testing is on program start to use the SELECT_BY_POS function, looking for each trade with a Magic number the same, but this doesn't allow the full functionality of the EA I as I sometimes run 2 buys at the same time and identifiying which is which is hard.

Thanks for any replies.

Instead of ticket numbers, try keeping track of your orders using magic numbers. This is the best way that I have found.

 
FerruFx:
Modify like this:

if(Show_Settings) subPrintDetails(); else Comment("");

FerruFx

Thanks a bunch!! I will test it Sunday evening. I really appreciate your assistance! Have a nice weekend!

Dave

 

EA modification

Hello

Would very much appreciate if someone could help me out. There is this EA I got from another FX forum. It looks great but would appreciate if someone can help make some modifications on it.

I have tried the little I think I know but it keeps giving me errors of unbalanced brackets e.t.c

The EA opens 5lots and takes profit of 1 lot each at a specified incremental value (say 50 points/pips). So it closes 1 lot each time the profit increases by a specified number and finally allows the fifth/last lot to run till there is an opposite signal.

Modifications:

I want it to open only 3 lots,

Close 1 lot each as profit increases at a specified no. of pips

After the first two Take profit points have been reached, a trailing Stop should be used for the third.

Illustration:

3 lots

Incremental TP point= 40 pips

1st lot TP = 40, stoploss moved to BE

2nd lot TP= 80

3rd lot = Trailing stop activated

Every other thing is already in the EA, but I just need to change the lot size and add a trailing stop.

Thanks

Files:
stoch_ac.txt  7 kb
 
Dave137:
Thanks a bunch!! I will test it Sunday evening. I really appreciate your assistance! Have a nice weekend! Dave

You're welcome Dave. Enjoy your sunday!

FerruFx

 

drawing a line and draw a up/down arrow on a candle

Im tring to program a very simple indicator to draw a line and draw a up/down arrow on a candle.

I cant figure out how to use those style, index, draw etc.

I have a very simple if statement inside Start(), so what else do I need to add before Start(), and within Start()'s if, to draw a line, and up arrow, and down arrow?

Thanks.

 
MoreYummy:
Im tring to program a very simple indicator to draw a line and draw a up/down arrow on a candle.

I cant figure out how to use those style, index, draw etc.

I have a very simple if statement inside Start(), so what else do I need to add before Start(), and within Start()'s if, to draw a line, and up arrow, and down arrow?

Thanks.

Before trying to draw with some conditions in the Start() function, you have to set/initialyze the buffers[].

Code an indicator isn't a simple job. You may have to learn some basics of mql coding.

Wish you all the best in your learning process.

FerruFx

 

help

Hello Fellow Programmers,

I have an EA that trades on EURUSD when I attach it to the EURUSD chart. Question is how can I trade multiple pairs without having to attach my EA to multiple charts?

Something like this?

string pairs = "GBPUSD;EURUSD;USDCHF;USDJPY;USDCAD;GBPJPY;EURJPY;GBPCHF;EURAUD;EURCHF;EURGBP;AUDUSD;CHFJPY";

Thanks in advance,

LF

 

Have your code to trade specific pair when you send your order, it is very simple, right in the documentation.

 

Use an array instead of a string then loop through the array placing an order for each pair on each iteration. If you haven't used arrays before just look it up in the help file. They're pretty straight forward.

Good luck

Lux

Reason: