buy and sell order

 

Hi,


I have written a small expert advisor.

If the price is above the moving average you buy and if the price is below moving average you sell.

But it only sells... what am I doing wrong?

If I remove the code to sell it only buys.

Help!


//+------------------------------------------------------------------+
//|                                                       errors.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


int order;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---


 double movingAverage = iMA(NULL,0,15,0,MODE_SMA, PRICE_MEDIAN,0);
 
   double currentPrice = Open[0];


 if((currentPrice > movingAverage))
   {
      order = OrderSend(NULL, OP_BUY,0.1,Ask,0,NULL,NULL,NULL,0,0,NULL );
   }
   
 
   if(currentPrice < movingAverage)
   {
       order = OrderSend(NULL, OP_SELL,0.1,Bid,0,NULL,NULL,NULL,0,0,NULL );
   }
   
  }
//+------------------------------------------------------------------+


If you look at the picture below, in the results I only have sell trades, no buy trades. what is happening?


https://imgur.com/a/8SAyJgn



If I remove the OrderSend and if statement for sell, I get only buys...

Imgur
Imgur
  • 2019.02.03
  • imgur.com
Post with 0 views.
 
samsungj4:

Hi,


I have written a small expert advisor.

If the price is above the moving average you buy and if the price is below moving average you sell.

But it only sells... what am I doing wrong?

If I remove the code to sell it only buys.

Help!



If you look at the picture below, in the results I only have sell trades, no buy trades. what is happening?


https://imgur.com/a/8SAyJgn



If I remove the OrderSend and if statement for sell, I get only buys...

What is the value of order when unsuccessful... and try a print of GetLastError() ?
Reason: