Download MetaTrader 5

Make EA open a trade when indicator gives signal

To add comments, please log in or register
Chatel Hill
492
Chatel Hill  

Hello,

 I made a simple EA but to speed up optimization I want to make the EA open a new trade at the same time and at the same bar that the indicators are right and NOT when a new bar starts.

Could someone tell me the code to use? I can't find the info online.



Current Code:


//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
//+------------------------------------------------------------------+
//| Expert start function                                            |
//+------------------------------------------------------------------+
void OnTick(){
 
     LotsSize();Indicators();int num = Orders(-1);Closer();
//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 
    bool band = 0,ban = 0;
    for(int i = OrdersTotal() - 1; i >= 0; i--)
         if(OrderSelect (i, SELECT_BY_POS))
         {       
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
       {
       if(OrderOpenTime() >= iTime(NULL,0,0)) ban = true;  
       }}
       if(ban){return;}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx     
    for(int i=OrdersHistoryTotal()-1;i>=0;i--)
       {
       if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
       Print("Error in history!"); break;
       }
       if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
       {
       if(OrderOpenTime() >= iTime(NULL,0,0)) band = true;  
         }}
       if(band){return;}

whroeder1
17093
whroeder1  
Chatel Hill: I want to make the EA open a new trade at the same time and at the same bar that the indicators are right and NOT when a new bar starts.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. You haven't posted code that does anything. learn to code it, or pay (Freelance) someone to code it.
    We're not going to code it for you.
    We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
Keith Watford
Moderator
10533
Keith Watford  
    LotsSize();Indicators();int num = Orders(-1);Closer();


We don't know what these functions do but
If you want to optimise your code why are you calling them before you check for trades?

You do nothing with the values if there was a trade already opened in the current bar so call them after the checks.
Chatel Hill
492
Chatel Hill  
Using the ea on the h1 chart whenever the indicator gives a signal, the ea doesn't open the trade the same time as the indicator gives the signal does but instead it opens the trade 1 hour later.

That is a part of the code that I posted.

How can I make the ea open the trade at the same time that the indicator gives a signal?
Keith Watford
Moderator
10533
Keith Watford  
Chatel Hill:
Using the ea on the h1 chart whenever the indicator gives a signal, the ea doesn't open the trade the same time as the indicator gives the signal does but instead it opens the trade 1 hour later.

That is a part of the code that I posted.

How can I make the ea open the trade at the same time that the indicator gives a signal?
How would we know?

You show code that checks if there are orders opened during the current bar.

Show relevant code.
Alain Verleyen
Moderator
35118
Alain Verleyen  

Forum on trading, automated trading systems and testing trading strategies



Welcome,

  • Usually people who can't code don't receive free help on this forum, though it could happen if you are lucky, be patient.
  • If you show your attempts and describe well your problem, you will most probably receive an answer from the community.
  • If you don't want to learn to code, nothing bad, you can either look at the Codebase if something free already exists, or in the Market for paid products (sometimes free also).
  • Finally, you also have the option to hire a programmer in the Freelance section.

Good luck.


To add comments, please log in or register