MQL4 Learning - page 43

 

IF statements?

How do you do a simple program with IF statements in MQL4 such as

If price=level 2 then sell.

if price= level 3 then sell

If price= level 1 or level 4, close all trades

restrict trades to 1 per level

with levels set by an indicator or manually

Sorry if this is an impertinent question but it would be good to cut to the chase and avoid learning all the colours, variables, graphics etc etc- just to be able to try out some simple ideas

an example program for the above would be fantastic

thanks

 

(ASK) Two users are logged in with one account at the same time.

Hi all,

Is it possible, if two users are logged in with one account at the same time when open MT4 software?

Two users have different IP addresses.

Thank you.

 

I do not know what do you need it for, but here you go

 

how to automatically close unnecessary locked position?

Hi people!

I've been succesfully trading for the last several months using Ichimoku in conbination with ADX, plus some stochastic configurations to pick up tiny pullbacks.

My problem is that I hate stop losses, and always would rather lock a losing position than close it. Be it good or bad, but it would be nice to have a way to automatically close a locking position should the initial one make money.

Say, I buy EURUSD at 159, set Take Profit at 160, and I put a sell stop at 158.50.

Now, if the TP works, I want Metatrader to cancel the sell stop automatically.

Is such a thing possible?

Thanks a lot

 

How do I read a color change with this indicator??

I need your help! How do I read the color change in this indicator for my ea?? The buffers seem to only describe how to create the candle and wick. The condition to change the color is in the indicator (Highlighted with arrows - //<<<< - in the program coding), but no values seem to be connected to the buffers (I do not believe).

Can somebody modify this indicator so that a buffer or 2 buffers will indicate a value change that I can sense in my ea I am trying to create. Please help me if you can - Thanks!

Dave

Indicator attached! Very frustrating. I can create ea's, but indicators still puzzle me at times.

Files:
 

Stop opening 2 trades per bar

Hello,

Im creating an EA, but orders are opened multiple times per bar. For example if the CCI, in 4H bars, crosses the -100 line I buy. With a 10 pip profit I will close; however, after the close another open will occur in this same bar. How do I stop this?

A member wrote a while ago that Time[x]; x=0,1,2,3.. could be used. Unfortunately, I do not know how to implement this into my ea.

Any help would be greatly appreciated!

Thanks!

PS. Ive tried using this statement, but it does not seem to work.

if (OrdersHistoryTotal()>0 && TimeCurrent() - OrderCloseTime() < 4*3600) {WaitingTime=1;}

else {WaitingTime=0;}

I would use the "WaitingTime==0" in the buy parameters.

Also, a loop might be needed. The above statement is placed before the buy and close portions of the code. I think the OrderCloseTime() is just equaling 0 because the close portion of the code has not been stated before the buy portion. Sorry my programming skills are very weak. Thanks again!

 

Tester versus live trading

The EA I wrote runs well in the Tester and opens and closes transactions as required. However, when I use it on forward data by attaching it to a EURUSD graph and enable trading etc etc it never opens any trades. Anyone know what the reason is for that. Is there any function call necessary to switch on live trading?

By that I dont mean clicking the live trading box in the ea setup, I mean something you have to call in adition in your MT ea program.

Thanks

 

whateveryouwant: it's hard to discover the problem whithout the code. It could be 20 reasons.

 
whateveryouwant:
The EA I wrote runs well in the Tester and opens and closes transactions as required. However, when I use it on forward data by attaching it to a EURUSD graph and enable trading etc etc it never opens any trades. Anyone know what the reason is for that. Is there any function call necessary to switch on live trading?

By that I dont mean clicking the live trading box in the ea setup, I mean something you have to call in adition in your MT ea program.

Thanks

Do you enable live trading in the common tab? Do you have smiley face on the top right corner? Do you have error message in your "journal" or "experts" tab?

FerruFx

 

Tester versus live trading

Yes I havd live trading enabled and allows DLL calls etc as required for all EA's to trade live. That is why I stated that that section is set up correctly.

However my EA runs in the tester and is very good, but I must be missing some function call; that enables trading that has nothing to do with the EA setup from Metatrader interface.

Is there any Function call in the code preamble necessary to enable live trading?

It is really weird... it works in the tester but not in Live trading and yes I have a smiley face.

FerruFx:
Do you enable live trading in the common tab? Do you have smiley face on the top right corner? Do you have error message in your "journal" or "experts" tab? FerruFx
Reason: