EA does not place SELL or CLOSE orders

 

Hi

I am learning how to program expert advisors. So far, it worked quite well.

Last week, I started to create programs including orders.


First I wanted to test my program in the strategy tester which is included in MT4. I could place Buy orders including SL and TP which worked fine. But the program also included Sell orders and OrderClose commands which both did not work.

 

To find the root cause, I created a small program only including a Buy order with SL and TP. First I ran that program with the strategy tester and set the SL and TP to a distance never to be reached in the specified timeframe. During the test, the EA placed the buy order at the beginning and that order was closed after the test, then I modified the SL an TP to be reached, which also worked. Following you can find my simple program:

bool flagOrder = true;
int ticket;
//+------------------------------------------------------------------+
int OnInit()
  {

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if(flagOrder)
     {
      ticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-1000*Point,Bid+1000*Point);
      flagOrder = false;
     }
  }
 

Afterwards I modified the program to place Sell orders. Which did not work at all in the strategy tester. It did not open any orders. Could you please help me to solve this issue? I have already spent many hours trying to solve this problem, googled it and read in the manual. But I could not find a solution. I also tried these small programs in my testaccount ( not the strategy tester), but I got the same result. The modification I made was only to the OrderSend command according to the following line:

      ticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,3,Ask-1000*Point,Ask+1000*Point);

For the strategy tester I used the following settings:

Symbol: EURUSD

Period: M15

Spread: 30

Model: every tick

Optimization: off

Timeframe: 2018.01.04 to 2018.01.05

 

For the EA I used the following settingsö.-:

Balance: 10000 USD

Positions: Long&Short

 

Best regards

Dominik Gächter

 
gaecdom:

Hi

I am learning how to program expert advisors. So far, it worked quite well.

Last week, I started to create programs including orders.


First I wanted to test my program in the strategy tester which is included in MT4. I could place Buy orders including SL and TP which worked fine. But the program also included Sell orders and OrderClose commands which both did not work.

 

To find the root cause, I created a small program only including a Buy order with SL and TP. First I ran that program with the strategy tester and set the SL and TP to a distance never to be reached in the specified timeframe. During the test, the EA placed the buy order at the beginning and that order was closed after the test, then I modified the SL an TP to be reached, which also worked. Following you can find my simple program:

 

Afterwards I modified the program to place Sell orders. Which did not work at all in the strategy tester. It did not open any orders. Could you please help me to solve this issue? I have already spent many hours trying to solve this problem, googled it and read in the manual. But I could not find a solution. I also tried these small programs in my testaccount ( not the strategy tester), but I got the same result. The modification I made was only to the OrderSend command according to the following line:

For the strategy tester I used the following settings:

Symbol: EURUSD

Period: M15

Spread: 30

Model: every tick

Optimization: off

Timeframe: 2018.01.04 to 2018.01.05

 

For the EA I used the following settingsö.-:

Balance: 10000 USD

Positions: Long&Short

 

Best regards

Dominik Gächter

Your stop loss and take profit are not good when you try to open sell - correct that and it will work
 
Mladen Rakic:
Your stop loss and take profit are not good when you try to open sell - correct that and it will work

Hi Mladen Rakic

Thank you for your reply.

This was exactly the problem. Now I also solved the problem with the CloseOrder. I mixed up Bid and Ask in the command.

I have spent at least 2 hours on this issue :(

Reason: