Download MetaTrader 5

EA Code Fix

To add comments, please log in or register
MQL5 Cloud Network speeds up calculations. Try it!
ghost_jc
663
ghost_jc 2015.04.02 16:48 

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 

Drazen Penic
2544
Drazen Penic 2015.04.02 17:52  
  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.
ghost_jc
663
ghost_jc 2015.04.03 01:41  

Hi Drazan64,

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

regards,

John 

To add comments, please log in or register