//+------------------------------------------------------------------+
//|                                              MT5_D_L_L=const.mq5 |
//|                                                         futurama |
//|  http://www.forex-nawigator.biz/dyskusje/viewtopic.php?t=21280&s |
//+------------------------------------------------------------------+
#property copyright "futurama"
#property link      "http://www.forex-nawigator.biz/dyskusje/viewtopic.php?t=21280&s"
#property version   "1.00"
#include <Trade\DealInfo.mqh>



MqlTradeRequest trReq;
MqlTradeResult trRez;

 static double ask1, bid1, io;
  double na, nb, ca, ca2;
int sl;
int tp;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   trReq.action=TRADE_ACTION_DEAL;
   trReq.symbol=Symbol();                 // Trade symbol
   trReq.volume=0.01;                      // Requested volume for a deal in lots
  


   if(_Digits==5)
     {
      sl*=10;
      tp*=10;
     }
             
   // Print("3uuu");

   return(0);
  }
  
  
 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
     MqlTick tick; //variable for tick info
   
 
  
  
   
 
   
  //
   if(!SymbolInfoTick(Symbol(),tick))
     {
      //Print("Failed to get Symbol info!");
      //return;
     }
if(PositionSelect(Symbol())==true)
{
//double Volume=OrderGetDouble(ORDER_PRICE_OPEN);
//Print(Volume);

}
            
      
      
      
 //   bool  RefreshRates();
     
      
    
   //PositionSelect(_Symbol);
   
   if(PositionsTotal() == 1)
   {
   
   if(trRez.price+10*_Point >= tick.ask)
   {
   
  // Print(PositionsTotal());
    //Print(ask1," <= ",tick.ask+20*_Point);
    trReq.price   = tick.ask;
    trReq.type    = ORDER_TYPE_SELL;
    trReq.volume  = 0.01;
    OrderSend(trReq,trRez);
    // ask1 = tick.ask;  
     //bid1 = tick.bid;
    //io = 1;
   }
   
   if(trRez.price-20*_Point <= tick.ask)
   {
    //Print(ask1," <= ",tick.ask+20*_Point);
    trReq.price   = tick.bid;
    trReq.type    = ORDER_TYPE_BUY;
    trReq.volume  = PositionGetDouble(POSITION_VOLUME);
    OrderSend(trReq,trRez);
    io = 1;
   }
   //Print(PositionsTotal());
   
   
   
   }
   
   
  // Print(ask1-10*_Point >= tick.ask);
     if(PositionsTotal() == 0)
        { 
        io = 0;
       //  ask1 = 1;  
         //bid1 = 1;

         trReq.price=tick.ask;                   // SymbolInfoDouble(NULL,SYMBOL_ASK);
           trReq.volume  = 0.01;           // Take Profit level of the order
         trReq.type=ORDER_TYPE_SELL;              // Order type
         
         
        // ask1 = tick.ask;  
         //bid1 = tick.bid;
         OrderSend(trReq,trRez);
         //io = 1;
        }
   
   
   
   //  if(OrdersTotal()>0)
  // {
  // trReq.price=tick.ask; 
   //bid1 = tick.bid;
   
  // }
   //Print("1 io = ", io);
   //Print("2 ask1 = ", ask1);
  // Print();
   // }
   //Print("1 io = ", io);
   //Print("2 ask1 = ", ask1);
   //Print("4 vol = ", PositionGetDouble(POSITION_VOLUME));
   //Print(trRez.volume);
  // "4 vol = ", PositionGetDouble(POSITION_VOLUME)                          ,
   //"//      ", DoubleToString(((tick.ask - trRez.price)*10000)-1,4)        ,
   //"//      ", trRez.price                                                 ,
   //"//      ", tick.ask 
  // );
  
 // refresh();
 //bool RefreshRates = a;
 //a;
 /*
    double ask11 =SymbolInfoDouble(Symbol(),SYMBOL_ASK);

    
      ObjectDelete      (0,"0");
      ObjectCreate      (0,"0",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"0",OBJPROP_XDISTANCE,60);
      ObjectSetInteger  (0,"0",OBJPROP_YDISTANCE,30);
      ObjectSetInteger  (0,"0",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"0",OBJPROP_TEXT,DoubleToString(((tick.ask - trRez.price)*10000),0));
      ObjectSetString   (0,"0",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"0",OBJPROP_FONTSIZE,20);
     // ObjectSetInteger  (0,"0",OBJPROP_SELECTABLE,true);
     // ChartRedraw(0);                                      
   //  }
    // int window=1;
    if(io == 1)
    {
     ObjectDelete      (0,"1a1");
      ObjectCreate      (0,"1a1",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"1a1",OBJPROP_XDISTANCE,00);
      ObjectSetInteger  (0,"1a1",OBJPROP_YDISTANCE,60);
      ObjectSetInteger  (0,"1a1",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"1a1",OBJPROP_TEXT,"p= ");
      ObjectSetString   (0,"1a1",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"1a1",OBJPROP_FONTSIZE,20);
          ObjectDelete      (0,"11a");
      ObjectCreate      (0,"11a",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"11a",OBJPROP_XDISTANCE,60);
      ObjectSetInteger  (0,"11a",OBJPROP_YDISTANCE,60);
      ObjectSetInteger  (0,"11a",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"11a",OBJPROP_TEXT,DoubleToString(PositionGetDouble(POSITION_VOLUME),2));
      ObjectSetString   (0,"11a",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"11a",OBJPROP_FONTSIZE,20);
      
      
    
    
      ObjectDelete      (0,"1a");
      ObjectCreate      (0,"1a",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"1a",OBJPROP_XDISTANCE,00);
      ObjectSetInteger  (0,"1a",OBJPROP_YDISTANCE,90);
      ObjectSetInteger  (0,"1a",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"1a",OBJPROP_TEXT,"p= ");
      ObjectSetString   (0,"1a",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"1a",OBJPROP_FONTSIZE,20);
          ObjectDelete      (0,"1");
      ObjectCreate      (0,"1",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"1",OBJPROP_XDISTANCE,60);
      ObjectSetInteger  (0,"1",OBJPROP_YDISTANCE,90);
      ObjectSetInteger  (0,"1",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"1",OBJPROP_TEXT,DoubleToString(PositionGetDouble(POSITION_PROFIT),2));
      ObjectSetString   (0,"1",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"1",OBJPROP_FONTSIZE,20);
      }
//ChartRedraw(0);     
      ObjectDelete      (0,"2");
      ObjectCreate      (0,"2",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"2",OBJPROP_XDISTANCE,60);
      ObjectSetInteger  (0,"2",OBJPROP_YDISTANCE,120);
      ObjectSetInteger  (0,"2",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"2",OBJPROP_TEXT,DoubleToString(trRez.price-10*_Point,4));
      ObjectSetString   (0,"2",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"2",OBJPROP_FONTSIZE,20);
  
  
  ObjectDelete      (0,"3");
      ObjectCreate      (0,"3",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"3",OBJPROP_XDISTANCE,60);
      ObjectSetInteger  (0,"3",OBJPROP_YDISTANCE,150);
      ObjectSetInteger  (0,"3",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"3",OBJPROP_TEXT,DoubleToString(trRez.price+30*_Point,4));
      ObjectSetString   (0,"3",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"3",OBJPROP_FONTSIZE,20);
      
       ObjectDelete      (0,"4");
      ObjectCreate      (0,"4",OBJ_LABEL,0,0,0);           
      ObjectSetInteger  (0,"4",OBJPROP_XDISTANCE,60);
      ObjectSetInteger  (0,"4",OBJPROP_YDISTANCE,180);
      ObjectSetInteger  (0,"4",OBJPROP_COLOR,YellowGreen);
      ObjectSetString   (0,"4",OBJPROP_TEXT,DoubleToString(ask11,4));
      ObjectSetString   (0,"4",OBJPROP_FONT,"Arial");
      ObjectSetInteger  (0,"4",OBJPROP_FONTSIZE,20);
      
      */
  }
//+------------------------------------------------------------------+
