//+------------------------------------------------------------------+
//|                           Copyright 2005, Gordago Software Corp. |
//|                                          http://www.gordago.com/ |
//+------------------------------------------------------------------+


#property copyright "Copyright 2005, Gordago Software Corp."
#property link      "http://www.gordago.com"

extern double lTakeProfit = 10;
extern double sTakeProfit = 10;
extern double Lots = 0.1;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start(){
   int cnt, ticket;
   if(Bars<100){
      Print("bars less than 100");
      return(0);
   }
   if(lTakeProfit<10){
      Print("TakeProfit less than 10");
      return(0);
   }
   if(sTakeProfit<10){
      Print("TakeProfit less than 10");
      return(0);
   }

   double diMA0=iMA(NULL,5,13,0,MODE_EMA,PRICE_CLOSE,0);
   double diMA1=iMA(NULL,5,34,0,MODE_EMA,PRICE_CLOSE,0);
   double diRSI2=iRSI(NULL,5,21,PRICE_CLOSE,0);
   double diOpen3=iOpen(NULL,1,0);
   double diSAR4=iSAR(NULL,1,0.05,0.2,0);
   double diMA5=iMA(NULL,5,13,0,MODE_EMA,PRICE_CLOSE,0);
   double diMA6=iMA(NULL,5,13,0,MODE_EMA,PRICE_CLOSE,1);
   double diMA7=iMA(NULL,5,13,0,MODE_EMA,PRICE_CLOSE,0);
   double diMA8=iMA(NULL,5,34,0,MODE_EMA,PRICE_CLOSE,0);
   double diRSI9=iRSI(NULL,5,21,PRICE_CLOSE,0);
   double diOpen10=iOpen(NULL,1,0);
   double diSAR11=iSAR(NULL,1,0.05,0.2,0);
   double diMA12=iMA(NULL,5,13,0,MODE_EMA,PRICE_CLOSE,0);
   double diMA13=iMA(NULL,5,13,0,MODE_EMA,PRICE_CLOSE,1);

   int total=OrdersTotal();
   if(total<1){
      if(AccountFreeMargin()<(1000*Lots)){
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);
      }

      if ((diMA0>diMA1 && diRSI2>50 && diOpen3>diSAR4 && diMA5>diMA6)){
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+lTakeProfit*Point, "gordago simple",16384,0,Green);
         if(ticket>0){
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
         }
         else Print("Error opening BUY order : ",GetLastError());
         return(0);
      }

      if ((diMA7<diMA8 && diRSI9<50 && diOpen10<diSAR11 && diMA12<diMA13)){
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-sTakeProfit*Point,"gordago sample",16384,0,Red);
         if(ticket>0) {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
         }
         else Print("Error opening SELL order : ",GetLastError());
         return(0);
      }
   }
   for(cnt=0;cnt<total;cnt++) {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) {
         if(OrderType()==OP_BUY){
         }else{
         }
      }
   }
}