Coding help - page 117

 

Thanks mladen, im a starter programmer,as a matter of fact you are the one that helped me with part one code sometime ago but the alert still repeat at the beginning of new candle ,pls kindly help me see to both part one and two.Thanks in advanced!

See the original message below:

Good day all, pls I want someone to help me modify the code below and explain.The number one part of the code contains buy and sell alert.It support to give alert when buy and sell signal only occur but it repeat the alert at the beginning of every new candle....pls help to correct this by making the alert sound when the set up condition occur only.

The second part of the code is a stop alert.It is to send stop signal to user when the undergoing buy or sell opportunity is no more.Those code has refuse to work at all, help pls....

static datetime lastAlerted=0;

//Momentum.....1hour

double mom_1h=iMomentum(NULL,60,14,PRICE_CLOSE,0);

double b4mom_1h=iMomentum(NULL,60,14,PRICE_CLOSE,1);

(1)========Alerts for buy and Sell==========

//Alerts for buy

if(mom_1h>99.6353)&&(mom_1h>b4mom_1h)&&(lastAlerte d!=Time[0])){

lastAlerted=Time[0];

Alert(Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

//Alerts for Sell

if(mom_1h<100.7482)&&(mom_1h<b4mom_1h)&&(lastAlert ed!=Time[0])){

lastAlerted=Time[0];

Alert("Sell","\n","Current time is ",TimeToStr(TimeLocal(),TIME_SECONDS),"\n",Symbol( ));

}

(2)==========Alerts for Stop buying and sell==============

//Alert to stop Buy

if(mom_1h<b4mom_1h)&&(lastAlerted!=Time[0])){

lastAlerted=Time[0];

Alert(Stop Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

//Alerts to Stop Selling

if(mom_1h>b4mom_1h)&&(lastAlerted!=Time[0])){

lastAlerted=Time[0];

Alert(" Stop Sell","\n","Current time is ",TimeToStr(TimeLocal(),TIME_SECONDS),"\n",Symbol( ));

}

 
Mastercash:
Thanks mladen, im a starter programmer,as a matter of fact you are the one that helped me with part one code sometime ago but the alert still repeat at the beginning of new candle ,pls kindly help me see to both part one and two.Thanks in advanced!

See the original message below:

Good day all, pls I want someone to help me modify the code below and explain.The number one part of the code contains buy and sell alert.It support to give alert when buy and sell signal only occur but it repeat the alert at the beginning of every new candle....pls help to correct this by making the alert sound when the set up condition occur only.

The second part of the code is a stop alert.It is to send stop signal to user when the undergoing buy or sell opportunity is no more.Those code has refuse to work at all, help pls....

static datetime lastAlerted=0;

//Momentum.....1hour

double mom_1h=iMomentum(NULL,60,14,PRICE_CLOSE,0);

double b4mom_1h=iMomentum(NULL,60,14,PRICE_CLOSE,1);

(1)========Alerts for buy and Sell==========

//Alerts for buy

if(mom_1h>99.6353)&&(mom_1h>b4mom_1h)&&(lastAlerte d!=Time[0])){

lastAlerted=Time[0];

Alert(Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

//Alerts for Sell

if(mom_1h<100.7482)&&(mom_1h<b4mom_1h)&&(lastAlert ed!=Time[0])){

lastAlerted=Time[0];

Alert("Sell","\n","Current time is ",TimeToStr(TimeLocal(),TIME_SECONDS),"\n",Symbol( ));

}

(2)==========Alerts for Stop buying and sell==============

//Alert to stop Buy

if(mom_1h<b4mom_1h)&&(lastAlerted!=Time[0])){

lastAlerted=Time[0];

Alert(Stop Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

//Alerts to Stop Selling

if(mom_1h>b4mom_1h)&&(lastAlerted!=Time[0])){

lastAlerted=Time[0];

Alert(" Stop Sell","\n","Current time is ",TimeToStr(TimeLocal(),TIME_SECONDS),"\n",Symbol( ));

}

Try something like this :

static datetime lastAlerted1=0;

static datetime lastAlerted2=0;

static string lastType1="";

static string lastType2="";

//Momentum.....1hour

double mom_1h=iMomentum(NULL,60,14,PRICE_CLOSE,0);

double b4mom_1h=iMomentum(NULL,60,14,PRICE_CLOSE,1);

//========Alerts for buy and Sell==========

//Alerts for buy

if((mom_1h>99.6353)&&(mom_1h>b4mom_1h)&&(lastAlerted1!=Time[0] && lastType1!="Buy")){

lastAlerted1=Time[0];

lastType1="Buy";

Alert("Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

//Alerts for Sell

if((mom_1h<100.7482)&&(mom_1h<b4mom_1h)&&(lastAlerted1!=Time[0] && lastType1!="Sell")){

lastAlerted1=Time[0];

lastType1="Sell";

Alert("Sell","\n","Current time is ",TimeToStr(TimeLocal(),TIME_SECONDS),"\n",Sym bol( ));

}

//==========Alerts for Stop buying and sell==============

//Alert to stop Buy

if((mom_1h<b4mom_1h)&&(lastAlerted2!=Time[0]&&lastType2!="Stop Buy")){

lastAlerted2=Time[0];

lastType2="Stop Buy";

Alert("Stop Buy","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

//Alerts to Stop Selling

if((mom_1h>b4mom_1h)&&(lastAlerted2!=Time[0]&&lastType2!="Stop Sell")){

lastAlerted2=Time[0];

lastType2="Stop Sell";

Alert(" Stop Sell","\n","Current time is ",TimeToStr(TimeLocal(),TIME_SECONDS),"\n",Sym bol( ));

}

 

Thanks,I will do that!

 

Coding help

Hi all.

Please, mladen or mr.tools. I have a little problem with the refreshing of this indicator. When a new candle opens, it doesn´t auto-refresh correctly, and I have to open and close the external parameters window to refresh it. Could you take a look at the code and fix it?

Thanks.

s.mq4

Files:
s.mq4  3 kb
 
lrprez:
Hi all.

Please, mladen or mr.tools. I have a little problem with the refreshing of this indicator. When a new candle opens, it doesn´t auto-refresh correctly, and I have to open and close the external parameters window to refresh it. Could you take a look at the code and fix it?

Thanks.

s.mq4

lrprez

Try it out now

Files:
s-2.mq4  3 kb
 

Thank you very much, mladen. You are a genius.

 

Need help on mt4 coding

Hi all,

I am looking for help on writing code with spec below:

1. i will input specific date & time

2. I wan the indicator to show the

the specific date & time candle open, high, low, close

For example, i input D'2013.8.01 13:00' & place in at M30 chart

The indicator will show me M30 chart candle at D'2013.8.01 13:00'

open, high, low, close value.

Thanks

 
tkz883:
Hi all,

I am looking for help on writing code with spec below:

1. i will input specific date & time

2. I wan the indicator to show the

the specific date & time candle open, high, low, close

For example, i input D'2013.8.01 13:00' & place in at M30 chart

The indicator will show me M30 chart candle at D'2013.8.01 13:00'

open, high, low, close value.

Thanks

You can do it like this :

#property copyright ""

#property link ""

#property indicator_chart_window

extern datetime TimeToCheck = D'2013.8.01 13:00';

int init() { return(0); }

int start()

{

int bar = iBarShift(NULL,0,TimeToCheck);

Comment("Open : "+DoubleToStr(Open,Digits)+"\n"+

"Close : "+DoubleToStr(Close,Digits)+"\n"+

"High : "+DoubleToStr(High,Digits)+"\n"+

"Low : "+DoubleToStr(Low,Digits));

return(0);

}
Files:
tkz.mq4  1 kb
 

Simple coding help

Need help on coding an indicator:

A. INPUT:

1. date & time info: D'2013.8.01 13:00'

2. Applied Price: Open, high, low close

B. Usage Example:

1. For example, i want the indicator to display the open price for

input date D'2013.8.01 13:00' in M60 charts & the indicator will

show me the open price value of the candle at tat specific input date

2. Next, the indicator will show the open price for anytime

after D'2013.8.01 13:00' (but not be4) & keep on updating

 

Hi mladen, I had this indicator tweaked a long time ago & I like how it displays now but the only problem is, it now is using up entirely to much CPU. Could you please take a look under the hood & see if maybe the code needs to be cleaned up or see why it freezes my platform when the markets start moving.

It will be greatly appreciated!

Thank you in advance!

G

Files:
Reason: