The == operand.

 

Hi, can anyone help? 


This seems a simple task but it does not work. I want to start a buy process when Ask or Bid crosses a Bollinger Band for example;

if(Ask==UpperBand)    // UpperBand is the iBands fuction
{

Then if ask is equal to Upperband then open trade etc .  

The problem is that the double equal  == operand does not work. When Ask is equal to Upper band the code ignores this . I tried this and it works  <=    and this does also   >=   does but not ==.

I want to trade to open at precisely the point that the market crosses the band.

Many thanks for any possible answers

 Chris 

 
ChrisSouthwood:

Hi, can anyone help? 


This seems a simple task but it does not work. I want to start a buy process when Ask or Bid crosses a Bollinger Band for example;

if(Ask==UpperBand)    // UpperBand is the iBands fuction
{

Then if ask is equal to Upperband then open trade etc .  

The problem is that the double equal  == operand does not work. When Ask is equal to Upper band the code ignores this . I tried this and it works  <=    and this does also   >=   does but not ==.

I want to trade to open at precisely the point that the market crosses the band.

Price may never be at exactly the price that your band is at  and even if it is it may not be == due to the way that double values work, you need to read all of this thread:  Can price != price ?
 

Yes thank you very much for your time to reply and the excellent links.

From what I understand from reading these there will be no time that the value of Ask or Bid will ever match preciously the value attributed to the variable of the iband function.
I understand now. Just got to get my head around writing code that will execute a function when those two figures are (approximately) equal and not just more or less than.

This part of my program is to generate a buy order when the market crosses the iband hoping that the market will reverse as a basic Bollinger strategy.  
Should they market continue in an adverse direction I don't want that trade to be opened then stopped-out then the next trade started because the code specifies that the ea buys when the ask or put is more than the iband value.

That is why I was seeking only the precise moment the market crosses the band or when it re=crosses when it reverses direction.

Some thought

Thanks again

 Chris 

 
ChrisSouthwood:

Yes thank you very much for your time to reply and the excellent links.

From what I understand from reading these there will be no time that the value of Ask or Bid will ever match preciously the value attributed to the variable of the iband function.
I understand now. Just got to get my head around writing code that will execute a function when those two figures are (approximately) equal and not just more or less than.

This part of my program is to generate a buy order when the market crosses the iband hoping that the market will reverse as a basic Bollinger strategy.  
Should they market continue in an adverse direction I don't want that trade to be opened then stopped-out then the next trade started because the code specifies that the ea buys when the ask or put is more than the iband value.

That is why I was seeking only the precise moment the market crosses the band or when it re=crosses when it reverses direction.

Some thought

How would you trade this manually ?  write code to do the same . . . 
 

Manually what I would do is watch the chart and trade as soon as it crosses the band. If this turns to a loss I would not open another trade while the market is still rising (I am going short) What, as discussed, is not happening with my EA is that the, say, Ask is not recognized to equal the iban when that position is reached with the operand == only after with >=. ie more than the iband.  Then I could take several losses on stop-loss because of the > bit.

So I will try this. Adding 0.000001 to the iband ensuring that the trade is opened very close to the band and then not above it      if(Ask>=UpperBand&&Ask<=UpperrBand+0.00001) ...

regards, Chris 

 
ChrisSouthwood:

 

Manually what I would do is watch the chart and trade as soon as it crosses the band. If this turns to a loss I would not open another trade while the market is still rising (I am going short) What, as discussed, is not happening with my EA is that the, say, Ask is not recognized to equal the iban when that position is reached with the operand == only after with >=. ie more than the iband.  Then I could take several losses on stop-loss because of the > bit.

So I will try this. Adding 0.000001 to the iband ensuring that the trade is opened very close to the band and then not above it      if(Ask>=UpperBand&&Ask<=UpperrBand+0.00001) ...

regards, Chris 

What you can't do is get the iband value between bars,  so if the cross happens between bars Bid will never == iband  ,  Bid because that is what you see on the chart,  the chart is drawn by Bid price.  Don't use 0.00001  use Point instead,  then it will be more valid for all instruments.
 

Thank you,

More thought

Chris 

Reason: