Can someone advice me on my error?

 

Hi :


Good day. Please kindly advice. Below is my program, i knew it is not done properly.


start ()

{

double tick_now, tick_prev=0;

int cnt=0;


tick_now = BID;

If ( tick_now > tick_prev)

{

cnt++; // this is the problem..... i wish to count how many times, present price more than previous price.

}

if(cnt=3) // if it is 3 times, where the present price more than previous price, program will execute the LONG position.

{

ticket = OrderSend(Symbol(),OP_BUY,lot,Ask,2,0,0,"My LONG order",0,0,Green);

tick_prev = tick_now;

}

return(0);

}


Really appreciate if that is someone who willing to guide me. Thank you.


regards,

miki

 
miki308 wrote >>

Hi :

Good day. Please kindly advice. Below is my program, i knew it is not done properly.

start ()

{

double tick_now, tick_prev=0;

int cnt=0;

tick_now = BID;

If ( tick_now > tick_prev)

{

cnt++; // this is the problem..... i wish to count how many times, present price more than previous price.

}

if(cnt=3) // if it is 3 times, where the present price more than previous price, program will execute the LONG position.

{

ticket = OrderSend(Symbol(),OP_BUY,lot,Ask,2,0,0,"My LONG order",0,0,Green);

tick_prev = tick_now;

}

return(0);

}

Really appreciate if that is someone who willing to guide me. Thank you.

regards,

miki

Hi,

Just rapidly looking at it and considering I understood what you are trying to do correctly, I can see 3 pb

1. You are not using static (or global) types for cnt and prev_tick, meaning cnt can never get a value higher than 1 and prev_tick can never be different from zero when you test it, as they are both initialized at zero for every new tick

2. "If ( tick_now > tick_prev)" neads to be completed by an ELSE statement "cnt=0;" in order to detect 3 sequential rises.

3. "tick_prev = tick_now;" should be placed outside the "if(cnt=3)" condition

Just an advice : a rise of 3 consecutive ticks is absolutely not a signal for further increase. I hope your EA will get more sophisticated in near future.

Another advice : try and read the documentation before posting and once you post, explain what you are aiming at.

regards

 

Good day to monpseudo88 and everyone who read this:


Thanks for your advice, monpseudo88. I am new to EA, just trying to create my own 1st EA. I will take notes of what you have advice me. Thanks a lot.


My programming objective:

1.Detect rise of 3 consecutive ticks.

2. Once 3 consecutive ticks detected, Run the ordersend command.

3. Erase the cnt (counter) to Zero and start the detect procedure again. ---- \ i do not know how to erase the cnt (counter), so that it can start counting again. Please advice.


Here is my corrected program, please kindly advice:


extern double tick_now, tick_prev=0;
int cnt=0;

int ticket=0;


int start ()
{
tick_now = Bid;
if ( tick_now > tick_prev) // If tick_now > than previous tick, cnt increase 1.
{
cnt++;
}

else
{
cnt=0; // or else, cnt still remain zero.
}

if(cnt==3) // when cnt = 3 (consecutive 3 rise), Long order will be send.

{
ticket = OrderSend(Symbol(),OP_BUY,lot,Ask,2,0,0,"My LONG order",0,0,Green);
}

tick_prev = tick_now; // tick_now become ticket previous. Notes: Am i locate this command at the right location or.... Please advice.
return(0);

}


Appreciate any comment. Have a great day ahead.


regards,

miki

Reason: