I would suggest Metaquotes the creation of a course that starts from bases (syntax), also with some video if possible, of specific to mq5: this is very useful for those who start programming.
I think that many people are interested in MT5 but not know how to programming.
many thanks, your code works, i.e.the label shows up, but the value is not updating. Did I make a mistake?
Here is my code.
walb99,
Try this. The problem was that you tried to update the value only if label object was not available. I added timestamp to the label, so you can see the time updating with every tick.
int OnCalculate( constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
int limit;
if (CountBars >= rates_total) limit = 0; else limit = rates_total - CountBars;
CopyBuffer(ma1_handle, 0, 0, rates_total, MA1TempBuffer);
for (int i = rates_total - 1; i > limit; i--)
{
MA1Buffer[i] = MA1TempBuffer[i];
double myMA_now = MA1TempBuffer[i];
double myMA_previous = MA1TempBuffer[i - 1]; //MA One bar agoif (myMA_now >= myMA_previous) MA1ColorBuffer[i] = 0;
elseif (myMA_now < myMA_previous) MA1ColorBuffer[i] = 1;
}
myMAnow=MA1TempBuffer[rates_total-1-MA1_Shift];
// myMAnow=MA1TempBuffer[rates_total - 1];
myPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if(myPrice>myMAnow)label_color=Lime; else label_color=Red;
// check if label object does not already exist and create itif(ObjectFind(0,label_info)<0)
{
// Create label in indicator's window ObjectCreate(0,label_info,OBJ_LABEL,window,0,0);
// Set X and Y distance from UPPER RIGHT CORNER ObjectSetInteger(0,label_info,OBJPROP_XDISTANCE,200);
ObjectSetInteger(0,label_info,OBJPROP_YDISTANCE,20);
ObjectSetInteger(0,label_info,OBJPROP_CORNER, CORNER_RIGHT_UPPER);
// Set text properties: colour, font and font sizeObjectSetInteger(0,label_info,OBJPROP_COLOR,label_color);
ObjectSetString(0,label_info,OBJPROP_FONT,"Arial");
ObjectSetInteger(0,label_info,OBJPROP_FONTSIZE,14);
// Set text to displayObjectSetString(0,label_info,OBJPROP_TEXT,DoubleToString(myMAnow,nDigits));
} else
{
ObjectSetString(0,label_info,OBJPROP_TEXT,TimeToString(TimeCurrent(), TIME_SECONDS)+" "+DoubleToString(myMAnow,nDigits));
};
return(rates_total);
}
Try this. The problem was that you tried to update the value only if label object was not available. I added timestamp to the label, so you can see the time updating with every tick.
Thanks, this works
if I put also info about label color into the brackets, the label color is also updated properly.
ok, I think i got it work from just showing the text, next I will work with the indicator. but can somebody tell me why I can't use obj_label instead of obj_text to make it display the text ?
//+------------------------------------------------------------------+ //| text win 2.mq5 | //| Copyright CREATE BY DK | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "CREATE BY DK" #property link "http://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_plots 1
string ddock = "try it out"; int windows = -1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ intOnInit() { //--- indicator buffers mapping /* if ((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR) windows=ChartWindowFind();
if (ObjectFind(0,ddock)<0) { ObjectCreate(0,ddock,OBJ_LABEL,windows,0,0); ObjectSetInteger(0,ddock,OBJPROP_XDISTANCE,200); ObjectSetInteger(0,ddock,OBJPROP_YDISTANCE,20); ObjectSetInteger(0,ddock,OBJPROP_CORNER, CORNER_RIGHT_UPPER); ObjectSetInteger(0,ddock,OBJPROP_COLOR,LightBlue); ObjectSetString(0,ddock,OBJPROP_FONT,"Arial"); ObjectSetInteger(0,ddock,OBJPROP_FONTSIZE,14); ObjectSetString(0,ddock,OBJPROP_TEXT, "TRYING VERY HARD"); } else Print("ddock already exists"); */ /* if((ENUM_PROGRAM_TYPE)MQL5InfoInteger(MQL5_PROGRAM_TYPE)==PROGRAM_INDICATOR) windows=ChartWindowFind(); */ // check if label object does not already exist and create it if(ObjectFind(0,ddock)<0) { // Create label in indicator's window ObjectCreate(0,ddock,OBJ_TEXT,windows,0,0); // Set X and Y distance from UPPER RIGHT CORNER ObjectSetInteger(0,ddock,OBJPROP_XDISTANCE,200); ObjectSetInteger(0,ddock,OBJPROP_YDISTANCE,20); ObjectSetInteger(0,ddock,OBJPROP_CORNER, CORNER_RIGHT_UPPER); // Set text properties: colour, font and font size ObjectSetInteger(0,ddock,OBJPROP_COLOR,LightPink); ObjectSetString(0,ddock,OBJPROP_FONT,"Arial"); ObjectSetInteger(0,ddock,OBJPROP_FONTSIZE,14); // Set text to display ObjectSetString(0,ddock,OBJPROP_TEXT,"TRYING VERY HARD"); } elsePrint("ddock already exists");
//--- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ intOnCalculate(constint rates_total, constint prev_calculated, constdatetime& time[], constdouble& open[], constdouble& high[], constdouble& low[], constdouble& close[], constlong& tick_volume[], constlong& volume[], constint& spread[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ /* void OnDeinit(const int reason) { if (!ObjectFind(0,ddock)<0) ObjectDelete(0,ddock); } /* void OnDeinit(const int reason) { //--- if(!ObjectFind(0,ddock)<0) ObjectDelete(0, ddock); } */
22
Thanks wald99 : I am trying.
I would suggest Metaquotes the creation of a course that starts from bases (syntax), also with some video if possible, of specific to mq5: this is very useful for those who start programming.
539
Hi Investeo
many thanks, your code works, i.e.the label shows up, but the value is not updating. Did I make a mistake?
Here is my code.
walb99,
Try this. The problem was that you tried to update the value only if label object was not available. I added timestamp to the label, so you can see the time updating with every tick.
15
walb99,
Try this. The problem was that you tried to update the value only if label object was not available. I added timestamp to the label, so you can see the time updating with every tick.
Thanks, this works
if I put also info about label color into the brackets, the label color is also updated properly.
8
where do you assign that objectname to in the rsi example above? I read the whole code but doesnt understand,
I just want to put a simple text into the indicator windows, I just cant get the same result like the RSI example above
My code :
result :
8
ok, I think i got it work from just showing the text, next I will work with the indicator. but can somebody tell me why I can't use obj_label instead of obj_text to make it display the text ?