Thread: How to code?
View Single Post
  #888 (permalink)  
Old 05-10-2008, 10:51 AM
hiachiever hiachiever is offline
Member
 
Join Date: Jan 2006
Posts: 48
hiachiever is on a distinguished road
One obvious thing is that you are missing a declaration for the number of indicator buffers that you are going to use.

This sits in the first part of init
eg
int init()
{
IndicatorBuffers(2);
.....
}


Give it a go and see if it fixes your problem. Note I haven't fully checked the code, I simply checked for obvious errors.

Cheers,
Hiachiever.

Quote:
Originally Posted by Nordic12 View Post
Hi

Ive tried to create an indicator and was wondering to see if someone can help me (i feel its 99.9% finished - well phase I anyway)

I just want an arrow when the CCI cross over zero line and the stoc crosses upwards (ideally the first time) - reverse for second time


//+------------------------------------------------------------------+
//| CCI_Stoc_Xover.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| Forex Trading Software: Forex Trading Platform MetaTrader 4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 SeaGreen
#property indicator_color2 Red

extern int CCI_Period = 14;
extern int Stoc_K=5;
extern int Stoc_D=3;
extern int Stoc_Slowing=3;

double CrossUp[];
double CrossDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY,3);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY,3);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
int limit, i, counter;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(i = 0; i <= limit; i++) {

counter=i;
double cci_1 = iCCI(Symbol(), Period(), CCI_Period, PRICE_TYPICAL, 1);
double cci_2 = iCCI(Symbol(), Period(), CCI_Period, PRICE_TYPICAL, 2);
double stok_0 = iStochastic(Symbol(), Period(), Stoc_K, Stoc_D, Stoc_Slowing, MODE_SMA, 0, MODE_MAIN, 0);
double stod_0 = iStochastic(Symbol(), Period(), Stoc_K, Stoc_D, Stoc_Slowing, MODE_SMA, 0, MODE_SIGNAL, 0);
double stok_1 = iStochastic(Symbol(), Period(), Stoc_K, Stoc_D, Stoc_Slowing, MODE_SMA, 0, MODE_MAIN, 1);
double stod_1 = iStochastic(Symbol(), Period(), Stoc_K, Stoc_D, Stoc_Slowing, MODE_SMA, 0, MODE_SIGNAL, 1);

if ((cci_2 <= 0 && cci_1 > 0 && stok_1 < stod_1 && stok_0 > stod_0)) {
CrossUp[i] = Low[i];
}
else if ((cci_2 >= 0 && cci_1 < 0 && stok_1 > stod_1 && stok_0 < stod_0)) {
CrossDown[i] = High[i];
}
}
return(0);
}
Reply With Quote