OnTick does not execute - page 2

 
Fredyrik #: Here is the screenshots. My EA is named AutoTP.

Please test the attached EA on your machine ... and post the screenshot results on both logs.

Files:
 
Keith Watford #:

I find it difficult to believe that you have pasted the complete code in post #3.

I only left out a function I'm not using yet. Here is the whole.

//+------------------------------------------------------------------+
//|                                                       AutoTP.mq5 |
//|                                                   Copyright 2022 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022"
#property link      ""
#property version   "1.00"

//--- input parameters
input int      TakeProfit=10;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Print("OnTick");
  }
//+------------------------------------------------------------------+

void AddTakeProfit ()
   {
   PrintFormat("Add Take Profit");
/*
      MqlTradeRequest request;
      MqlTradeResult  result;

      ulong position_ticket = PositionGetTicket(PositionsTotal()-1);
      PositionSelectByTicket(position_ticket);
      double tp = OrderGetDouble(ORDER_TP);
      ulong Magic = OrderGetInteger(ORDER_MAGIC);
      
      if (tp == 0 && !Magic == 13)
      {
         //--- parameters of the order
         string position_symbol = PositionGetString(POSITION_SYMBOL); // symbol 
         int digits = (int)SymbolInfoInteger(position_symbol,SYMBOL_DIGITS); // number of decimal places
         double volume = PositionGetDouble(POSITION_VOLUME);    // volume of the position
         double sl = PositionGetDouble(POSITION_SL);  // Stop Loss of the position
         ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);  // type of the position

         //--- calculate the current price levels
         double price=PositionGetDouble(POSITION_PRICE_OPEN);
         double bid=SymbolInfoDouble(position_symbol,SYMBOL_BID);
         double ask=SymbolInfoDouble(position_symbol,SYMBOL_ASK);
         int stop_level=(int)SymbolInfoInteger(position_symbol,SYMBOL_TRADE_STOPS_LEVEL);
         tp = NormalizeDouble(TakeProfit,digits);
         //--- zeroing the request and result values
         ZeroMemory(request);
         ZeroMemory(result);
         //--- setting the operation parameters
         request.action = TRADE_ACTION_SLTP; // type of trade operation
         request.position = position_ticket;   // ticket of the position
         request.symbol = position_symbol;     // symbol 
         request.sl = sl;                // Stop Loss of the position
         request.tp = tp;                // Take Profit of the position
         request.magic = 13;         // MagicNumber of the position
         //--- output information about the modification
         PrintFormat("Modify #%I64d %s %s",position_ticket,position_symbol,EnumToString(type));
         //--- send the request
         if(!OrderSend(request,result))
            PrintFormat("OrderSend error %d",GetLastError());  // if unable to send the request, output the error code
         //--- information about the operation   
         PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
      }
*/
   }
 
Fredyrik #:

I only left out a function I'm not using yet. Here is the whole.

Again, that works exactly as it should.

 
Keith Watford #:

Again, that works exactly as it should.

Ok, now it works, I don't understand...

Sorry for the weird bug. Thank you everyone for your help.

 

Altough the author seems to have solved the problem already some time ago, this might be helpful for other users. At least I also ended up in this thread looking for a solution. 

In my case the OnTick() function DOES execute, but the Print() function seems to be not working within OnTick(). Whyever.... But PrintFormat() does!! :-)   

Problem solved. 

Reason: