Learning curve

 

Good day.


Please help.

The code doesn't give a Alert for "Signal1" or "Signal2"

Dont know what I am doing wrong:


void OnTick()

  {

  if(!CheckIfOpenOrdersByMagicNB(111))

    {

 int Orderbuy = OrderSend(_Symbol,OP_BUY,0.01,Ask,10,Ask-(1000*_Point),Ask+(200*_Point),NULL,111);

 }

    

    if(OrderSelect(Orderbuy, SELECT_BY_TICKET)==true)

    {

     double y = OrderOpenPrice();

     double a = y-(10*_Point);

     double b = y+(10*_Point);

    

     

     if (Ask<=a)

     {

      Alert("signal 1");

     }

     

     if (Ask>=b)

     {

      Alert("Signal 2");

     }

}

}
 
LouisBreet:

Good day.


Please help.

The code doesn't give a Alert for "Signal1" or "Signal2"

Dont know what I am doing wrong:


Of course it doesn't alert.

     double y = OrderOpenPrice();
     double a = y-(10*_Point);

y should be the same as Ask

So a is < Ask.  Ask can't be >a

if (Ask<=a)

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
LouisBreet:

Good day.


Please help.

The code doesn't give a Alert for "Signal1" or "Signal2"

Dont know what I am doing wrong:


I think it's more complex than that.

This code happens OnTick. If the condition is met you open a new order and capture the ticket number.

Then you get the open price for that order and compare +/- 10 points against the current Ask price.

Immediately after opening the order the open price and ask price are the same so the tests for +/- 10 points will both fail, as expected.

What you are looking for is to raise an alert later when the price has moved by more than 10 points,    ...   but ...

On the next entry to OnTick the variable Orderbuy will no longer hold the ticket number and the OrderSelect will fail without a valid number.

Try, at the beginning of OnTick

static int Orderbuy = 0;

then just remove the int type declaration from the order line and the function will remember the last value set for Orderbuy.

 
LouisBreet:

Do not double post!

I have deleted your duplicated topic!

 
Keith Watford:

Do not double post!

I have deleted your duplicated topic!

Apologies Keith.


I couldn't find the original post and thought it didn't submit it correctly.


Kind regards.

 
Arthur Joseph Mcalister:

I think it's more complex than that.

This code happens OnTick. If the condition is met you open a new order and capture the ticket number.

Then you get the open price for that order and compare +/- 10 points against the current Ask price.

Immediately after opening the order the open price and ask price are the same so the tests for +/- 10 points will both fail, as expected.

What you are looking for is to raise an alert later when the price has moved by more than 10 points,    ...   but ...

On the next entry to OnTick the variable Orderbuy will no longer hold the ticket number and the OrderSelect will fail without a valid number.

Try, at the beginning of OnTick

then just remove the int type declaration from the order line and the function will remember the last value set for Orderbuy.

Thanks Arthur.


Complete novice at this point so thanks for the help and actually taking the time to teach me something. 


I am not 100% sure what to do exactly, but I am going to take what you said and work on it.


Kind regards.

Reason: