First EA not live trading - but works in strategy tester?

 

I finally got around to getting my first EA done, but I've come to a grinding halt, as it does not live trade.

The attached EA is a simple one (of course I thought I'd do something simple for my first EA....) It basically checks if the price has moved outside of an EMA envelope. If it has moved above the higher envelope then enter into a sell, if it moves lower than the lower envelope enter into a buy. When the price moves back to the center EMA close the trade. Only one trade allowed on the currency at a time.

Running it on the strategy tester shows the trades happening. Leaving it live trading for a few days, and seeing the bars happen that should have triggered trades, very similar to the strategy tester bars, and nothing happens. I searched high and dry to try and figure it out. I even tightened the value of the envelopes so that the price would definitely move outside of them, and it still did not trade, but just made the results worse in the strategy tester!!!!

So I am guessing there must be some thing which I should know that I'm not doing.

Can you guys please pull my code apart and tell me the things I should be doing.

Cheers

Colin

Files:
envxover.mq4  6 kb
 

I assume you mean live on the demo account but works in the tester (also demo account.)

You do have a smiley face in the upper right.

I see nothing wrong. (Won't work on a ECN broker where you have to open first and then set stops.)

If it is actually trying to open trades the journal would have an message from the print, so I suggest printing values of your open condition logic.

 

Yeah its all Demo account stuff, and yes I've got the smiley face.

Hey I'm glad that you see nothing wrong in a sense.

But now I wonder, I guess my broker (IC Markets, Australia) is an ECN, as when you manual trade you have to set the SL after entering. I have checked the journal and nothing appears in there with errors to do with entering trades, it just does not enter, so maybe MT4 is not showing up some error from the server with IC Markets?

The reason the code has the comment showing the envelope values and MA value was just to diagnose problems, and make sure it was entering into the section to check for a valid trade, and I could see when it should enter.

Much appreciated for you taking a look and idea.

 

Again, if it was an ECN problem, there would be a journal entry from the if() print()

The problem must be else where. Add a print to the beginning start() so you know it's running and show values

 

Hey,

Not sure why I did not get a journal entry, I've checked this myself and asked a few friends as well, who can also confirm the same thing? One with Go-markets, another with GFT. No journal entries????? The orders just fall into a black hole.

Anyway I changed the code to;

 SellTicket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, UseSlippage, 0, 0, "Sell Order", MagicNumber,0, Red);
            if (SellTicket < 0)
            {
               Print("OrderSend failed with error #",GetLastError());
               SellTicket=0;
            }
            else     //now enter in the SL and TP via OrderModify to make compatible with ECN broker
            {
               if (OrderSelect(SellTicket, SELECT_BY_TICKET))
               {
                  if (!OrderModify(SellTicket, Bid, SellStopLoss, SellTP, 0, Red))
                     Print("Error modifying order");
               }
            }

And it all works well in strategy and the live trading. Saw your post elsewhere on talking to an ECN and it was not much to change it.

Reason: