Please help / Question_?

To add comments, please log in or register
Stanislav Milka
521
Stanislav Milka  
Hi, please help. (I am self-taught)
I can't figure out why it's a mistake.

EA buys or sells according to the last candle opean <closed or opean> closed

When the loss is closed, the EA multiplies the next position until it closes on the TP.

Please help.
Error: 'selectOurOrder' - function not defined opean bricks renko.mq4 325 13

Thank you
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict

//--- input parameters
input int      TakeProfit=50;
input int      StopLoss=50;
input double   LotSize=0.1;
input int      Slippage=3;
input int      MagicNumber=5555;

// ====================================================================
// Enums and Classes
// ====================================================================

enum TradeDir {
    TradeDir_NONE,
    TRADEDIR_LONG,
    TRADEDIR_SHORT
};

enum ScalperPhaseType {
    SCALPERPHASE_NEUTRAL,
    SCALPERPHASE_TOP,
    SCALPERPHASE_BOTTOM
};

enum ScalperBufferType {
    SCALPERBUFFER_NEUTRAL = 0,
    SCALPERBUFFER_TOP = 1,
    SCALPERBUFFER_BOTTOM = 2
};

enum LogLevel {
    LogLevel_NULL  = 0,
    LOGLEVEL_FATAL = 1,
    LOGLEVEL_ERROR = 2,
    LOGLEVEL_WARN  = 3,
    LOGLEVEL_INFO  = 4,
    LOGLEVEL_DEBUG = 5,
    LOGLEVEL_TRACE = 6
};


class Logger {
   
private:
    LogLevel m_level;

public:
    Logger(const LogLevel level) {
        m_level = level;
    }

    void log(const LogLevel level, const string message) {
        if (isEnabled(level)) {
            PrintFormat("[%s] %s", toString(level), message);
        }
    }

    bool isEnabled(const LogLevel level) {
        return (level <= m_level);
    }

    void fatal(const string message) {
        log(LOGLEVEL_FATAL, message);
    }
    void error(const string message) {
        log(LOGLEVEL_ERROR, message);
    }
    void warn(const string message) {
        log(LOGLEVEL_WARN, message);
    }
    void info(const string message) {
        log(LOGLEVEL_INFO, message);
    }
    void debug(const string message) {
        log(LOGLEVEL_DEBUG, message);
    }
    void trace(const string message) {
        log(LOGLEVEL_TRACE, message);
    }

   

 

private:

    static string toString(const LogLevel level) {
        switch (level) {
            case LOGLEVEL_FATAL: return "FATAL";
            case LOGLEVEL_ERROR: return "ERROR";
            case LOGLEVEL_WARN: return "WARN";
            case LOGLEVEL_INFO: return "INFO";
            case LOGLEVEL_DEBUG: return "DEBUG";
            case LOGLEVEL_TRACE: return "TRACE";
            default: return "???";
        }
    }
}; 


//--- global variables
double MyPoint;
int    MySlippage;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   MyPoint = MyPoint();
   MySlippage = MySlippage();

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if(TotalOpenOrders() == 0 && IsNewBar() == true)
     {
      // Check Buy Entry
      if(BuySignal() == true)
        {
         OpenBuy();
        }

      // Check Sell Entry
      else
         if(SellSignal() == true)
           {
            OpenSell();
           }
     }

  }
//+------------------------------------------------------------------+
//| Custom functions                                                 |
//+------------------------------------------------------------------+

// Buy Logic
bool BuySignal()
  {
   if(Close[1] > Open[1])
     {
      return(true);
     }
   else
     {
      return(false);
     }
  }


// Sell Logic
bool SellSignal()
  {
   if(Close[1] < Open[1])
     {
      return(true);
     }
   else
     {
      return(false);
     }
  }


// Open Buy Order
void OpenBuy()
  {
// Open Buy Order
   int ticket = OrderSend(_Symbol,OP_BUY,LotSize,Ask,MySlippage,0,0,"BUY",MagicNumber);

   if(ticket<0)
     {
      Print("OrderSend failed with error #",GetLastError());
     }
   else
     {
      Print("OrderSend placed successfully");
     }

// Modify Buy Order
   bool res = OrderModify(ticket,OrderOpenPrice(),Ask-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,0);

   if(!res)
     {
      Print("Error in OrderModify. Error code=",GetLastError());
     }
   else
     {
      Print("Order modified successfully.");
     }
  }


