Ask! - page 99

 
Big Be:
WHEN do you want to use a STATIC variable - what problems can it solve?

WHEN do you want to put something in the INIT() section - what problems does it solve?

Big Be

So, an answer to this, is that instead of, or in addition to, the explanations in the MQ4 documentation?

 

How to keep track of multiple orders?

I'm currently making an EA that only has 1 open trade at a time.

I have alot of variables to keep track of what is happening during this trade.

If I had more open trades at the same time I thought I could use arrays for these variables with the ticket number as key. But as I understand it the keys has to be 0,1,2,3 etc right? So this wouldn't be possible.

Instead of that I could have a multidimension array like this, I hope you understand my javascript/php like description.

barsSinceOpen = array(

0 => array(0 => 123123, 1 => 63)

1 => array(0 => 552352, 1 => 5)

);

0 in second dimension would be ticket number, and 1 would be amount of bars since the trade was open.

barSinceOpen is just an example.. I know I could calculate this one out for each trade every time I want, but that's not the point. I have ALOT of things I keep track of for a trade.

And to select the correct order I would have to iterate over the array and select the 2nd level array with correct ticket.

Do you think this is a good idea? How would you do it?

 

Another question

It seems like when I do a orderModify() to set a take profit for example.

And then before next tick or we could aswell say before I select the same order again I do another orderModify() to set a stop loss. And in that I use OrderTakeProfit() so it doesn't remove the take profit. But, It removes the take profit anyway.

Do I need to wait for next tick or to select the order again for the OrderTakeProfit() to return my new take profit?

 
Big Be:
WHEN do you want to use a STATIC variable - what problems can it solve?

WHEN do you want to put something in the INIT() section - what problems does it solve?

Big Be
ralph.ronnquist:
So, an answer to this, is that instead of, or in addition to, the explanations in the MQ4 documentation?

That would be in addition.

(I always try to do my homework first.)

Maybe I need explanation and example(s).

Big Be

 
Big Be:
WHEN do you want to use a STATIC variable - what problems can it solve?

WHEN do you want to put something in the INIT() section - what problems does it solve?

Big Be

A static variable will remain the same with every function call that that variable is in, unless it's changed in the function of course. You may want an integer in that function only that you want to increase by 1 for example every function call.

But, you could aswell use global variables for this.

Example of init:

int init() {

TakeProfit=TakeProfit*Point;

StopLoss=StopLoss*Point;

TrailingStop=TrailingStop*Point;

breakEven=breakEven*Point;

return(0);

}

These are extern variables and you set takeprofit to 50 for example if you want 50 pips. But for this to work in the EA it must be multiplicated with the pip value of the currency 0.001 for example.

 
SimonF:
A static variable will remain the same with every function call that that variable is in, unless it's changed in the function of course. You may want an integer in that function only that you want to increase by 1 for example every function call.

But, you could aswell use global variables for this.

...

Simon-

Thanks. Please help make it clear:

Does this mean a static variable holds the last value assigned to it even though it is not global?

Regarding init(), it looks like it is used as a setup function.

- Can you tell me other good examples for it?

- Do you have to follow it with deinit()?

Big Be

 

Ask

codersguru:
Hi folks,

I've got a lot of private messages asking me for helping with some pieces of code.

Here you can post your questions related to MQL4, and I'll do my best to answer them.

Hello,

I want to learn mql directly from you i have read your tutorial and i have been coding couple of EA.

 

ma color based on closing

HI,

is there any ma indicator that color change according to the close of the candle.For example if the candle close above SMA then the line color is blue but if below MA then the color will change to red.

I know there is a indicator that has called "ma_in_color.mq4" sorry but i don't know how to post it, my question is, of there is anybody out there, who could program an sound alert in this indicator.

thx a lot

 

What is the easiest way to get the buffer values of an indicator to either display as a comment or print out in the experts folder so I can see the values change?? I have 8 buffers in this indicator.

Dave

 

ctrl-D .

Reason: