Download MetaTrader 5

My EA open trade where condition set is not met

To add comments, please log in or register
Newbie
9
Newbie  

Hello all,

Can anyone pls help me to check out where is the problem with my EA? It open some trade where the condition set is not met.Below is the attached file of my code

Appreciate your help.

Thank,

Newbie

Files:
whroeder1
17828
whroeder1  
  1. Rename your file's extension to mql4 not txt.

  2. Why did you post your MT4 question in the Root / MT5 Systems section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  3. double sl=High[1];
    double sl2=Low[1];
    These are globally declared variables, they are initialized once on load. They don't update unless you assign to them. Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent and prices are valid.

  4. extern double   bmi=25.0;
    int OnInit(){
       bmi*=0.01;
    The first time the EA is loaded bmi is 0.25. Every time you change TFs or symbol you reduce it again.

  5. void OpenBuyOrder(){
       orderStatus = OrderSend(Symbol(),OP_BUY,lot,Ask,3,sl2,tp,"",0,0,Green);
    }
    void OpenSellOrder(){
       orderStatus = OrderSend(Symbol(),OP_SELL,lot,Bid,3,sl,tp,"",0,0,Red);
    }
    Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  6.   if((body<=maxSize &&Open[1]<Close[1]&&High[1]-Open[1]<=maxSize
       &&Low[1]<Low[2]&&Low[1]<Low[3]&&Close[1]<LowStoch)||(body<=maxSize &&Open[1]>Close[1]&&High[1]-Close[1]<=maxSize
       &&Low[1]<Low[2]&&Low[1]<Low[3]&&Close[1]<LowStoch))
    Use the debugger or print out your variables, including _LastError and find out why.

  7.  void TrailStops(){
        for (int i = 0; i < OrdersTotal(); i++) {
    In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (US brokers,) (or the EA only opens one order per symbol,) you can simply count down in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 and MetaTrader 4 - MQL4 programming forum
      For FIFO (US brokers,) and you (potentially) process multiple orders per symbol, you must count up and on a successful operation, reprocess all positions (set index to -1 before continuing.)
    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use the Predefined Variables (Bid/Ask) or OrderClosePrice() instead, on the next order/server call.

Newbie
9
Newbie  

@whroeder1 Thk for your help will look through it.

Next time i will be posting in mt4. Din't notice here is mt5.

Sorry for the trouble cause

To add comments, please log in or register