Anticipate the position opening?

 
Hi everyone,

it's like one year that I'm studying trading and automated trading.

I'm trying to figure out different trading strategies in MQL4 using Metatrader4, manly focusing on forex scalping.

I have a limitation on every algorithm that I create, the trade are open some pips too late, probably due to my bad programming idea. someone have a tips to anticipate the position opening?

in the example, it's a rudimental doji trading.

  if (  (iClose(NULL, 0, 5) < iOpen(NULL, 0, 5)) &&
    (iClose(NULL, 0, 4) < iOpen(NULL, 0, 4)) &&
       (iClose(NULL, 0, 3) < iOpen(NULL, 0, 3)) &&
       (iClose(NULL, 0, 2) < iOpen(NULL, 0, 2)) &&
       (iClose(NULL, 0, 4) >= iClose(NULL, 0, 3)) &&
       (iClose(NULL, 0, 3) >= iClose(NULL, 0, 2)) &&
       
            (iClose(NULL,0,1) - iOpen(NULL,0,1)) >= 0 * Point &&
            (iClose(NULL,0,1) - iOpen(NULL,0,1)) < VolumeDoji * Point &&
            iLow(NULL,0,1) > iOpen(NULL,0,1) - 10 * Point &&
            iLow(NULL,0,1) < iOpen(NULL,0,1) - 1 * Point &&
            iHigh(NULL,0,1) < iClose(NULL,0,1) + 10 * Point &&
            iHigh(NULL,0,1) > iClose(NULL,0,1) + 1 * Point
        )
        {                                          
            Opn_B = true;
        }
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Please don't attach images of code. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

 
Federico Libra: [..] the trade are open some pips too late [..]

If they are only a few pips and not an entire bar, it sounds to be the spread. But without a minimal example that can be tested, I can only guess.

 
dcstoyanov #:

If they are only a few pips and not an entire bar, it sounds to be the spread. But without a minimal example that can be tested, I can only guess.

thanks for your comment. do you want to see the entire code? anyway yes sometimes it's an entire bar
 
Federico Libra #: ? anyway yes sometimes it's an entire bar

You are looking at past bars; it's always going to be an entire bar.