Array Begining vs End

 

I have an indicator with the following code.

The intent is to open an alert window when the SSA line crosses the 0 level.

However, when the 0 level is crossed, there is no alert window.

Then, several candles later, the alert window finally opens.

I need help with the Alert section to identify the problem. Thanks.

#import "SSA.ex4"
void fastsingular(double a[],int n,int lag,int s,double& b[]);
#import

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_level1 0.0
// ------------------------------------------------------------------------------------------
// E X T E R N A L V A R I A B L E S 
// ------------------------------------------------------------------------------------------
extern int Lag=50;
extern int NumComps=5;
extern int PeriodNorm=20;
extern int N=300;
extern bool Alerts=false;
// ------------------------------------------------------------------------------------------
// I N T E R N A L V A R I A B L E S 
// ------------------------------------------------------------------------------------------
double arryTimeSeries[];
double SSA[];
// ------------------------------------------------------------------------------------------
// I N I T I A L I S A T I O N 
// ------------------------------------------------------------------------------------------
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,SSA);
ArrayResize(arryTimeSeries,N);

IndicatorShortName("");
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
SetIndexLabel(4,NULL);
SetIndexLabel(5,NULL);
SetIndexLabel(6,NULL);
SetIndexLabel(7,NULL);
return(0);
} 
// ------------------------------------------------------------------------------------------
// Main Processing Section 
// ------------------------------------------------------------------------------------------
int start()
{
int counted_bars=IndicatorCounted();
SetIndexDrawBegin(0,Bars-N);
double dev,ma;
int i, nmax, nmin;

for( i=N-1; i>=0; i--) {

ma=iMA(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i);
dev=3*iStdDev(NULL,0,PeriodNorm,0,MODE_SMA,PRICE_CLOSE,i);
if(dev==0) dev=0.1;
arryTimeSeries[i]=(Close[i]-ma)/dev;//iDeMarker(NULL,0,PeriodNorm,i);
}
fastsingular(arryTimeSeries,N,Lag,NumComps,SSA);

if(Alerts)
{
if(SSA[N] > 0 && SSA[N-1] <=0 && SSA[N] != EMPTY_VALUE)
{
Alert("SSA Cross Above 0Level- BUY. SSA[N]=",SSA[N]," SSA[N-1]=", SSA[N-1]);
}
else if(SSA[N] < 0 && SSA[N-1] >=0 && SSA[N] != EMPTY_VALUE)
{
Alert("SSA Cross Below 0Level- SELL. SSA[N]=",SSA[N]," SSA[N-1]=", SSA[N-1]);
}
}
return(0);
}
// ------------------------------------------------------------------------------------------
// End Program 
// ------------------------------------------------------------------------------------------ 

Files:
temp.mq4  4 kb
 

Where is the source for SSA?

Where is the evidence that SSA is indeed crossing zero when you think so?

You are making some bold assertions without evidence to back you up ... and nothing for us to work with.

 

I forget the mathematical priority evaluation for someing like "SSA[N] > 0 && SSA[N-1] <=0 && SSA[N] != EMPTY_VALUE" so I just use a lot of brackets to be sure it works as intended.

 

  1. fastsingular(arryTimeSeries,N,Lag,NumComps,SSA);
    arryTimeSeries is a normal array (zero on the left,) SSA is a series array (zero index on the right. ) is it putting the values where you expect?
 
brewmanz:

Where is the source for SSA?

Where is the evidence that SSA is indeed crossing zero when you think so?

You are making some bold assertions without evidence to back you up ... and nothing for us to work with.


Attached is an example. The Alert window opened, but the SSA is not crossing the 0 level.
 

*exasperation* Your refusal to allow me to duplicate your charts is VERY ANNOYING.

As far as I can see, THE PROGRAM IS DOING EXACTLY WHAT YOU ARE TELLING IT TO - Displaying an alert N (300) bars after SSA is crossing 0

I'll say that again in a different way; You are NOT asking for an alert when SSA crossing 0, but N bars AFTER it crosses 0

Some of us are willing to assist, but you are making it very difficult because you are making FAR TOO MANY ASSUMPTIONS and releasing FAR TOO LITTLE CODE! Will you PLEASE show ...

- The chart at the point that is N bars old

It would be REALLY helpful to have the program display the time, rather taking your word for it (sorry, but I've caught MYSELF out many times ASSUMING what the values are)

i.e. Display "Time[123] = ..." and convert Time[N] to a human readable form.

*mutter* this is like trying to fight with one hand tied behind my back

 

@ brewmanz we don't have to help, it is nice to help but we don't have to!

After all we could just tell the poster to put print statements at all the critical points in the code so they can easily solve the problem for themselves.

Reason: