How do I code an EA to enter a trade at the open of a new candle?
Please forgive my ignorance, but I am new to the programming side of MQL4.
What I am trying to accomplish is enter one trade at the open of a new candle.
For example, if I had a 30min chart open, I would like to enter one trade at the open. Or if I had a 4hour chart open, how would I enter the trade at the open of that chart?
Also, I would like to enter only 1 trade at the open. I have tried a few commands and found it either entering the trade many times during the first minute, or not at all.
I have tried the "time current" function as well as "if minute = XXXX". The EA works when I backtest it, but when I try to put it on my live demo, it only works once in a while.
Any input would be greatly appreciated.
Thanks in advance.
Moved your post to this thread where you will find some links about how to code one trade oer candle etc.
besides there are some other threads:
How to paint "Close/High" in seperate window.
How to code the expiration for pending orders.
- MT4 Files Functions Replacement
- Create your own MetaTrader extension (dll) + video about how to do it.
- Net DLL wrapper
- dll tutorial for Visual Studio 2005
NO Trade 2 hours before or 1 hour after news EA.
hot keys in MetaTrader:
what time of the day, the broker forms new daily candles?
How to link together multiple EA’s in under 15 minutes!
Text objects on the chart coding.
objects: set time zero+- X distance
Best way to add MaxBarsToCount (History) to the limit
EA instant order requote problem: the thread with codes.
Mt4 and DDE: some programming issue.
- how to set EA's time in timefilter is on this post and this page.
- how to code timefilter in EAs (codes) is here.
- "Non-Trading Hours" on the screen fixing: example code; now it displays "Trading Hours" during trading hours and "Non-trading Hours" during non-trading hours. Thanks Locutus.
- how to code time filter: public thread.
Solution to computer restarts, keep those EAs running: some good suggestion about.
MM (money management) calculation, indicators, discussion, tools: calculate your lot size and so on. Original thread with several versions.
- Automatic Magic Function: small thread about how to do it.
- how to put magic number in EA: small elite section thread.
- magic number: small thread with explanation.
How to create your own code Wizard Templates.
Creating Custom symbol Set File.
Automatic Time Control.
SpeechText back to live!
Signal Transmitter/Receiver: tool to send/receive text messages between MT4 instances.
Create your own .wav alerts.
Thread about copy trades to one or many Metatraders from many brokers from demo or/and real and so on with many combination of EAs or manual testing.
Code to check the spread.
Hidden SL and TP
EA to only allow to work on Demo account and not Live account.
Difference between if(Close == Open) and if (iClose(NULL,0,1) == iOpen(NULL,0,1)).