// Open Sell Order
void OpenSell()
  {
//Open Sell Order
   int ticket = OrderSend(_Symbol,OP_SELL,LotSize,Bid,MySlippage,0,0,"SELL",MagicNumber);

   if(ticket<0)
     {
      Print("OrderSend failed with error #",GetLastError());
     }
   else
     {
      Print("OrderSend placed successfully");
     }

// Modify Sell Order
   bool res = OrderModify(ticket,OrderOpenPrice(),Bid+StopLoss*MyPoint,Bid-TakeProfit*MyPoint,0);

   if(!res)
     {
      Print("Error in OrderModify. Error code=",GetLastError());
     }
   else
     {
      Print("Order modified successfully.");
     }
  }


// Get My Points
double MyPoint()
  {
   double CalcPoint = 0;

   if(_Digits == 2 || _Digits == 3)
      CalcPoint = 0.01;
   else
      if(_Digits == 4 || _Digits == 5)
         CalcPoint = 0.0001;

   return(CalcPoint);
  }


// Get My Slippage
int MySlippage()
  {
   int CalcSlippage = 0;

   if(_Digits == 2 || _Digits == 4)
      CalcSlippage = Slippage;
   else
      if(_Digits == 3 || _Digits == 5)
         CalcSlippage = Slippage * 10;

   return(CalcSlippage);
  }


// Check if there is a new bar
bool IsNewBar()
  {
   static datetime RegBarTime=0;
   datetime ThisBarTime = Time[0];

   if(ThisBarTime == RegBarTime)
     {
      return(false);
     }
   else
     {
      RegBarTime = ThisBarTime;
      return(true);
     }
  }


// Returns the number of total open orders for this Symbol and MagicNumber
int TotalOpenOrders()
  {
   int total_orders = 0;

   for(int order = 0; order < OrdersTotal(); order++)
     {
      if(OrderSelect(order,SELECT_BY_POS,MODE_TRADES)==false)
         break;

      if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol)
        {
         total_orders++;
        }
     }

   return(total_orders);
  }
//+------------------------------------------------------------------+
//Repeat positions//

bool findLatestClosedPosition(int &out_ticket, double &out_pl, double &out_lots) {
    out_ticket = -1;
    out_pl = out_lots = 0.0;
    
    datetime latestOrderOpenTime = NULL, orderOpenTime;
    for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) {
        if (selectOurOrder(i, SELECT_BY_POS, MODE_HISTORY) &&
                    isBuyOrSell(OrderType())) {
            orderOpenTime = OrderOpenTime();
            if (latestOrderOpenTime == NULL || orderOpenTime > latestOrderOpenTime) {
                latestOrderOpenTime = orderOpenTime;
                out_ticket = OrderTicket();
                out_pl = OrderProfit() + OrderSwap() + OrderCommission();
                out_lots = OrderLots();
            }
        }
    }
    return (out_ticket != -1);
}

inline bool wasSelectedOrderTPHit() {
    return (OrderProfit() > 0.0);   // TODO: fix if an actual TP hit needs to be tested
}

inline bool isBuyOrSell(const int op) {
    return (op == OP_BUY || op == OP_SELL);
}
William Roeder
22458
William Roeder  
Stanislav Milka: Please help.
Error: 'selectOurOrder' - function not defined opean bricks renko.mq4 325 13

Help you want what? That line has a function call, but you didn't define it.

Stanislav Milka
521
Stanislav Milka  
William Roeder:

Help you want what? That line has a function call, but you didn't define it.

Where?

In another code, this also has no definition and it works.

Thank you

William Roeder
22458
William Roeder  
Stanislav Milka: Error: 'selectOurOrder' - function not defined opean bricks renko.mq4 325 13
Stanislav Milka: Where? In another code, this also has no definition and it works.
  1. Line 325 column 13.
  2. Impossible. Post the code and your compile log for it.
  3. Rewrite your topic to something meaningful.
              Use meaningful, specific subject headers
  4. Why did you post your MT4 question in the MT5 General 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.

To add comments, please log in or register