MT4 Saving multiple events

 
Starting to get a bit more in depth with MQL4 and need some help.

Lets say (for example) the price hits 1.5000 3 times in one day. I would like to buy it on the third time.
Is there any way MT4 can record how many times an event has happened?


I guess my problem is that i want to open an order after certain events have happened. i.e. at 1pm price hit 1.5000 then at 3pm a macd crossed then at 5pm a moving average hit a level.

I cant use if statements because these events are not happening at the same time.


Thanks to anyone who can solve this.
 

if you save last 200 ticks then look how often a tick happend 3 or more times

So what do you mean price hits 1.5000 3 times in one day ....

 

I guess my problem is that i want to open an order after certain events have happened. i.e. at 1pm price hit 1.5000 then at 3pm a macd crossed then at 5pm a moving average hit a level.

I cant use if statements because these events are not happening at the same time.
 
tokyonine:

I guess my problem is that i want to open an order after certain events have happened. i.e. at 1pm price hit 1.5000 then at 3pm a macd crossed then at 5pm a moving average hit a level.

I cant use if statements because these events are not happening at the same time.
You said that already . . .
 
RaptorUK:
You said that already . . .

Yeah.
 
Devries commented on the first part of my question. Can anyone help on the second part of my question?
 
tokyonine:
Devries commented on the first part of my question. Can anyone help on the second part of my question?
If you want live events, not just that a bar has hit a certain level then you have to remember these as you go and store that fact in a a variable. When the variables tell you that all the events you need have been met then do what you want to do . . . place a trade or whatever it is you want.
 

You'll need to use static or global scoped variables to store counts etc. Here is a rough simplified template that I tend to use. This allows me to slot in extra steps to the strategy or remove them without too much pain...

#define STATE_BEGIN 0
#define STATE_WAIT_PRICE 1
#define STATE_WAIT_MACD_CROSS 2
#define STATE_WAIT_MA_HIT_LEVEL 3
#define STATE_ENTER_MARKET 4
#define STATE_NO_MORE_TRADES_TODAY 5

start()
{
        static int state;
        
        if (day_changed) state=STATE_WAIT_PRICE;

        switch(state) {
                case STATE_WAIT_PRICE:

                        code/fn to analyse tick/market for price

                        if (condition met) {
                                state = STATE_WAIT_MACD_CROSS;
                        }
                        // Fall through to save waiting for next tick
                        if (state != STATE_WAIT_MACD_CROSS ) break;

                case STATE_WAIT_MACD_CROSS:

                        code/fn to analyse tick/market for macd

                        if (condition met) {
                                state = STATE_WAIT_MA_HIT_LEVEL;
                        }
                        // Fall through to save waiting for next tick
                        if (state != STATE_WAIT_MA_HIT_LEVEL ) break;

                case STATE_WAIT_MA_HIT_LEVEL:

                        code/fn to analyse tick/market for MA hitting level

                        if (condition met) {
                                state = STATE_ENTER_MARKET;
                        }
                        // Fall through to save waiting for next tick
                        if (state != STATE_ENTER_MARKET ) break;

                case STATE_ENTER_MARKET:
                        buy, sell etc.
                        state = STATE_WAIT_PRICE;
                        or
                        state = STATE_NO_MORE_TRADES_TODAY;
                        break;

                case STATE_NO_MORE_TRADES_TODAY:
                        break;
        }
}
 
Ah ok. Cheers raptor. I'll start looking at variables. I wasn't sure what I was looking for before hand. Thanks for your help folks. No doubt ill be back to annoy you all at some point. :)
 
ydrol:

You'll need to use static or global scoped variables to store counts etc. Here is a rough simplified template that I tend to use. This allows me to slot in extra steps to the strategy or remove them without too much pain...

Cheers for that. I'll have a look at this.
Reason: