Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader 5

MetaTrader 5 MT5 is already out of its beta stage, but the development is ongoing. Some brokers already offer real accounts and the interest of traders is growing. You can discuss anything related to MetaTrader 5 in this forum.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 24th September 2011, 20:06
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default indicator colour

Hi

I am not sure why my indicator is not changing color. please help thx.

MQL5 Code:
double iBuf[];  
double iBuf_colour[];

int OnInit()
  {
   SetIndexBuffer(0,iBuf,INDICATOR_DATA);
   SetIndexBuffer(1, iBuf_colour,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Red);  
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Blue);
}


int OnCalculate(...)
{
   for(int x = 0; x < ArraySize(itemp); x++)
   {
      iBuf[x] = itemp[x];
      if(x>6) iBuf_colour[x]=0;
      else iBuf_colour[x]=1;
   }

}
Reply With Quote
  #2 (permalink)  
Old 24th September 2011, 21:32
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

It'd better if you could also show your #property declarations for this indicator.

I don't know why do you use PlotIndexSetInteger for color setting. I do it with #property:

MQL5 Code:
#property indicator_color1 clrYellow, clrWhite

Then, you color values are incorrect. MQL5 now uses 'clr' prefix for all colors.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 24th September 2011, 23:08
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

did you mean this way?
it is still not plotting the indicator in 2 colors.

MQL5 Code:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_color1  clrRed, clrBlue


int OnInit()
  {

   SetIndexBuffer(0,iBuf,INDICATOR_DATA);
   SetIndexBuffer(1, iBuf_colour,INDICATOR_COLOR_INDEX);
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
 return(0);
}

int OnCalculate(const int rates_total,...

   for(int x = 0; x < ArraySize(itemp); x++)
   {
      iBuf[x] = itemp[x];
      if(x>6) iBuf_colour[x]=0;
      else iBuf_colour[x]=1;
}
   return 1;
Reply With Quote
  #4 (permalink)  
Old 25th September 2011, 08:09
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

MQL5 Code:
#property indicator_type1   DRAW_LINE

Should be:

MQL5 Code:
#property indicator_type1   DRAW_COLOR_LINE

This line isn't needed:

MQL5 Code:
PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

OnCalculate() should return rates_total, not '1'.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #5 (permalink)  
Old 25th September 2011, 17:52
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

when I use the following line, it plots the indicator in Red only.
MQL5 Code:
#property indicator_type1 DRAW_LINE

When I use the following line, it does not plot it at all.
MQL5 Code:
#property indicator_type1 DRAW_COLOR_LINE

here are the relevant sections of the code:
MQL5 Code:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_color1 clrRed, clrBlue


// Indicator buffers
double itemp[300];
double iBuf[];  
double iBuf_colour[];

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,iBuf,INDICATOR_DATA);
   SetIndexBuffer(1, iBuf_colour,INDICATOR_COLOR_INDEX);
   
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   ArraySetAsSeries(iBuf, true);

int OnCalculate(const int rates_total,...

   for(int x = 0; x < ArraySize(itemp); x++)
   {
      iBuf[x] = itemp[x];
      if(x<6) iBuf_colour[x]=1;
      else iBuf_colour[x]=0;
//Alert(x + "  colour is  " + iBuf_colour[x]);    <<<< all is well
}
  return (rates_total);
  }

Last edited by samjesse; 25th September 2011 at 17:55.
Reply With Quote
  #6 (permalink)  
Old 25th September 2011, 18:08
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

You set iBuf as timeseries, so that [0] is the latest bar, but you don't set iBuf_colour as timeseries, so its [0] is oldest bar on the chart. That's probably the reason.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #7 (permalink)  
Old 25th September 2011, 18:18
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. that fixed it.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
QQE Indicator Enivid MetaTrader Indicators 0 20th August 2010 09:10
SAR Spy [MT4 Indicator] x1nx0nx MetaTrader Indicators 0 28th December 2009 18:10
RSI Signal (Buy\Sell Indicator) - GREAT signal indicator MechXTrader MetaTrader Indicators 0 25th September 2009 08:34
MTF CCI Indicator MechXTrader MetaTrader Indicators 0 3rd July 2009 04:35
MTF RSI Indicator MechXTrader MetaTrader Indicators 1 2nd July 2009 21:47


All times are GMT. The time now is 11:14.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2