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 14th September 2011, 16:18
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default indicator not showing

Hi

I am not getting my indicator on the screen when I compile and run the code below. do I need to drag it to a chart or to id a window?
Please take a look to see if all else is Ok.

thx

MQL5 Code:
#property description "stoch_change"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_color1  Blue

//--- indicator
double rlBuffer [300];

int OnInit()
  {
// a class here populates the rlBuffer
   return(0);
  }

int OnCalculate(const int rates_total,
...
  {
   SetIndexBuffer(0,rlBuffer,INDICATOR_DATA);
Reply With Quote
  #2 (permalink)  
Old 14th September 2011, 20:22
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

SetIndexBuffer(0,rlBuffer,INDICATOR_DATA); should go into OnInit() handler. You should be filling the array (rlBuffer) with actual indicator values in the OnCalculate().
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #3 (permalink)  
Old 16th September 2011, 20:49
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
SetIndexBuffer(0,rlBuffer,INDICATOR_DATA); should go into OnInit() handler. You should be filling the array (rlBuffer) with actual indicator values in the OnCalculate().
thanks for that.
Why this is not plotting as expected?

MQL5 Code:
#property description "test"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_SOLID
#property indicator_color1  Blue

double iBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
    SetIndexBuffer(0,iBuf,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   iBuf[0] = high[0];
   iBuf[1] = high[1];
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+---------------------------------------
Reply With Quote
  #4 (permalink)  
Old 17th September 2011, 07:52
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

iBuf[0] is the oldest bar on the chart in MetaTrader 5 (unless you use ArraySetAsSeries() on it), not the newest. So, are you sure it's not plotting?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #5 (permalink)  
Old 17th September 2011, 08:05
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
iBuf[0] is the oldest bar on the chart in MetaTrader 5 (unless you use ArraySetAsSeries() on it), not the newest. So, are you sure it's not plotting?
I tried to populate the indicator buffer in OnInt() since the markets are closed and OnCalculate will not fire but I am not getting the indicator to show

GBPJPY H4


MQL5 Code:
//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                                             Copyright 2011, titi |
//|                                     http://www.test.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, test"
#property link      "http://www.test.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_label1  "alosh"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

double iBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
    SetIndexBuffer(0,iBuf,INDICATOR_DATA);
    ArraySetAsSeries(iBuf, true);
   
    iBuf[0] = 123.200;  
    iBuf[1] = 123.200;
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
    iBuf[0] = 123.200;  
    iBuf[1] = 123.200;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reply With Quote
  #6 (permalink)  
Old 17th September 2011, 11:53
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

First, remove any indicator buffer assignments from the OnInit(). Second, you are also missing these lines:
MQL5 Code:
#property indicator_buffers 1
#property indicator_plots   1
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #7 (permalink)  
Old 17th September 2011, 15:58
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thx for that. I got it to work, now I tired to modify it with my "real" indicator but this is not plotting. Please take another look thx

MQL5 Code:
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_label1  "alosh"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

   double rlBuffer [300];
   CLASS_TYPE h4_alosh("GBPJPY", PERIOD_H4);


int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,rlBuffer,INDICATOR_DATA);
   ArrayInitialize(rlBuffer,EMPTY_VALUE);
   h4_alosh.set_SOMTHIN();
   h4_alosh.set_ANOTHER();    
   
//---
   return(0);
  }

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   h4_alosh.get_POPULATE_INDICATOR(2, rlBuffer, false);    
ushort n = ArraySize(rlBuffer)-1; for(ushort i=0; i<=50; i++) Alert("index, value=== " + i + "        " +rlBuffer[i]); //n-i

// YES IT PRINTED THE VALUES SUITABLE FOR PLOTTING.

//--- return value of prev_calculated for next call
   return(rates_total);
  }
Reply With Quote
  #8 (permalink)  
Old 17th September 2011, 17:28
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,548
Thanks: 18
Thanked 20 Times in 16 Posts
Default

Indicator data array should be dynamic. And don't use ArrayInitialize(rlBuffer,EMPTY_VALUE) on it. Use PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE) . Hope that helps.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #9 (permalink)  
Old 17th September 2011, 20:45
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
Indicator data array should be dynamic. .... Hope that helps.
Well.
Yes and No.
thanks for that.

this code I am writing for an EA but want to see it on the screen while I am developing it.
Static Array is very lean/cheap comparing to dynamic ones when running. Now what would I do to have my cake and eat it at the same time?

Will typecasting help? i.e. by CopyBuffer for the indicator and leave it static for the EA?

OnCalculate()...

ArrayCopy(indicator_Buf, static_rlBuffer, 0, 0, WHOLE_ARRAY);

Last edited by samjesse; 17th September 2011 at 20:57. Reason: new thought
Reply With Quote
  #10 (permalink)  
Old 17th September 2011, 21:06
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried to test it myself but it gives strange information.

MQL5 Code:
//--- in the code heading
   double iBuf[];

//---  in OnCalculate

   Alert(ArrayIsDynamic(iBuf));    //<<<<<<< FALSE <<<< WHY <<<<<
   ArrayCopy(iBuf, rlBuffer, 0, 0, WHOLE_ARRAY);
   Alert(ArrayIsDynamic(iBuf));     //<<<<<<< FALSE <<<< WHY <<<<<
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
Wall Street is Showing Signs of Reverse mercaforex Fundamental Analysis 0 25th August 2009 11:58
MTF CCI Indicator MechXTrader MetaTrader Indicators 0 3rd July 2009 04:35


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