MT5 Indicator , converted from MT4 (no display DrawText) not working

 

HI..

I need help with MT5 conversion.


I created an indicator in MT4 which displayed Balances and trading info, but when I converted it across to MT5. 

I managed to get rid of all the errors except for "no indicator plot defined for indicator",  I added the following

#property indicator_plots 1

and that got rid of the final error.


But nothing is displaying on my chart.

I am using Drawtext, which is not giving me an error, but I can't find any information on MT5 and Drawtext.

Can someone please help.

 
Kristina Suh:

HI..

I need help with MT5 conversion.

I created an indicator in MT4 which displayed Balances and trading info, but when I converted it across to MT5. 

I managed to get rid of all the errors except for "no indicator plot defined for indicator",  I added the following

#property indicator_plots 1

and that got rid of the final error.

But nothing is displaying on my chart.

I am using Drawtext, which is not giving me an error, but I can't find any information on MT5 and Drawtext.

Can someone please help.

Hmm... not sure if any one can help from your description alone... without any code to play with...

 

Thanks for your reply

Here is the opening section, which i think the problem is there, because nothing is coming up at all, not even normal Comment Text.

   

      #import "stdlib.ex5"

#import

#include <stdliberr.mqh>



#property indicator_chart_window 

//#property indicator_separate_window

#property indicator_buffers 5

#property indicator_plots 1


Attached file.   MT4 vs MT5 view

 bool    ShowProfitInfo          = true;

 bool    ShowTodayRanges         = false;

input bool    ShowRiskInfo            = false;

 bool    ShowAccountOrderInfo    = true;

 int     RiskStopLoss            = 0;

 string  RiskLevels              = "1,5,10,20,40,50,60,80,100";


 bool    OnlyAttachedSymbol      = false;

 int     MagicNumber             = -1;

 string  CommentFilter           = "";

 string  StartDateFilter         = "";

input int     FontSize                = 10;//General Text

input int     fontS                   =10; //Balances

 bool    WhiteMode               = false;


int      windowIndex                   = 0;

string   preCurrSign                   = "";

string   postCurrSign                  = "";

double   pip_multiplier                = 1.0;

int      daySeconds                    = 86400;


double   MaxDD            = 0,

         MaxDDp           = 0,

         CurrentDD        = 0, 

         CurrentDDp       = 0;


datetime maxDDDay;

datetime startDateFilter = 0;

datetime LastDrawProfitInfo = 0;


This section also could be an issue.  even though I am not getting any errors when I compile it.


oid DrawRiskInfo() {

//+------------------------------------------------------------------+

   SetPipMultiplier(Symbol());


   if (RiskStopLoss > 0)

      DrawText(1, 0, 0, "Order Risk (SL=" + IntegerToString(RiskStopLoss) + ")", WhiteMode?Black:White, FontSize); 

   else

      DrawText(1, 2, 10, "Order Risk", WhiteMode?Black:White, FontSize); 

   

   DrawText(1, 3, 10, "-------------------", WhiteMode?Black:White, FontSize); 

   

   string levels = RiskLevels;

   int i = 0;

  

   while (StringLen(levels) > 0)

   {

      string c = StringTrimLeft_MQL4(StringTrimRight_MQL4(CutAt(levels, ",")));

      double value = StringToDouble(c);

      

      if (value != EMPTY_VALUE) {

      

         color clr = levelColors[ArraySize(levelColors) - 1];

         if ( i < ArraySize(levelColors))

            clr = levelColors[i];            

      

         DrawText(1, i + 4, 0, StringConcatenate_MQL4(value, "%:   ", DTS(MM(value), 2) + " lot"), clr, FontSize); 

         i++;

         

      }

   } 

}

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Properties
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Properties
  • www.mql5.com
Price chart drawing. If false, drawing any price chart attributes is disabled and all chart border indents are eliminated, including time and price scales, quick navigation bar, Calendar event labels, trade labels, indicator and bar tooltips, indicator subwindows, volume histograms, etc. Scrolling the chart horizontally using the left mouse...
Files:
IndMT5.png  38 kb
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button




 
Kristina Suh:

Thanks for your reply

Here is the opening section, which i think the problem is there, because nothing is coming up at all, not even normal Comment Text.

Your DrawText() function - where is it declared? 

 
Seng Joo Thio:

Your DrawText() function - where is it declared? 

void DrawAccountInfo() {
//+------------------------------------------------------------------+
   SetPipMultiplier(Symbol());
   int row = 1;
   string text;
   int colWidth1 = 200;
   
   color c = WhiteMode?DarkBlue:LightCyan;
   text = StringConcatenate_MQL4("Balance:  ", MTS(AccountBalance(),2)); 
      DrawText(0, row, 0, text, c, FontSize); 
   
       
   double eqPercent = 0;
   if (AccountBalance() > 0)
      eqPercent = MathDiv(AccountEquity(), AccountBalance() * 100.0);
   
   text = StringConcatenate_MQL4("Equity:  ", MTS(AccountEquity()), "  (", DTS(eqPercent, 2), "%)"); 
   DrawText(0, row, colWidth1, text, c, FontSize); 
   row++;
   double marginLevel = 0;
   
   if (AccountMargin() > 0) marginLevel = MathDiv(AccountEquity(), AccountMargin() * 100.0);
   text = StringConcatenate_MQL4("Margin: ", DTS(AccountMargin(), 2), "  (", DTS(marginLevel, 2), "%)"); 
   DrawText(0, row, 0, text, c, FontSize); 
   
   if (AccountFreeMargin() < 0)
      c = Red;
   text = StringConcatenate_MQL4("Free margin: ", DTS(AccountFreeMargin(), 2)); 
   DrawText(0, row, colWidth1, text, c, FontSize); 
   row++;
   c = WhiteMode?DarkBlue:LightCyan;

   text = StringConcatenate_MQL4("Leverage: 1:", AccountLeverage()); 
   DrawText(0, row, 0, text, c, FontSize); 
   
   text = StringConcatenate_MQL4("Swap  Long: ", MTS(MarketInfo(Symbol(), MODE_SWAPLONG), 2), "  Short: ", MTS(MarketInfo(Symbol(), MODE_SWAPSHORT), 2)); 
   DrawText(0, row, colWidth1, text, c, FontSize); 
   row++;

   DrawText(0, row, 0, "-------------------------------------------------------------", Gray, FontSize); 
}

Here is another section where it defines the Text,  

It worked perfectly in MT4, but I am getting nothing in MT5, yet when i compile it I have NO errors.

Is there something else I need to add in MT5 or change for the text?

thanks

 
Kristina Suh:

Here is another section where it defines the Text,  

It worked perfectly in MT4, but I am getting nothing in MT5, yet when i compile it I have NO errors.

Is there something else I need to add in MT5 or change for the text?

thanks

No, not Text, but DrawText() function - where is it defined?

Because DrawText() is not a standard function of MQL4 and MQL5 (could be from windows, but your code did not contain the necessary importation, so perhaps not).

So if your program compiles, then that function must exist some where within your code, designed for MT4 primarily... and that is likely the reason why you can't display texts in MT5.

 
Seng Joo Thio:

No, not Text, but DrawText() function - where is it defined?

Because DrawText() is not a standard function of MQL4 and MQL5 (could be from windows, but your code did not contain the necessary importation, so perhaps not).

So if your program compiles, then that function must exist some where within your code, designed for MT4 primarily... and that is likely the reason why you can't display texts in MT5.

What do you suggest I change it to for MT5 to work.

I need to display text as a Dashboard info Indicator..

 
Kristina Suh:

What do you suggest I change it to for MT5 to work.

I need to display text as a Dashboard info Indicator..

No, there is no need to change DrawText() to something else... because you'll have a lot more challenge in figuring out the meaning of each of its parameters and then make them work in harmony to display your dashboard...

How about we do it another way... go to your mq5 (or the original mq4) file, search for "ObjectCreate(". See whether there is a function named DrawText, that contains ObjectCreate(. If there is, that is the function you need to check through and possibly modify, so that your dashboard information will show up.

 
Seng Joo Thio:

No, there is no need to change DrawText() to something else... because you'll have a lot more challenge in figuring out the meaning of each of its parameters and then make them work in harmony to display your dashboard...

How about we do it another way... go to your mq5 (or the original mq4) file, search for "ObjectCreate(". See whether there is a function named DrawText, that contains ObjectCreate(. If there is, that is the function you need to check through and possibly modify, so that your dashboard information will show up.

HI, @tsengjoo


Here is some text from Object create.  

I noticed that Color and Text info needs to be changed from MT4 to MT5 coding, but it is really hard to find examples 

thanks for your help

void DrawText(int corner, int row, int xOffset, string text, color c, int size = 7) {
//+------------------------------------------------------------------+
   string objName = "TradeInfo_" + DTS(corner) + "_" + DTS(xOffset) + "_" + DTS(row);
   if (ObjectFind(objName) != 0) {
      ObjectCreate(objName, OBJ_LABEL, windowIndex, 0, 0);
      ObjectSet(objName, OBJPROP_CORNER, corner);
      ObjectSet(objName, OBJPROP_SELECTABLE, 0);
      ObjectSet(objName, OBJPROP_HIDDEN, 1);
   }

   ObjectSetText(objName, text, size, "Verdana", c);
   ObjectSet(objName, OBJPROP_XDISTANCE, 6 + xOffset);
   ObjectSet(objName, OBJPROP_YDISTANCE, 6 + row * (size + 6));
   ObjectSet(objName, OBJPROP_BACK, false);
}
//   create_button(EquityP)
double CE=(DoubleToString((AccountEquity()-GetBalance())));
create_button1(name_EquityP,350,60,150,60,clrBGE,clrfontE,"Current Equity Profit  $ "+DoubleToString(AccountEquity()-GetBalance(),2));
Print("  C Equity "+ CE);
 

the Button does not display, but I know that the calculation is correct, because the Print command confirmed the results.
 
Kristina Suh:

HI, @tsengjoo

Here is some text from Object create.  

I noticed that Color and Text info needs to be changed from MT4 to MT5 coding, but it is really hard to find examples 

thanks for your help

the Button does not display, but I know that the calculation is correct, because the Print command confirmed the results.

For DrawText() function, the right functions to use are all listed in https://www.mql5.com/en/docs/objects.

I've changed the obvious ones, try this:

void DrawText(int corner, int row, int xOffset, string text, color c, int size = 7) {
//+------------------------------------------------------------------+
   string objName = "TradeInfo_" + DTS(corner) + "_" + DTS(xOffset) + "_" + DTS(row);
   long cid = ChartID();
   if (ObjectFind(cid,objName) != 0) {
      ObjectCreate(cid,objName, OBJ_LABEL, windowIndex, 0, 0);
      ObjectSetInteger(cid,objName, OBJPROP_CORNER, corner);
      ObjectSetInteger(cid,objName, OBJPROP_SELECTABLE, 0);
      ObjectSetInteger(cid,objName, OBJPROP_HIDDEN, 1);
   }

   ObjectSetTextString(cid,objName, OBJPROP_TEXT, text);
   ObjectSetInteger(cid,objName,OBJPROP_FONTSIZE, size);
   ObjectSetString(cid,objName,OBJPROP_FONT, "Verdana");
   ObjectSetInteger(cid,objName,OBJPROP_COLOR, c);
   ObjectSetInteger(cid,objName, OBJPROP_XDISTANCE, 6 + xOffset);
   ObjectSetInteger(cid,objName, OBJPROP_YDISTANCE, 6 + row * (size + 6));
   ObjectSetInteger(cid,objName, OBJPROP_BACK, false);
}

As for create_button1(), just like DrawText(), it's your own function somewhere within your code... look for it.

Documentation on MQL5: Object Functions
Documentation on MQL5: Object Functions
  • www.mql5.com
The functions defining the properties of graphical objects, as well as ObjectCreate() and ObjectMove() operations for creating and moving objects along the chart are actually used for sending commands to the chart. If these functions are executed successfully, the command is included in the common queue of the chart events. Visual changes in...
Reason: