How to code? - page 44

 

Gidday ralph.ronnquist

so should i create another sdl line something like SDLL = long SDLS = short ?

I think i'm right in saying that on the SDL indi

uptrend = buffer 1 & Index 1 colour Blue

dntrend = buffer 2 & Index 2 Colour Red

If so where would I put them. do I put them at the end of the iCustom line.

double SDL=iCustom(NULL,0,"Slope Direction Line",period,method,price,1,1,shift);

or am I way off track

 

The statement:

double SDL=iCustom(NULL,0,"Slope Direction Line",period,method,price,1,shift);

makes SDL hold the value of the second buffer (Uptrend) at the given "shift" bar.

(Note that you had a repeated ",1", which looked like a typo. In any case it should't be there)

So, yes, if you want to read off both Uptrend and Dntrend, then you'll need two variables to hold the values. As you say, Uptrend is 1 and Dntrend is 2.

 

Gidday ralph

Thanks for the help It's working I can go to sleep now.

Cheers

Beno

 
wolfe:
Hope this is what you were looking for.

It sent me in the right direction- thanks man, really appreciated.

My new issue is that when my if statement is called....

It goes off the previous indicator bar's value in relation to the current bar, and sends an Alert(); that I created... about 20 times.

How would I go about having it only send the once?

I tried created and on/off switch using variables-- doesn't work in MQL4 unfortunately.

Then I thought about Timers... if there was a timer I could create that only Alerted once over a 20 sec period that would work too....

But I'm a loss as to an idea that would actually be possible in MQL4.

Any ideas?

 

In other words... I need some way to stop it from Alerting after the first one, because at the moment it's Alerting multiple times (annoying and unnecessary as you might guess)

 
dharsant:
In other words... I need some way to stop it from Alerting after the first one, because at the moment it's Alerting multiple times (annoying and unnecessary as you might guess)

Could you provide some code to look at?

Maybe you could set up a boolean true/false to be tripped after the alert is sent the first time.

 

I'm not sure which code would make any sense. Here's my if statement for the alert.

"Code":

latestlatestmain = 2 bars back in my indicator.

latestmain = previous bar on my indicator

if(MainCCI > ErgoCCI){

{signal = "SHORT";

if ((latestlatestmain >= 0) && (latestmain < 0)) {

PlaySound("alert2.wav");

}

}

if(lastsignal != signal && alertTag!=Time[0]){

alertTag = Time[0];

lastsignal=signal;

}

}

if (MainCCI < ErgoCCI){

{signal = "LONG";

if ((latestlatestmain 0)) {

PlaySound("alert2.wav");

}

This is the FX Sniper indicator, and when it fits my parameters it sends the Alert.

How would I go about setting up a boolean true/false thing?

I tried doing this.....

"Code with on/off switch":

if(MainCCI > ErgoCCI){

{signal = "SHORT";

if ((latestlatestmain >= 0) && (latestmain < 0)) {

if (onealert == 1) {

PlaySound("alert2.wav");

onealert = 0;

} }

}

if(lastsignal != signal && alertTag!=Time[0]){

alertTag = Time[0];

lastsignal=signal;

}

}

if (MainCCI < ErgoCCI){

{signal = "LONG";

if ((latestlatestmain 0)) {

if (onealert == 0) {

PlaySound("alert2.wav");

onealert = 1;

} }

or some variant of that, to create the on/off with variables.

There's something else I could do using boolean is there? Any ideas on how I can go about doing that?

At the moment it works fine as far as alerting me goes, it just alerts me about 5-6 times.

Appreciate the time and help mate.

-dharsant

 

Just thought I'd worked it out, and that Sleep(); would work.... darn

 

I found this by Codersguru;

void AlertOnce(string alert_msg, int ref)

{

if (ref > 10)

return;

ref--;

static int LastAlert[10];

if( LastAlert[ref] == 0 || LastAlert[ref] < Bars)

{

Alert(alert_msg);

LastAlert[ref] = Bars;

}

}

Looks like what I'm after!!

In using this with my indicator...

Would I just place the function in my script, and then use

AlertOnce("Sniper going LONG",10);

in place of my Alert(); ?

I feel like a pesty little inexperienced programmer

 

Got it, thanks for the help!!!

Reason: