EA Code Fix

 

hi all,

If there are anyone out who could help me, it be much appreciated.

I am having some issue with my current code. What i am trying to do here, is to have a condition that trigger a buy or sell, when the differences between 2 points equals to 10 (for example) . actual example, the differences between point A and point B is 10. I want to trigger a buy/sell only when the differences is 10 pips.

  

I am currently using on the following code:

=========================================

    if (Time[0] > lastBuyTime && Low[0] < AngularResistance && Close[0] > AngularResistance)
    {
        if (DoubleToStr(dif4GreenLine, Digits) == DoubleToStr(GreenLineDifPips,Digits))
        {            
            Print("HighPoint[0]:",HighPoint[0], " HighPoint[1]:",HighPoint[1], " dif4GreenLine:",dif4GreenLine);
            Alert("The difference between Point A and B is ", DoubleToStr(dif4GreenLine, Digits), " , which is more then specified " + DoubleToStr(GreenLineDifPips/digitFactor, 2) + " pips");
        }
        else
        {
            Print("HighPoint[0]:",HighPoint[0], " HighPoint[1]:",HighPoint[1], " dif4GreenLine: ",dif4GreenLine, " GreenLineDifPips: ",GreenLineDifPips*Point, " GreenLineDifPips: ", DoubleToStr(GreenLineDifPips/digitFactor, 2));
            if (DoOpenOrder(LONG, OrderSize, StopLossPips, TakeProfitPips, Blue) > 0)
            {
                lastBuyTime = Time[0];
            }
        }
    } 

========================================= 

i would like to know if i am using the right code (marked in bold) to trigger the buy/sell. At the moment it is allowing trades only when the differences is bigger than the specified differences.

Any help will be much appreciated. 

Regards,
John 

 
  1. You should not compare prices for equality because:
    • prices can change for more than 1 point and at one moment you have price less than your line and next tick can have prices bigger than your line
    • due to internal number representation, prices can differ on decimals after declared number of digits

  2. You should use "greater than or equal (>=)",  "greater than (>)", "less than or equal (<=)",  "less than (<)"  operators for comparing prices (depending on your algorithm)

  3. You should compare double values, you should NOT convert numbers to strings and then compare strings.
 

Hi Drazan64,

Many thanks for the info. I will try it on my code. much appreciated.

regards,

John