Navigation´╝ÜHome > Content >

BarrettM82A1-TRADER.mq4

Time: 2010-07-03 | Download file:BarrettM82A1-TRADER.mq4

#property copyright   "ArbitrageWay Scalping Forex Robot.Create by RonnyFX"

extern string    Set0                = "=============================================================";
extern string    Edition             = "";
extern int       MagicNumber         = 10001;
extern string    Set1                = "=============================================================";
extern bool      HiddenStops         = TRUE;
extern double    StopLoss            = 9.0;
extern double    TakeProfit          = 1.0;
extern string    Set2                = "=============================================================";
extern bool      DynamicDiff         = FALSE;
extern double    TradeDiff           = 3.0;
extern string    Set3                = "=============================================================";
extern bool      HoldOrder           = FALSE;
extern double    HoldTime            = 5.30;
extern string    Set4                = "=============================================================";
extern bool      MoneyManagement     = TRUE;
extern double    Risk                = 10.0;
extern string    Set5                = "=============================================================";    
extern double    Lots                = 0.1;
extern double    TargetPips          = 10.0;
extern double    StopPips            = 10.0;
extern double    TrailingStop        = 0.0;
extern int       Slippage            = 1;
extern double    MaxSpread           = 5.0;
       string    Comm                = "";
extern string    Set6                = "=============================================================";

   
       int    result                 = 0;
       string GLSAsk;
       string GLSBid;
       string FeederStatus;
       double TheStopLoss;
       double TheTakeProfit;

//---------------------------------------------------------------------------------------------------------//
void OnTick()
{

  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double MarketSpread = MarketInfo(Symbol(),MODE_SPREAD);
  if(Digits==3 || Digits==5)MarketSpread = MarketInfo(Symbol(),MODE_SPREAD)*0.1;
  
  CheckFeeder();
  
  double FeederAsk = StringToDouble(GLSAsk) ;
  double FeederBid = StringToDouble(GLSBid) ;
  int FeederOnline = StringToInteger(FeederStatus) ;
  
  double FeederSpread = (FeederAsk - FeederBid) / MyPoint;
  
  double Diff = TradeDiff ;
  if(DynamicDiff == TRUE) Diff = MarketSpread +TradeDiff ;
  
  double AskDiff = (FeederBid-Ask) / MyPoint ;
  double BidDiff = (Bid-FeederAsk) / MyPoint ;
  
  if(MarketSpread <= MaxSpread && FeederOnline == 1)
  {  
   if(AskDiff >= Diff) OpenBuy();         
   if(BidDiff >= Diff) OpenSell();
  }          
  
  if(HoldOrder == true) CheckHoldOrder();
  if(HoldOrder == true) HiddenStops = false; 
  if(HiddenStops == true) CheckHiddenStops();
  if(TrailingStop > 0) CheckTrailing();
  
  string Status = "";
  if(FeederOnline == 0) Status = "Slow";
  if(FeederOnline == 1) Status = "Fast";
 
  color Col1 = Gold;
  color Col2 = Gold;
  if(AskDiff > 0.1) Col1 = DeepSkyBlue;
  if(BidDiff > 0.1) Col2 = DeepSkyBlue;
  
   ObjectCreate("Feeder-Ask",OBJ_HLINE,0,0,0);
   ObjectSet("Feeder-Ask",OBJPROP_COLOR,Col2);
   ObjectSet("Feeder-Ask",OBJPROP_STYLE,2);
   ObjectSet("Feeder-Ask",OBJPROP_BACK,true);
   
   ObjectCreate("Feeder-Bid",OBJ_HLINE,0,0,0);
   ObjectSet("Feeder-Bid",OBJPROP_COLOR,Col1);
   ObjectSet("Feeder-Bid",OBJPROP_BACK,true);
   
   ObjectMove("Feeder-Ask",0,Time[0],FeederAsk);
   ObjectMove("Feeder-Bid",0,Time[0],FeederBid);
   
   ObjectCreate("bg1",OBJ_LABEL,0,0,0);
   ObjectSetText("bg1","g",140,"Webdings",Crimson);
   ObjectSet("bg1",OBJPROP_XDISTANCE,0);
   ObjectSet("bg1",OBJPROP_YDISTANCE,17);
    
   Comment
  ("    ========================",
  "\n","    Trader Spread = "+(MarketSpread),
  "\n","    Feeder Spread = "+(FeederSpread),
  "\n","    ========================",
  "\n","    Feeder Status = "+(Status),
  "\n","    Feeder Ask = "+(FeederAsk),
  "\n","    Feeder Bid = "+(FeederBid),
  "\n","    ========================",
  "\n","    Trader Ask = "+(Ask),
  "\n","    Trader Bid = "+(Bid),
  "\n","    ========================",
  "\n","    Ask Diff = "+(AskDiff),
  "\n","    Bid Diff = "+(BidDiff),
  "\n","    Entry Diff = "+(Diff),
  "\n","    ========================");
  
}
//---------------------------------------------------------------------------------------------------------// 
int TotalOrdersCount()
{
  for(int i=0;i0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TargetPips>0) TheTakeProfit=Ask+TargetPips*MyPoint;
         if(StopPips>0) TheStopLoss=Ask-StopPips*MyPoint;
         result=OrderSelect(result,SELECT_BY_TICKET);
         result=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
  }
}
//---------------------------------------------------------------------------------------------------------// 
void OpenSell()
{ 
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  if(MoneyManagement == TRUE) Lots = ((Risk * AccountBalance()) /100) /100;
  if(TotalOrdersCount() == 0)
  {
    result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,Comm,MagicNumber,0,Red);
    if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TargetPips>0) TheTakeProfit=Bid-TargetPips*MyPoint;
         if(StopPips>0) TheStopLoss=Bid+StopPips*MyPoint;
         result=OrderSelect(result,SELECT_BY_TICKET);
         result=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
  }
}   
//---------------------------------------------------------------------------------------------------------// 
void CheckFeeder()
{

 string InpFileName1="";
 string InpFileName2="";
 string InpFileName3="";
 string InpFileName4="";

 string FeederName  ="Feeder";


if(Symbol() == "EURUSD" || Symbol() == "EURUSD.lmx")
{
  InpFileName1="eu-ask.txt";
  InpFileName2="eu-bid.txt";
  InpFileName3="eu-status.txt";
  InpFileName4="eu-tick2.txt";
  
}

if(Symbol() == "GBPUSD" || Symbol() == "GBPUSD.lmx")
{
  InpFileName1="gu-ask.txt";
  InpFileName2="gu-bid.txt";
  InpFileName3="gu-status.txt";
  InpFileName4="gu-tick2.txt";
  
}

if(Symbol() == "USDJPY" || Symbol() == "USDJPY.lmx")
{
  InpFileName1="uj-ask.txt";
  InpFileName2="uj-bid.txt";
  InpFileName3="uj-status.txt";
  InpFileName4="uj-tick2.txt";
  
}

if(Symbol() == "EURJPY" || Symbol() == "EURJPY.lmx")
{
  InpFileName1="ej-ask.txt";
  InpFileName2="ej-bid.txt";
  InpFileName3="ej-status.txt";
  InpFileName4="ej-tick2.txt";
  
}

if(Symbol() == "AUDUSD" || Symbol() == "AUDUSD.lmx")
{
  InpFileName1="au-ask.txt";
  InpFileName2="au-bid.txt";
  InpFileName3="au-status.txt";
  InpFileName4="au-tick2.txt";
  
}

if(Symbol() == "USDCAD" || Symbol() == "USDCAD.lmx")
{
  InpFileName1="ucad-ask.txt";
  InpFileName2="ucad-bid.txt";
  InpFileName3="ucad-status.txt";
  InpFileName4="ucad-tick2.txt";
  
}
 
 string InpDirectoryName="FeederData";      
 string path1=FeederName+"//"+"MQL4"+"//"+"Files"+"//"+InpDirectoryName+"//"+InpFileName1;
 string path2=FeederName+"//"+"MQL4"+"//"+"Files"+"//"+InpDirectoryName+"//"+InpFileName2;
 string path3=FeederName+"//"+"MQL4"+"//"+"Files"+"//"+InpDirectoryName+"//"+InpFileName3;
 string path4=FeederName+"//"+"MQL4"+"//"+"Files"+"//"+InpDirectoryName+"//"+InpFileName4;

  int handle1 = FileOpen(path1,FILE_READ);
  if(handle1 > 0)
  {
  GLSAsk =FileReadString(handle1);
  FileClose(handle1);
  }

  int handle2 = FileOpen(path2,FILE_READ);
  if(handle2 > 0)
  {
  GLSBid =FileReadString(handle2);
  FileClose(handle2);
  }
  
  int handle3 = FileOpen(path3,FILE_READ);
  if(handle3 > 0)
  {
  FeederStatus =FileReadString(handle3);
  FileClose(handle3);
  }
  
  int handle4 = FileOpen(path4,FILE_WRITE);
  if(handle4 > 0)
  {
  FileWrite(handle4,GetTickCount());
  FileClose(handle4);
  }
 
} 
//---------------------------------------------------------------------------------------------------------//
void CheckHiddenStops()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  double CurrentPips=0;
  double MinDistance=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point+MyPoint;
  
      double dBid=Bid;
      double dAsk=Ask;
      int OldTicket=result;
      result=0;
      for(int j=OrdersTotal()-1; j>=0; j--) 
          if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
            if((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber))
              {
               if(OrderType()==OP_BUY)
                  CurrentPips=dBid-OrderOpenPrice();
               else
                  CurrentPips=OrderOpenPrice()-dAsk;
               CurrentPips=CurrentPips/MyPoint;
               result=OrderTicket();
               if((CurrentPips>=TakeProfit || CurrentPips<=-StopLoss) && IsTradeContextBusy()==false)
                 {
                  if(OrderType()==OP_BUY)
                     result=OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(dBid,Digits), Slippage*MyPoint/Point, Blue);
                  else
                     result=OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(dAsk,Digits), Slippage*MyPoint/Point, Red);
                 }
               
              }
}                
//---------------------------------------------------------------------------------------------------------// 
void CheckHoldOrder()
{

  double HoldOrderTime = HoldTime * 60;
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  double CurrentPips=0;
  double MinDistance=MarketInfo(Symbol(),MODE_STOPLEVEL)*Point+MyPoint;
  
      double dBid=Bid;
      double dAsk=Ask;
      int OldTicket=result;
      result=0;
      for(int j=OrdersTotal()-1; j>=0; j--) 
          if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
            if((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber))
              {
               if(OrderType()==OP_BUY)
                  CurrentPips=dBid-OrderOpenPrice();
               else
                  CurrentPips=OrderOpenPrice()-dAsk;
               CurrentPips=CurrentPips/MyPoint;
               result=OrderTicket();
               if(((TimeCurrent()- OrderOpenTime()) >= HoldOrderTime) && (CurrentPips>=TakeProfit || CurrentPips<=-StopLoss) && (IsTradeContextBusy()==false))
                 {
                  if(OrderType()==OP_BUY)
                     result=OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(dBid,Digits), Slippage*MyPoint/Point, Blue);
                  else
                     result=OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(dAsk,Digits), Slippage*MyPoint/Point, Red);
                 }
              
              }
}                
//---------------------------------------------------------------------------------------------------------// 
void CheckTrailing()
{

double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;

for(int cnt=0;cnt0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     result=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return;
                    }
                 }
              }
           }
        }
      }
      

}  

//---------------------------------------------------------------------------------------------------------// 

Recommend