Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Custom indicator request
 Post subject: Custom indicator request Post rating: 0   New post Posted: Thu 27 Oct, 2011, 19:41 

User rating: -
Hi,

I would like to ask you to help me in coding the following 2 very simple custom indicators I am using for my trading. I wrote it in MQL4, unfortunately, the MQL4 - Jforex converter could not convert them error free.

Indicator 1 - MidpointChange Histogramm - Indicator in a separate pane below the chart

The indicator should calculate 2 values for each bar:
1. HL/2 of the current bar = midpoint
2. The average of the midpoints of the last 2 bars = avgmidpoint
The indicator should compare these 2 figures for each tick and display the indicator value based on the following rule:

if (avgmidpoint<=midpoint)
{
indicator value = midpoint - avgmidpoint
}
else
{
indicator value =midpoint - avgmidpoint;
}
It would be very useful if the midpointchange histogram indicator should have different colors depending on whether the indicator value is higher or lower than 0.

2. It would be very nice to have an indicator, which puts a mark above/below the bar at the close of the bar , in case the midpoint change indicator change polarity on the close of the actual bar.
So e.g. it should put a dot above the bar at the close if the midpoint change indicator goes from positive figure on the previous bar to negative at the close of the current bar. Similarly, it would be nice if it put a dot below the current bar, if the midpoint change histogram indicator goes from negative figure on the previous bar to positive at the close of the current bar.

Your help is very much appreciated!

Thanks in advance!


 
 Post subject: Re: Custom indicator request Post rating: 0   New post Posted: Fri 28 Oct, 2011, 09:05 

User rating: 0
Joined: Thu 20 Oct, 2011, 12:11
Posts: 9
Location: Latvia,
viewtopic.php?f=110&t=43112


 
 Post subject: Re: Custom indicator request Post rating: 0   New post Posted: Fri 28 Oct, 2011, 09:45 

User rating: -
Hi,

thanks for the link! I converted the indicators successfully, however compilation showing a number of errors.
I am not sure what the problem could be. As said, the indicator is very basic in MQL4. Could you please take a look at the error log.
Thanks!

2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 Exception JFException is not compatible with throws clause in MQL4ConnectorIndicator.deinit()
2011-10-28 08:34:30 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2011-10-28 08:34:30 public int deinit() throws JFException {
2011-10-28 08:34:30 8. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 81)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 The method iMA(Instrument, int, int, int, int, int, int) from the type MQL4Functions refers to the missing type JFException
2011-10-28 08:34:30 ^^^
2011-10-28 08:34:30 AVGMED0 = toDouble(iMA(null,0,2,1,MODE_SMA,PRICE_MEDIAN,i));
2011-10-28 08:34:30 7. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 62)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 The method iMA(Instrument, int, int, int, int, int, int) from the type MQL4Functions refers to the missing type JFException
2011-10-28 08:34:30 ^^^
2011-10-28 08:34:30 MED0 = toDouble(iMA(null,0,1,0,MODE_SMA,PRICE_MEDIAN,i));
2011-10-28 08:34:30 6. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 60)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 Exception JFException is not compatible with throws clause in MQL4ConnectorIndicator.start()
2011-10-28 08:34:30 ^^^^^^^^^^^^^^^^^^^^^^^^^^
2011-10-28 08:34:30 public int start() throws JFException {
2011-10-28 08:34:30 5. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 44)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 The method SetIndexStyle(Number, Number, Number, Number, Color) from the type MQL4ConnectorIndicator refers to the missing type JFException
2011-10-28 08:34:30 ^^^^^^^^^^^^^
2011-10-28 08:34:30 SetIndexStyle(1,DRAW_HISTOGRAM,2,2,Green);
2011-10-28 08:34:30 4. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 37)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 The method SetIndexStyle(Number, Number, Number, Number, Color) from the type MQL4ConnectorIndicator refers to the missing type JFException
2011-10-28 08:34:30 ^^^^^^^^^^^^^
2011-10-28 08:34:30 SetIndexStyle(0,DRAW_HISTOGRAM,2,2,Red);
2011-10-28 08:34:30 3. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 31)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 Exception JFException is not compatible with throws clause in MQL4ConnectorIndicator.init()
2011-10-28 08:34:30 ^^^^^^^^^^^^^^^^^^^^^^^^^
2011-10-28 08:34:30 public int init() throws JFException {
2011-10-28 08:34:30 2. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 27)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:30 The hierarchy of the type MeanChange_Histo is inconsistent
2011-10-28 08:34:30 ^^^^^^^^^^^^^^^^
2011-10-28 08:34:30 public class MeanChange_Histo extends MQL4ConnectorIndicator {
2011-10-28 08:34:30 1. ERROR in C:\DOCUME~1\User\LOCALS~1\Temp\jfxide\tmp\MeanChange_Histo.java (at line 10)
2011-10-28 08:34:30 ----------
2011-10-28 08:34:23 Compiling MeanChange_Histo.java


 
 Post subject: Re: Custom indicator request Post rating: 0   New post Posted: Fri 28 Oct, 2011, 10:47 

User rating: 0
Joined: Thu 20 Oct, 2011, 12:11
Posts: 9
Location: Latvia,
Hi,

If you could provide the source for the indicator, I could take a look what is the problem. Btw, did the example indicators work for you?


 
 Post subject: Re: Custom indicator request Post rating: 0   New post Posted: Fri 28 Oct, 2011, 12:08 

User rating: -
Hi,

thanks very much for your help. Yes, the codes work on MT4.
Please find the indicator codes below.

Indicator 1:
/+------------------------------------------------------------------+
//| Meanchange_Histo |
//| Copyright ďż˝ 2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ďż˝ 2010, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net"

#property indicator_separate_window //Indicator is in a separate window
#property indicator_buffers 2 //Number of buffers

extern int History =20; //# of bars in calculation history



double Line_0[], Line_1[]; //Declaring data arrays

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//+-------
//Negative Histogramm
SetIndexBuffer(0,Line_0); //Assigning an array to buffer 0
SetIndexStyle(0,DRAW_HISTOGRAM,2,2,Red); //Line style
SetIndexArrow(0, 234);
//Positive Histogramm
SetIndexBuffer(1,Line_1);
SetIndexStyle(1,DRAW_HISTOGRAM,2,2,Green); //Line style
SetIndexArrow(1, 233);

//+-------
return(0);
}
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, Counted_bars=IndicatorCounted(); //Number of counted bars

double MED0, AVGMED0;


//+-------

Counted_bars=IndicatorCounted(); //Number of counted bars
i=Bars-Counted_bars-1; //Index of the first uncounted bar
if (i>History-1) //If too many bars...
i=History-1; //... calculate only for specified # of bars

while (i>=0) //Loop for uncounted Bars
{


//Initialization

MED0=iMA(NULL,0,1,0,MODE_SMA,PRICE_MEDIAN,i);
AVGMED0=iMA(NULL,0,2,1,MODE_SMA,PRICE_MEDIAN,i);



if (AVGMED0<=MED0)
{
Line_0[i]=0;
Line_1[i]=MED0-AVGMED0;
}
else
{
Line_0[i]=MED0-AVGMED0;
Line_1[i]=0;

}


i--; //Next bar
}

//+-------
return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}


Indicator2:
//+------------------------------------------------------------------+
//| Meanchange.mq4 |
//| Copyright ďż˝ 2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ďż˝ 2010, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net"

#property indicator_chart_window //Indicator is in a separate window
#property indicator_buffers 2 //Number of buffers

extern int History =20; //# of bars in calculation history



double Line_0[], Line_1[]; //Declaring data arrays

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//+-------
//Change down
SetIndexBuffer(0,Line_0); //Assigning an array to buffer 0
SetIndexStyle(0,DRAW_ARROW,EMPTY,2,Red); //Line style
SetIndexArrow(0, 234);
//Change up
SetIndexBuffer(1,Line_1);
SetIndexStyle(1,DRAW_ARROW,EMPTY,2,Green); //Line style
SetIndexArrow(1, 233);

//+-------
return(0);
}
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i, Counted_bars=IndicatorCounted(); //Number of counted bars

double MED0, MED1, AVGMED0, AVGMED1;


//+-------

Counted_bars=IndicatorCounted(); //Number of counted bars
i=Bars-Counted_bars-1; //Index of the first uncounted bar
if (i>History-1) //If too many bars...
i=History-1; //... calculate only for specified # of bars

while (i>=0) //Loop for uncounted Bars
{



//Initialization

MED0=iMA(NULL,0,1,0,MODE_SMA,PRICE_MEDIAN,i);
MED1=iMA(NULL,0,1,0,MODE_SMA,PRICE_MEDIAN,i+1);
AVGMED0=iMA(NULL,0,2,1,MODE_SMA,PRICE_MEDIAN,i);
AVGMED1=iMA(NULL,0,2,1,MODE_SMA,PRICE_MEDIAN,i+1);


if (((AVGMED1>MED1)&&(AVGMED0>MED0))||((AVGMED1<MED1)&&(AVGMED0<MED0)))
{
Line_0[i]=2147483647;
Line_1[i]=2147483647;
}

if ((AVGMED1>MED1)&&(AVGMED0<MED0))
{
Line_0[i]=2147483647;
Line_1[i]=Low[i]-40*Point;
}

if ((AVGMED1<MED1)&&(AVGMED0>MED0))
{
Line_0[i]=High[i]+40*Point;
Line_1[i]=2147483647;
}


i--; //Next bar
}

//+-------
return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}


 
 Post subject: Re: Custom indicator request Post rating: 0   New post Posted: Sun 30 Oct, 2011, 21:59 

User rating: 0
Joined: Thu 20 Oct, 2011, 12:11
Posts: 9
Location: Latvia,
Download the ConverterClient 1.1 here:
https://code.google.com/p/mql4-connector/downloads/list

I attached both of your indicators, that i tested with.


Attachments:
Indicator2.mq4 [2.4 KiB]
Downloaded 316 times
Indicator1.mq4 [2.09 KiB]
Downloaded 317 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com