How to code? - page 317

 

Hi,

i'm thinking how i can code this indicator/Tools.

I need an indicator,script or something like it where i can decide some range in days (ex 12/10/2012-15/10/2012 or 15/10/2012-15/10/2012) and after it writ in a csv or excel file the open high low and close for the candle displayed in the chart depending on TF (ex. if i decide only one day and attach it in 1hr TF it write 24 candle with their specification).

Thank you in advance for your help

 

Alert Signal Problem.

Hi everyone in the house,there is this little problem with an MT4 code I wrote.This code suppose to watch over three indys, stoichastic,RSI,and CCI.if stoichastic crosses its signal line up or down AND RSI of period 70 and 6 crosses each other up or down and CCI is above or below zero, there should a buy signal if the whole 3 indys are above their signal lines or there should be sell signal if the 3 indys are below their signal lines........this code works but whenever there is alert, it keep on repeating itself at each ticks of the candle.What can I do to make this alert only sound once if the three conditions are met on current candle and not reapt sound. this is the code below.

if(Period()==240){

double ist_main=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_MAIN,0);

double ist_signal=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_SIGNAL,0);

double RSIP1=iRSI(NULL,240,14,PRICE_CLOSE,0);

double RSIP2=iRSI(NULL,240,70,PRICE_CLOSE,0);

double b4enCCI=iCCI(NULL,240,6,PRICE_TYPICAL,1);

double nowenCCI=iCCI(NULL,240,6,PRICE_TYPICAL,0);

double b4trCCI=iCCI(NULL,240,14,PRICE_TYPICAL,1);

double nowtrCCI=iCCI(NULL,240,14,PRICE_TYPICAL,0);

// alerts

if((ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI>0&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)){

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

}

if((ist_main<ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI<0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI<b4trCCI)){

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

}

}

 
mladen:
pooh

It is simply because the values of different symbols can differ so much (for example GBPJPY is around 126 now and EURUSD is roughly 100 times less - when you draw those values on the same chart, the value of EURUSD is simply "out of the picture because metatrader takes GBPJPY values as a criteria for chart scaling).

Take a look at this thread : https://www.mql5.com/en/forum/178052 . There are a couple of solutions for similar problems at that thread already

Thank you Mladen. Followed your link and found the indicator that suits my need.

pooh

 

Try like this :

if(Period()==240)

{

static datetime lastAlerted=0;

double ist_main=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_MAIN,0);

double ist_signal=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_SIGNAL,0);

double RSIP1=iRSI(NULL,240,14,PRICE_CLOSE,0);

double RSIP2=iRSI(NULL,240,70,PRICE_CLOSE,0);

double b4enCCI=iCCI(NULL,240,6,PRICE_TYPICAL,1);

double nowenCCI=iCCI(NULL,240,6,PRICE_TYPICAL,0);

double b4trCCI=iCCI(NULL,240,14,PRICE_TYPICAL,1);

double nowtrCCI=iCCI(NULL,240,14,PRICE_TYPICAL,0);

// alerts

if((ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI >0&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0]; Alert("Buy Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

if((ist_main<ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI <0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI<b4trCCI)&&(lastAlerted!=Time[0]))

{

lastAlerted=Time[0]; Alert("Sell Arrow","\n","Current time is ",TimeToStr(CurTime()),"\n",Symbol());

}

}
Mastercash:
Hi everyone in the house,there is this little problem with an MT4 code I wrote.This code suppose to watch over three indys, stoichastic,RSI,and CCI.if stoichastic crosses its signal line up or down AND RSI of period 70 and 6 crosses each other up or down and CCI is above or below zero, there should a buy signal if the whole 3 indys are above their signal lines or there should be sell signal if the 3 indys are below their signal lines........this code works but whenever there is alert, it keep on repeating itself at each ticks of the candle.What can I do to make this alert only sound once if the three conditions are met on current candle and not reapt sound. this is the code below.

if(Period()==240){

double ist_main=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_MAIN,0);

double ist_signal=iStochastic(NULL,240,8,3,3,MODE_SMA,0,MODE_SIGNAL,0);

double RSIP1=iRSI(NULL,240,14,PRICE_CLOSE,0);

double RSIP2=iRSI(NULL,240,70,PRICE_CLOSE,0);

double b4enCCI=iCCI(NULL,240,6,PRICE_TYPICAL,1);

double nowenCCI=iCCI(NULL,240,6,PRICE_TYPICAL,0);

double b4trCCI=iCCI(NULL,240,14,PRICE_TYPICAL,1);

double nowtrCCI=iCCI(NULL,240,14,PRICE_TYPICAL,0);

// alerts

if((ist_main>ist_signal)&&(RSIP1>RSIP2)&&(nowenCCI>0&&nowenCCI>b4enCCI)&&(nowtrCCI>0&&nowtrCCI>b4trCCI)){

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

}

if((ist_main<ist_signal)&&(RSIP1<RSIP2)&&(nowenCCI<0&&nowenCCI<b4enCCI)&&(nowtrCCI<0&&nowtrCCI<b4trCCI)){

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

}

}
 

Alert Problems

Thank you mladen, i will try it.I never take note of the function LastAlert() and please you may let me know where to get the directory of all this "tranche rouse" mt4 functions.

 

Mastercash

Be careful : that is not a function but a static variable that is used to store the time (bar time) of the last alert and that way prevents multiple alerts on the same bar. Unfortunately there is no such function as LastAlert() in metatrader so we have to find workarounds lake the one from the example to solve the lack of functions

Mastercash:
Thank you mladen, i will try it.I never take note of the function LastAlert() and please you may let me know where to get the directory of all this "tranche rouse" mt4 functions.
 

Hi mladen.

I need to assigne 24 variable each for the 24 last hour day candle.

I need to do some calculate with the candle and the result will be assigne at a buffer.

How i can code for work with each of the 24hr candle of the previous day?.

Thank you

 

dasio

You can use something similar to this (this mode does not use arrays). Also, this example is for current day

datetime startTime = iTime(NULL,PERIOD_D1,0);

for (int i=iBarShift(NULL,PERIOD_H1,startTime); TimeDayOfYear(iTime(NULL,PERIOD_H1,i))==TimeDayOfYear(startTime); i--)

{

//

//

// processing the hourly data ... just an example here

//

//

double close = iClose(NULL,PERIOD_H1,i); //

double open = iOpen(NULL,PERIOD_H1,i); // and so on ...

}

dasio:
Hi mladen.

I need to assigne 24 variable each for the 24 last hour day candle.

I need to do some calculate with the candle and the result will be assigne at a buffer.

How i can code for work with each of the 24hr candle of the previous day?.

Thank you
 
mladen:
dasio

You can use something similar to this (this mode does not use arrays). Also, this example is for current day

datetime startTime = iTime(NULL,PERIOD_D1,0);

for (int i=iBarShift(NULL,PERIOD_H1,startTime); TimeDayOfYear(iTime(NULL,PERIOD_H1,i))==TimeDayOfYear(startTime); i--)

{

//

//

// processing the hourly data ... just an example here

//

//

double close = iClose(NULL,PERIOD_H1,i); //

double open = iOpen(NULL,PERIOD_H1,i); // and so on ...

}

Thank you mladen.

In this example:

double close = iClose(NULL,PERIOD_H1,i); //

double open = iOpen(NULL,PERIOD_H1,i); //

Which candle rappresent and how i can switch to the next candle? i+1?

Thank you

 

dasio

It is looping through all the hours of the current day already. I placed the iClose() and iOpen() just as an example of a call from a time frame different than 1 hour. If you want to access different day than the current then replace the "0" on the datetime startTime=iTime(NULL,PERIOD_D1,0);part with any day you wish the data collected for

dasio:
Thank you mladen.

In this example:

double close = iClose(NULL,PERIOD_H1,i); //

double open = iOpen(NULL,PERIOD_H1,i); //

Which candle rappresent and how i can switch to the next candle? i+1?

Thank you
Reason: