Download MetaTrader 5
To add comments, please log in or register
We have launched Spanish and Portuguese versions of the website. Try them!
Jhonson
35
Jhonson 2014.03.21 10:12 

i wirte function BUY SELL with MA7 and MA 21.

if MA7 < MA21 ==> sell

it worked but when have close ordered. ma7 < ma21 it is continue order

i want when MA7 < MA21 ==> sell and it is only a order until MA7 > MA21

who can help me. thanks

int CountTrades()
  {
   int count=0;
   int trade;
   for(trade=OrdersTotal()-1;trade>=0;trade--)
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
           {
            if(OrderType()==OP_SELL || OrderType()==OP_BUY)
               count++;
           }
         else
            Print("Error selecting orders in CountTrades() function : "+GetLastError());
        }
     }
   return(count);
}
void AddSell()
{
     int ticket ;
     int    myTrades=CountTrades();
double prema7 = iMA(NULL,0, 7,0,MODE_SMA,PRICE_CLOSE,1),
       prema21 = iMA(NULL,0, 21,0,MODE_SMA,PRICE_CLOSE,1),
       wasma7 = iMA(NULL,0, 7,0,MODE_SMA,PRICE_CLOSE,2),
       wasma21 = iMA(NULL,0, 21,0,MODE_SMA,PRICE_CLOSE,2);
bool  wasbool1 = prema7 < prema21,
      wasbool2 =  wasma7 < wasma21
bool   tradingHours  = (Hour() >=  Start_Time && Hour() <= Finish_Time);

  //------
      if(!tradingHours) return(0);
      if(myTrades<1 && tradingHours )
      {
      if ( wasbool1 != wasbool2 )
       { 
         ticket = OrderSend(Symbol(),OP_SELL, S_lot, BID,Slippage,BID-S_SL*point, BID+S_TP*point,"SELL one ",MagicNumber,0, Green);
       }
      }
}
qjol
3243
qjol 2014.03.21 11:51  

general idea

bool MA7GreaterMA21;
bool MA7SmallerMA21;

if(MA7 > MA21)
   MA7GreaterMA21 = true;

if (MA7 < MA21 && MA7GreaterMA21)
   {
   MA7GreaterMA21 = false;
   ticket = OrderSend(....);
   }
whroeder1
13627
whroeder1 2014.03.21 13:04  
axbc: i want when MA7 < MA21 ==> sell and it is only a order until MA7 > MA21
void CloseAllOrders(int op){ ...
void OpenAnOrder(int op){ ...
:
if(MA7 > MA21)              CloseAllOrders(OP_SELL);
else if(CountTrades() == 0) OpenAnOrder(OP_SELL);
Keith Watford
Moderator
7958
Keith Watford 2014.03.21 13:32  
  int CountTrades()
  {
   int count=0;
   int trade;
   for(trade=OrdersTotal()-1;trade>=0;trade--)
     {
      if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
           {
            if(OrderType()==OP_SELL || OrderType()==OP_BUY)
               count++;
           }
         else  //This else does not refer to OrderSelect
               // it refers to if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
            Print("Error selecting orders in CountTrades() function : "+GetLastError());
        }
     }
   return(count);
    // There is no closing } after return
/
To add comments, please log in or register