Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader Indicators

MetaTrader Indicators Post and discuss the MetaTrader indicators here.

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 7th February 2010, 23:49
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
I don't know but the second check on myCCInow in the end is unnecessary. Do you see any errors in the Experts log output?
Thanks for your help.
Code is now like this, but still not working

Quote:
//+------------------------------------------------------------------+
//| CCI Arrows |
//| Copyright © 2009, EarnForex |
//| http://www.earnforex.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link "http://www.earnforex.com"
#property version "1.01"
#property description "CCI Arrows - direct trading signals based on CCI indicator."
#property description "Displays red and blue arrows for Short and Long signals."

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_color1 Red
#property indicator_type1 DRAW_ARROW
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5

#property indicator_color2 Lime
#property indicator_type2 DRAW_ARROW
#property indicator_style2 STYLE_SOLID
#property indicator_width2 5



input ENUM_TIMEFRAMES TimeFrame = PERIOD_H4;
input double Arrow_Offset=20.0;


input double UpLevel=100;
input double DnLevel=-100;


double myCCInow;

double dUpCCIBuffer[];
double dDownCCIBuffer[];

input int CCI_Period = 21; //This value sets the CCI Period Used, The default is 21

int myCCI;
double CCIBuffer[];
double mtf_CCIBuffer[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+

void OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME, "CCI_Arrows(" + IntegerToString(CCI_Period) + ")");

//---- indicator buffers mapping

SetIndexBuffer(0, dUpCCIBuffer, INDICATOR_DATA);
SetIndexBuffer(1, dDownCCIBuffer, INDICATOR_DATA);

//---- drawing settings


PlotIndexSetInteger(0, PLOT_ARROW, 115);//233
// PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, -Arrow_Offset);
PlotIndexSetString(0, PLOT_LABEL, "CCI Buy");

PlotIndexSetInteger(1, PLOT_ARROW, 115);//234
// PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, Arrow_Offset);
PlotIndexSetString(1, PLOT_LABEL, "CCI Sell");



myCCI = iCCI(NULL,TimeFrame, CCI_Period, PRICE_TYPICAL);

}

//+------------------------------------------------------------------+
//| Custom CCI Arrows |
//+------------------------------------------------------------------+
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[])



{

//--------------------
datetime TimeArray[];


CopyTime(Symbol(), TimeFrame, 0, rates_total, TimeArray);
int shift, limit, y;

if(BarsCalculated(myCCI) < rates_total) return(0);

//--- we can copy not all data
int to_copy;
if(prev_calculated > rates_total || prev_calculated < 0) {
to_copy = rates_total;
}
else {
to_copy = rates_total-prev_calculated;
if(prev_calculated > 0)
to_copy++;
}

if(CopyBuffer(myCCI, 0, 0, rates_total, mtf_CCIBuffer) <= 0) {
Print("Getting MA buff failed! Error", GetLastError());
return(0);
}

for(int i=0, y=0; i<limit; i++) {
if (time[i] < TimeArray[y])
y++;

CCIBuffer[i] = mtf_CCIBuffer[y];

}


//--------------------


ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);


for (int i = rates_total; i > 1; i--)
{
dUpCCIBuffer[rates_total - i + 1] = 0;
dDownCCIBuffer[rates_total - i + 1] = 0;

myCCInow = CCIBuffer[rates_total - i + 1];

double myCCI2 = CCIBuffer[rates_total - i]; //CCI One bar ago

//---

if (myCCInow >= 0) //is going long
{
if(myCCI2 < 0) //did it cross from below 50
{
dUpCCIBuffer[rates_total - i + 1] = Low[i] - 2 * _Point*Arrow_Offset; //
}
}

//-----------------

if (myCCInow < 0) //is going short
{
if(myCCI2 > 0) //did it cross from above 50
{
dDownCCIBuffer[rates_total - i + 1] = High[i] + 2 * _Point*Arrow_Offset; //
}
}

//-----------------
}

//-----
return(rates_total);
}
Reply With Quote
  #22 (permalink)  
Old 8th February 2010, 08:07
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,445
Thanks: 6
Thanked 8 Times in 7 Posts
Default

I still suggest you looking at the Experts log tab in your MT5 terminal. You can also try outputting your myCCInow and myCCI2 values to see if they are correct.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #23 (permalink)  
Old 8th February 2010, 11:13
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
I still suggest you looking at the Experts log tab in your MT5 terminal. You can also try outputting your myCCInow and myCCI2 values to see if they are correct.
Coded it new and found error
array out of range

