Making an EA that will open trades on an interval from previous closed bar?

 

Hello everyone! I am trying to create an EA based on a simple formula I read on the internet. Some days it appears to be profitable, some days not so much. Either way, I want to create an EA because it's easier to let the computer open trades instantly than typing it all up manually.

Here is the basic formula that I am using (http://forexsoho.com/daily-95-pips-from-the-forex-market.html):

EXECUTING AND PLACING THE TRADES
1. Determine at what time your broker closes its daily candle as this varies from broker to broker. After you have done so, bookmark this time as you will be placing your trades at this exact time everyday.

2. After the new daily bar opens, place 6 pending orders on the PREVIOUS daily candle. 3 Pending buy orders above the High which should be as follows:

Buy/Long Orders:
i. #1 – Entry = HIGH+5pips, Take Profit=15pips, S/L=30pips
ii. #2 – Entry = HIGH+5pips, Take Profit=30pips, S/L=30pips
iii. #3 – Entry = HIGH+5pips, Take Profit=50pips, S/L=30pips

And 3 pending sell orders below the daily LOW as follows:

Sell/Short Orders:
i. #1 – Entry = LOW-5pips, Take Profit=15pips, S/L=30pips
ii. #2 – Entry = LOW-5pips, Take Profit=30pips, S/L=30pips

iii. #3 – Entry = LOW-5pips, Take Profit=50pips, S/L=30pips

Essentially it gets a simple 95 pips a day, 0 pips, or negative pips. I want to forward test this theory (and backtest too) and see how well it really works.

What this EA will need:

1. A timer or time indicator of GMT and server time and your time on real-time would be nice (refer to b-clock.mq4 in other threads)

2. The ability to know when the next day starts and also read the high and low of the previous day (should be easy on D1 time frame)

3. An awesome feature would be that it trades all pairs (or ones the user chooses) with being placed on only one graph (similar to how CCFp EA works)

4. Be able to make 3 levels of pending buy trades (5 pips above prev. day hi) and 3 levels of pending sell trades (5 pips below prev. day lo)

5. I bet I could incorporate hidden tp/sl into it without much hassle (I used to have a template, I would have to find again or help?)

So where do I start? I have pretty much all the tools I need, but I don't know how to go about making an EA that will say "open this time with these perimeters" kind of a thing :(

I attached my first stab at creating the EA which opens a trade if the current high is above the previous high for a buy and if the current low is lower than the previous low (D1 chart) but it opens tons of trades lol! Help to expand the EA to its desired potential above would be great, thanks!

Files:
 
I expect that a search for 'breakout mql4 ea' would find something that would serve as a starting point
 
  1. 1. A timer or time indicator of GMT and server time and your time on real-time would be nice (refer to b-clock.mq4 in other threads)
    extern int      Srvr.To.UTC.Hours           =   0;
    
    Comment(TimeToStr(TimeGMT(), TIME_MINUTES|TIME_SECONDS), " UTC");
    
    datetime TimeGMT(){ // TimeCurrent to GMT
        datetime    now = TimeCurrent();
        return (now + Srvr.To.UTC.Hours*3600);
    }
    

  2. 2. The ability to know when the next day starts and also read the high and low of the previous day (should be easy on D1 time frame)
    On a D1 chart simply wait for Time[0] to change. On a H1 chart wait for TimeHour(TimeGMT()) to change to zero.
  3. 3. An awesome feature would be that it trades all pairs (or ones the user chooses) with being placed on only one graph (similar to how CCFp EA works)
    Write the EA to trade the current chart pair. Attach it to multiple charts.
  4. 4. Be able to make 3 levels of pending buy trades (5 pips above prev. day hi) and 3 levels of pending sell trades (5 pips below prev. day lo)
    No slaves here, learn to code or pay someone.
  5. 5. I bet I could incorporate hidden tp/sl into it without much hassle (I used to have a template, I would have to find again or help?)
    Why bother.
  6. So where do I start? I have pretty much all the tools I need, but I don't know how to go about making an EA that will say "open this time with these perimeters" kind of a thing :(
    Make up your mind, either you have the tools and know how to code or you don't.
  7. I attached my first stab at creating the EA which opens a trade if the current high is above the previous high for a buy and if the current low is lower than the previous low (D1 chart) but it opens tons of trades lol! Help to expand the EA to its desired potential above would be great, thanks!
    1.    for (int i = 0; i < Total; i ++) {
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
      
      Total is never set. You MUST count down when closing/deleting in the presense of multiple orders/multiple charts. Always test return codes
          for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
              OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
          &&  OrderMagicNumber()  == magic.number             // my magic number
          &&  OrderSymbol()       == Symbol() ){              // and my pair.
      

    2. if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      
      Bars is unreliable (once you reach maximum bars on chart it won't change.) Volume is unreliable.
      int     start(){
          static datetime Time0;
          if (Time0 != Time[0]){  Time0 = Time[0]; ...
      

    3.          if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else S...
      Adjust TP, SL, and slippage for 5 digit brokers. OrderSend with no TP, SL and then set them for ECN brokers
      //++++ These are adjusted for 5 digit brokers.
      double  pips2points,    // slippage  3 pips    3=points    30=points
              pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
      int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
      int     init(){
          if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
          } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
          // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl