Daily_Hedge1





//+------------------------------------------------------------------+
//|                                                      HedgeEA.mq4 |
//|                                 Copyright © 2006, ForexForums.org|
//+------------------------------------------------------------------+




#property copyright "Copyright © 2006, ForexForums.org"
#property link      "http://www.forexforums.org/"

#include <stdlib.mqh>

//---- input parameters
extern string     eaname           = "[DH_Perky]";                       // Expert Name and first part of comment line
extern int        Magic            = 1001;                          // Magic Number ( 0 - for All positions)
extern bool       Autotrade        = true;                          // Set to false to prevent an entry after an exit
extern bool     HedgeGBPUSD=True;
extern bool     HedgeEURUSD=True;
extern bool     HedgeUSDCHF=True;
extern bool     HedgeUSDJPY=True;



extern string     Lotsizes         = "Set Ratio to 1 to use equal";
extern double     Lots             = 0.1;                           // Lots for first pair if MM is turned off
extern bool       StopManageAcc    = false;                         // Stop of Manage Account switch(Close All Trades)
extern double     MaxLoss          = 0;                             // Maximum total loss in pips or USD 
extern bool       AccountIsMicro   = true;                          // Set true if you use a micro account
extern double     ProfitTarget     = 50;                            // Profit target in pips or USD  
extern bool       UsePips          = true;
extern bool       MoneyManagement  = true;
extern double     Risk             = 20;                            // Risk
extern bool       AutoProfit       = true;                          // When the price of Bolliner pair passes the Upper Bollinger close all trades

string comment = "";
string eBody = "";
string eSubject = "";
string TradeSymbol ="";
int totalPips=0;
double  totalProfits=0;
int ticket1=0
   ,ticket2=0
   ,Symbol1SP
   ,Symbol2SP
   ,Order1=0
   ,Order2=0
   ,c1=0
   ,c2=0
   ,Symbol1OP
   ,Symbol2OP
   ,numords=0
   ;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {



// ---- Scan Open Trades


// Generate Comment on OrderSend 
string GenerateComment(string eaname, int Magic)
{
   return (StringConcatenate(eaname, "-", Magic));
}




void ChartComment()
{
   string sComment   = "";
   string sp         = "****************************\n";
   string NL         = "\n";

   sComment = sp;
   sComment = sComment + "Open Positions      = " + ScanOpenTrades() + NL;
   
  
   
   //sComment = sComment + "Account Leverage 1:" + AccountLeverage() + NL;
   sComment = sComment + NL + sp;

  
   Comment(sComment);
}	  


// added MM v3
double LotSize()
{
     double lotMM = MathCeil(AccountFreeMargin() *  Risk / 1000) / AccountLeverage() / 2;
	  
	  if(AccountIsMicro==false)                          //normal account
	  {
	     if(lotMM < 0.1)                    lotMM = 0.1;
	     if((lotMM >= 0.1) && (lotMM < 0.2)) lotMM = 0.2;
	     if((lotMM >= 0.2) && (lotMM < 0.3)) lotMM = 0.3;
	     if((lotMM >= 0.3) && (lotMM < 0.4)) lotMM = 0.4;
	     if((lotMM >= 0.4) && (lotMM < 1))   lotMM = 0.5;  
	     if(lotMM >= 1.0)                    lotMM = MathCeil(lotMM);
	     if(lotMM >= 100)                    lotMM = 100;
	  }
	  else                                               //micro account
	  {
	     if(lotMM < 0.01)                 lotMM = 0.01; 
	     if((lotMM >= 0.01) && (lotMM < 0.02)) lotMM = 0.02;
	     if((lotMM >= 0.02) && (lotMM < 0.03)) lotMM = 0.03;
	     if((lotMM >= 0.03) && (lotMM < 0.04)) lotMM = 0.04;
	     if((lotMM >= 0.05) && (lotMM < 0.06)) lotMM = 0.05; 
	     if((lotMM >= 0.06) && (lotMM < 0.07)) lotMM = 0.06; 
	     if((lotMM >= 0.07) && (lotMM < 0.08)) lotMM = 0.08; 
	     if((lotMM >= 0.08) && (lotMM < 0.09)) lotMM = 0.09;
	     if((lotMM >= 0.09) && (lotMM < 0.10)) lotMM = 0.1;  
	     if((lotMM >= 0.1) && (lotMM < 0.2)) lotMM = 0.2;
	     if((lotMM >= 0.2) && (lotMM < 0.3)) lotMM = 0.3;
	     if((lotMM >= 0.3) && (lotMM < 0.4)) lotMM = 0.4;
	     if((lotMM >= 0.4) && (lotMM < 1))   lotMM = 0.5; 	   
	     if(lotMM >= 1.0)                  lotMM = MathCeil(lotMM);
	     if(lotMM >= 100)                  lotMM = 100;
	  }
  
//	  Print(lotMM);
	  
	  return (lotMM);
}

 
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
   
{
  
 
   ChartComment();

   //---- 

  //=============================================================================
//                                                           
//GrabNewsFF.mq4 - hacked up!
//                                            Copyright © 2006, Derk Wehler
//                   Code derieved from original by: Copyright © 2006, Abhi
// (SCRIPT)
//=============================================================================
//#property copyright "Copyright © 2006, Derk Wehler"
//#property link      "no site"

//
// Ron hacked this up so it can grab
// data from AlterTrader
//

#include <WinInet.mqh>

  // it's the symbol + "clo" to get other data
//string	myUrlGBPUSD            = "http://www.altertrader.com/GBPUSDclo.html";
string	myUrl        = "http://www.altertrader.com/EURUSDclo.html";
//string	myUrlUSDCHF            = "http://www.altertrader.com/USDCHFclo.html";
//string	myUrlUSDJPY            = "http://www.altertrader.com/USDJPYclo.html";

string 	Outputfile       =   "altertrade.txt";


int beginning=1;


{
   
   int handle;
   int finalend;
   int end;
   int i,xx;
   string sData;
   string xdate,xprice,xpct;
   double Pricez[];
   int size;

   int endcheck;


	GrabWeb(myUrl, sData);
	finalend=StringLen(sData);
	


	// let's parse it now and write to csv file
	handle = FileOpen(Outputfile,FILE_CSV|FILE_WRITE,",");

   // Handle DATE just once 
   beginning = StringFind(sData,"<BR>",beginning)+4;
   end = StringFind(sData,"<",beginning);
   //Print("1 B="+beginning+" E="+end);
   if ((end-beginning)>0)
     {
      xdate = StringSubstr(sData,beginning,end-beginning);
     }

	FileWrite(handle,"Price","Percent ",xdate);
	
	while (beginning < finalend)
	  {
     
      // Handle PRICE 
      beginning = StringFind(sData,"align=\"center\">",beginning)+15;
      end = StringFind(sData,"<",beginning);
      //Print("1 B="+beginning+" E="+end);
      if ((end-beginning)>0)
        {
         xprice = StringSubstr(sData,beginning,end-beginning);
         pricez[xx]=xprice;
        }
         
      // Handle PERCENT
      beginning = StringFind(sData,"align=\"center\">",beginning)+15;
      end = StringFind(sData,"<",beginning);
      //Print("2 B="+beginning+" E="+end);
      if ((end-beginning)>0)
        {
         xpct = StringSubstr(sData,beginning,end-beginning);
        }
         

      FileWrite(handle,xprice+","+xpct);
      xx=xx+1;  
      // are we out of data?
      endcheck = StringFind(sData,"<tr>", beginning);
      if(endcheck<0) break;
      
      beginning=endcheck;

	}

	FileClose(handle);
 
}



    
    

  
// Prepare Comment line for the trades

     if(Symbol1isLong) {
     comment = Symbol1 + "_L/"; 
     } else {
     comment = Symbol1 + "_S/";
     }
     if(Symbol2isLong) {
     comment = comment + "L_" + Symbol2;
     } else {
     comment = comment +"S_" + Symbol2;
     }
     
     comment = comment + " " + GenerateComment(eaname, Magic);
     
// Micro or Mini

double AccountSize;

     if(AccountIsMicro)  {
     
     AccountSize=2;
     
     } else {
     
     AccountSize=1;
     
     }        

// added MM statement


double OrderLots1,OrderLots2;


     if(MoneyManagement) {
     
     OrderLots1 = NormalizeDouble(LotSize(),AccountSize); //Adjust the lot size
     OrderLots2 = NormalizeDouble(LotSize() * Ratio,AccountSize); // change 2 to 1 for mini account
     
     } else {
     
     OrderLots1 = Lots;
     OrderLots2 = NormalizeDouble(Lots * Ratio,2); //change 2 to 1 for mini account
   
     }
      
     

     

     
     
// Long/Short   open trades//+------------------------------------------------------------------+







     
     
           
      
      OrderSend(Symbol1,OP_BUY,OrderLots1,MarketInfo(Symbol1,MODE_ASK),3,0,0,comment,Magic,0,Blue);
      if (GetLastError()==0) {Order1=1;}
     
   
      OrderSend(Symbol2,OP_SELL,OrderLots2,MarketInfo(Symbol2,MODE_BID),3,0,0,comment,Magic,0,Red);
      if (GetLastError()==0) {Order2=1;}
      
      
      

      

    
      
              
 return(0);
}//int start
//+------------------------------------------------------------------+







Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
It automatically opens orders when conditions are reached

Other Features:


Uses files from the file system
It writes information to file