Quote:
//+------------------------------------------------------------------+
//| CCI Arrows |
//| Copyright © 2009, EarnForex |
//| http://www.earnforex.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link "http://www.earnforex.com"
#property version "1.01"
#property description "CCI Arrows - direct trading signals based on CCI indicator."
#property description "Displays red and blue arrows for Short and Long signals."

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_color1 Blue
#property indicator_type1 DRAW_ARROW
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_type2 DRAW_ARROW
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2

double dUpCCIBuffer[];
double dDownCCIBuffer[];
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H4;
input int CCI_Period = 14; //This value sets the CCI Period Used, The default is 21
int myCCI;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME, "CCI_Arrows(" + IntegerToString(CCI_Period) + ")");

//---- indicator buffers mapping
SetIndexBuffer(0, dUpCCIBuffer, INDICATOR_DATA);
SetIndexBuffer(1, dDownCCIBuffer, INDICATOR_DATA);

//---- drawing settings
PlotIndexSetInteger(0, PLOT_ARROW, 233);
PlotIndexSetInteger(1, PLOT_ARROW, 234);

PlotIndexSetString(0, PLOT_LABEL, "CCI Buy");
PlotIndexSetString(1, PLOT_LABEL, "CCI Sell");

myCCI = iCCI(NULL, 0, CCI_Period, PRICE_CLOSE);
}

//+------------------------------------------------------------------+
//| Custom CCI Arrows |
//+------------------------------------------------------------------+
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[])
{

double CCIBuffer[];
double mtf_CCIBuffer[];
//------------------------

datetime TimeArray[];

CopyTime(Symbol(), TimeFrame, 0, rates_total, TimeArray);
int shift, limit, y;

if(BarsCalculated(myCCI) < rates_total) return(0);

//--- we can copy not all data
int to_copy;
if(prev_calculated > rates_total || prev_calculated < 0) {
to_copy = rates_total;
}
else {
to_copy = rates_total-prev_calculated;
if(prev_calculated > 0)
to_copy++;
}

if(CopyBuffer(myCCI, 0, 0, rates_total, mtf_CCIBuffer) <= 0) {
Print("Getting MA buff failed! Error", GetLastError());
return(0);
}

for(int i=0, y=0; i<limit; i++) {
if (time[i] < TimeArray[y])
y++;

CCIBuffer[i] = mtf_CCIBuffer[y];

}

//---------------------------------------------------
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);




// CopyBuffer(myCCI, 0, 0, rates_total, CCIBuffer);

for (int i = rates_total; i > 1; i--)
{
dUpCCIBuffer[rates_total - i + 1] = 0;
dDownCCIBuffer[rates_total - i + 1] = 0;

double myCCInow = CCIBuffer[rates_total - i + 1]; // *******for this line array out of range ********
double myCCI2 = CCIBuffer[rates_total - i]; //CCI One bar ago

if (myCCInow >= 0) //is going long
{
if((myCCInow > 0) && (myCCI2 < 0)) //did it cross from below 50
{
dUpCCIBuffer[rates_total - i + 1] = Low[i] - 2 * _Point;
}
}

if (myCCInow < 0) //is going short
{
if((myCCInow < 0) && (myCCI2 > 0)) //did it cross from above 50
{
dDownCCIBuffer[rates_total - i + 1] = High[i] + 2 * _Point;
}
}
}

return(rates_total);
}
Reply With Quote
  #24 (permalink)  
Old 8th February 2010, 21:44
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,445
Thanks: 6
Thanked 8 Times in 7 Posts
Default

I don't think that you can copy arrays like it:

MQL5 Code:
CCIBuffer[i] = mtf_CCIBuffer[y];

You didn't specify the size of CCIBuffer anywhere before.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #25 (permalink)  
Old 8th February 2010, 23:03
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
I don't think that you can copy arrays like it:

MQL5 Code:
CCIBuffer[i] = mtf_CCIBuffer[y];

You didn't specify the size of CCIBuffer anywhere before.
How should I do this?
Reply With Quote
  #26 (permalink)  
Old 9th February 2010, 07:39
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,445
Thanks: 6
Thanked 8 Times in 7 Posts
Default

You do it with CopyBuffer. But why do you copy an indicator to mtf_CCIBuffer instead of the one you use in further calculations?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #27 (permalink)  
Old 9th February 2010, 07:54
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
You do it with CopyBuffer. But why do you copy an indicator to mtf_CCIBuffer instead of the one you use in further calculations?
OK, changed now the code to this version, but still is not yet MTF

Quote:
//+------------------------------------------------------------------+
//| CCI Arrows |
//| Copyright © 2009, EarnForex |
//| http://www.earnforex.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, EarnForex"
#property link "http://www.earnforex.com"
#property version "1.01"
#property description "CCI Arrows - direct trading signals based on CCI indicator."
#property description "Displays red and blue arrows for Short and Long signals."

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_color1 Blue
#property indicator_type1 DRAW_ARROW
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_type2 DRAW_ARROW
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2

double dUpCCIBuffer[];
double dDownCCIBuffer[];
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H4;
input int CCI_Period = 14; //This value sets the CCI Period Used, The default is 21
int myCCI;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
IndicatorSetString(INDICATOR_SHORTNAME, "CCI_Arrows(" + IntegerToString(CCI_Period) + ")");

//---- indicator buffers mapping
SetIndexBuffer(0, dUpCCIBuffer, INDICATOR_DATA);
SetIndexBuffer(1, dDownCCIBuffer, INDICATOR_DATA);

//---- drawing settings
PlotIndexSetInteger(0, PLOT_ARROW, 233);
PlotIndexSetInteger(1, PLOT_ARROW, 234);

PlotIndexSetString(0, PLOT_LABEL, "CCI Buy");
PlotIndexSetString(1, PLOT_LABEL, "CCI Sell");

myCCI = iCCI(NULL, TimeFrame, CCI_Period, PRICE_CLOSE);
}

//+------------------------------------------------------------------+
//| Custom CCI Arrows |
//+------------------------------------------------------------------+
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[])
{

double CCIBuffer[];
double mtf_CCIBuffer[];
//------------------------

datetime TimeArray[];

CopyTime(Symbol(), TimeFrame, 0, rates_total, TimeArray);
int shift, limit, y;

if(BarsCalculated(myCCI) < rates_total) return(0);

//--- we can copy not all data
int to_copy;
if(prev_calculated > rates_total || prev_calculated < 0) {
to_copy = rates_total;
}
else {
to_copy = rates_total-prev_calculated;
if(prev_calculated > 0)
to_copy++;
}

if(CopyBuffer(myCCI, 0, 0, rates_total, CCIBuffer) <= 0) {
Print("Getting MA buff failed! Error", GetLastError());
return(0);
}

for(int i=0, y=0; i<limit; i++) {
if (time[i] < TimeArray[y])
y++;

CCIBuffer[i] = CCIBuffer[y];

}

//---------------------------------------------------
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);




// CopyBuffer(myCCI, 0, 0, rates_total, CCIBuffer);

for (int i = rates_total; i > 1; i--)
{
dUpCCIBuffer[rates_total - i + 1] = 0;
dDownCCIBuffer[rates_total - i + 1] = 0;

double myCCInow = CCIBuffer[rates_total - i + 1]; //
double myCCI2 = CCIBuffer[rates_total - i]; //CCI One bar ago

if (myCCInow >= 0) //is going long
{
if((myCCInow > 0) && (myCCI2 < 0)) //did it cross from below 50
{
dUpCCIBuffer[rates_total - i + 1] = Low[i] - 2 * _Point;
}
}

if (myCCInow < 0) //is going short
{
if((myCCInow < 0) && (myCCI2 > 0)) //did it cross from above 50
{
dDownCCIBuffer[rates_total - i + 1] = High[i] + 2 * _Point;
}
}
}

return(rates_total);
}
Reply With Quote
  #28 (permalink)  
Old 9th February 2010, 17:24
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,445
Thanks: 6
Thanked 8 Times in 7 Posts
Default

I don't quite understand what do you mean by MTF? How do you want to display an indicator from a smaller or bigger timeframe on the chart of the current timeframe?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #29 (permalink)  
Old 9th February 2010, 17:32
Default Avatar
Member
 
Join Date: Dec 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
I don't quite understand what do you mean by MTF? How do you want to display an indicator from a smaller or bigger timeframe on the chart of the current timeframe?
MTF=multi-time-frame
means: indicator should display the arrows of a higher (4h) in lower (1h or 15min) timeframes.
Reply With Quote
  #30 (permalink)  
Old 9th February 2010, 18:02
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,445
Thanks: 6
Thanked 8 Times in 7 Posts
Default

Quote:
Originally Posted by fxwalb View Post
MTF=multi-time-frame
means: indicator should display the arrows of a higher (4h) in lower (1h or 15min) timeframes.
I know what MTF means, I just don't understand how are you going to achieve it. For example, it's H1 chart and you want to use M5 CCI arrows. How will you display 2 or more arrows generated during one 60-minute period? And what's the point?
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
Reply

Bookmarks

Tags
arrows, cci, cross, indicator, metatrader


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



All times are GMT. The time now is 17:42.


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