//+------------------------------------------------------------------+
//|                                                Sell Order1.1.mq4 |
//|                                       Copyright © 2008, Rob Rice |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Rob Rice"
#property link      ""

#include <stdlib.mqh>
#include <WinUser32.mqh>

#property show_inputs

extern     int TakeProfit = 100,
               StopLoss = 50;

extern double  Lots = 0.2;

extern bool    MM = true;
extern double  PercentRisk = 2;

extern bool    Confirm = true;

extern int     Slippage = 3;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   if (MM)
      {
      double PipValue = MarketInfo(Symbol(), MODE_TICKVALUE); 
      Lots = NormalizeDouble((AccountBalance() * PercentRisk / StopLoss / PipValue / 100.0),2);
      }
      Print ("PipValue = ",PipValue);
      Print ("Lots = ",Lots);
            
      double tpPrice = Bid - TakeProfit * Point;
      if (TakeProfit == 0) tpPrice = 0;
      double slPrice = Bid + StopLoss * Point;
      if (StopLoss == 0) slPrice = 0;
      
      if(Confirm)
         {
         string LOTS = DoubleToStr(Lots,2);
         if(MessageBox("Do you really want to SELL "+LOTS+" "+Symbol()+" at BID price?    ",
                 "Script",MB_YESNO|MB_ICONQUESTION)!=IDYES) return(1);
         }
      
      OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, slPrice, tpPrice);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+