Jump to content

Hedge Trading #1 - EUR & CHF


Recommended Posts

Re: Hedge Trading #1 - EUR & CHF

 

Have you changed the SymbolStartlots to something else than 0.0.

 

Does anyone know what is the best value for SPipDivergence?

 

As to Symbol1StartLots and Symbol2StartLots parameters, should I put the same lot size for EURUSD and USDCHF, or different lot sizes? Could you tell me what SymbolStartLots, SymbolLot Step, and SymbolTargetLots for the 2 symbols (EURUSD and USDCHF) should be like?

Link to comment
Share on other sites

  • Replies 139
  • Created
  • Last Reply

Top Posters In This Topic

Re: Hedge Trading #1 - EUR & CHF

 

It has been stated numerous times before, but you are trading the EURCHF simple as that even if your lot size is 'perfectly hedged' at the time of opening the position. Any profit or loss is due to change in the EURCHF exchange rate.

Trading two pairs (EURUSD & USDCHF) to achieve the same thing increases your costs in spread and swap. I don't understand why you would want to do it that way.

Historically the EUR & CHF are highly correlated however the EURCHF has moved in a 4000 pip range over the last 20 years and there is no guarantee that that range will never be breached in the future.

Link to comment
Share on other sites

Re: Hedge Trading #1 - EUR & CHF

 

As to Symbol1StartLots and Symbol2StartLots parameters, should I put the same lot size for EURUSD and USDCHF, or different lot sizes? Could you tell me what SymbolStartLots, SymbolLot Step, and SymbolTargetLots for the 2 symbols (EURUSD and USDCHF) should be like?

 

The same lot size for both. Lot steps the same size too. SymbolTargetLots is probably max total open lots.

Link to comment
Share on other sites

  • 2 weeks later...

Re: Hedge Trading #1 - EUR & CHF

 

With this script you can open 2 Pairs Market Orders simultaneously with TakeProfit and StopLoss settings. You can set the lot size and trade type - buy or sell - for the 2 Pairs separately.

Enjoy! :-bd

 

2PairsMarketOrdersWithTPandSL.mq4[/attachment:2j41au82]

 

Thanks.

 

I improved this script so now u only need to type how many EURUSD lots you want to trade, USDCHF lots will be calculated automatically according to current marginal requirements.

 

E.g. now 1 microlot EURUSD requires USD$2.93 (1:500 margin) and 1 microlot of USDCHF requires USD$2.00. So trading 0.2 lots EURUSD script will trade 0.2 EURSD and 0.2x2.93/2.00 lots of USDCHF.

Minimal lots and lotsteps considered.

Default Stoplosses amd Takeprofits are zeroed, since we're hedging.

If u still want to use them, they're in decimal pips, so for 50 pips u need to type 500.

 

Please try this script on demo first. Good luck!

http://www.4shared.com/file/138257693/2a477d54/HEDGE_2PairsMarketOrdersWithTP-SLandMM.html

Link to comment
Share on other sites

  • 2 weeks later...

Re: Hedge Trading #1 - EUR & CHF

 

 

Here is my little contribution which I hope that will help a bit.

4X-ROX.com offers this indi for $37 for monthly subscription. Don't worry its a full code indicator.

fx1001, do you happen to have other 4x-rox indis from HOG2? This indicator repaints so it shouldn't be used standalone.

Link to comment
Share on other sites

  • 2 weeks later...

Re: Hedge Trading #1 - EUR & CHF

 

well this is the best hedge expert i ever saw...

you can set it ti buy or sell the pairs then it will track the positions tell they reach the take profit you choose and close the tow positions

 

33633373 2009.11.09 02:10 buy 19.60 usdchf 1.01740 0.00000 0.00000 2009.11.09 02:34 1.01572 0.00 0.00 0.00 -3,241.84

33633426 2009.11.09 02:13 buy 19.60 eurusd 1.48581 0.00000 0.00000 2009.11.09 02:34 1.48778 0.00 0.00 0.00 3,861.20

33634049 2009.11.09 02:59 buy 0.10 usdchf 1.01493 0.00000 0.00000 2009.11.09 12:41 1.00732 0.00 0.00 0.00 -75.55

33634050 2009.11.09 02:59 buy 0.10 eurusd 1.48968 0.00000 0.00000 2009.11.09 12:41 1.49943 0.00 0.00 0.00 97.50

Link to comment
Share on other sites

Re: Hedge Trading #1 - EUR & CHF

 

here is the expert...some kudos please....

 

 

//+------------------------------------------------------------------+
//|                                                  HedgeTrader.mq4 |
//|                                  Copyright © 2006, Forex-Experts |
//|                                     [url]http://www.forex-experts.com[/url] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-Experts"
#property link      "http://www.forex-experts.com"

//---- input parameters
extern double    Lot1=1.05;
extern double    Lot2=1.;
extern string    Sym1="USDCHF";
extern string    Sym2="EURUSD";
extern string    Operation1="buy";
extern string    Operation2="buy";
extern double    Commission1=3.0;
extern double    Commission2=2.0;
extern double    Profit=5.0;
extern bool 	  SetNewOrders=true;
extern int		  NumTradesForReverse=0;	// Max number of trades after we should reverse for opearations; if 0 - disable it.

extern bool      UseMM=true;
extern double    Delta=500;
extern int 		  MagicNumber=0;
int OP1=-1, OP2=-1;

double Ilo1=0, Ilo2=0;
bool	NewOrders=false;
bool  FirstTime=true;

int	Last1=0, Last2=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
 {
//---- 
//init global variables
if (!GlobalVariableCheck("_CanClose"+DoubleToStr(MagicNumber,0))) {
GlobalVariableSet("_CanClose"+DoubleToStr(MagicNumber,0),0);
}      
//if (!GlobalVariableCheck("_CanSet")) {
//GlobalVariableSet("_CanSet",0);
//}      


if (!GlobalVariableCheck("_Trades"+DoubleToStr(MagicNumber,0))) {
GlobalVariableSet("_Trades"+DoubleToStr(MagicNumber,0),0);
}      



if (!GlobalVariableCheck("_Last1"+DoubleToStr(MagicNumber,0))) {
GlobalVariableSet("_Last1"+DoubleToStr(MagicNumber,0),0);
}      
if (!GlobalVariableCheck("_Last2"+DoubleToStr(MagicNumber,0))) {
GlobalVariableSet("_Last2"+DoubleToStr(MagicNumber,0),0);
}      





//----
  return(0);
 }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
 {
//---- 
  
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
 {
Ilo1=Lot1; Ilo2=Lot2;
if (UseMM) {
Ilo1=TradeLot(AccountBalance());
Ilo2=Ilo1*(Lot2/Lot1);
}

if (FirstTime==true) {
NewOrders=true;
FirstTime=false;
if (Operation1=="buy" || Operation1=="BUY") OP1=OP_BUY;
if (Operation2=="buy" || Operation2=="BUY") OP2=OP_BUY; 
if (Operation1=="sell" || Operation1=="SELL") OP1=OP_SELL; 
if (Operation2=="sell" || Operation2=="SELL") OP2=OP_SELL; 
GlobalVariableSet("_Last1"+DoubleToStr(MagicNumber,0),OP1);
GlobalVariableSet("_Last2"+DoubleToStr(MagicNumber,0),OP2);
Last1=OP1;
Last2=OP2;
}

if (CntOrd(OP_BUY,MagicNumber,Sym1)>0) {
OP1=OP_BUY;
GlobalVariableSet("_Last1"+DoubleToStr(MagicNumber,0),OP1);
}	

if (CntOrd(OP_SELL,MagicNumber,Sym1)>0) {
OP1=OP_SELL;
GlobalVariableSet("_Last1"+DoubleToStr(MagicNumber,0),OP1);
}	

if (CntOrd(OP_BUY,MagicNumber,Sym2)>0) {
OP2=OP_BUY;
GlobalVariableSet("_Last2"+DoubleToStr(MagicNumber,0),OP2);
}	

if (CntOrd(OP_SELL,MagicNumber,Sym2)>0) {
OP2=OP_SELL;
GlobalVariableSet("_Last2"+DoubleToStr(MagicNumber,0),OP2);
}	





//---- 
double Commissions=0;




if (OP1<0 || OP2<0) {
  Comment("Wrong operation selected, aborted...");
  return;
}

int	_Trades=0;

if (GlobalVariableGet("_CanClose"+DoubleToStr(MagicNumber,0))==1 && CntOrd(GlobalVariableGet("_Last1"+DoubleToStr(MagicNumber,0)),MagicNumber,Sym1)==0 && CntOrd(GlobalVariableGet("_Last2"+DoubleToStr(MagicNumber,0)),MagicNumber,Sym2)==0) {
_Trades=GlobalVariableGet("_Trades"+DoubleToStr(MagicNumber,0))+1;
GlobalVariableSet("_Trades"+DoubleToStr(MagicNumber,0),_Trades);
  GlobalVariableSet("_CanClose"+DoubleToStr(MagicNumber,0),0);
}

if (GlobalVariableGet("_CanClose"+DoubleToStr(MagicNumber,0))==0 && CntOrd(GlobalVariableGet("_Last1"+DoubleToStr(MagicNumber,0)),MagicNumber,Sym1)==0 && CntOrd(GlobalVariableGet("_Last2"+DoubleToStr(MagicNumber,0)),MagicNumber,Sym2)==0) {
if(NumTradesForReverse != 0)
{
if (GlobalVariableGet("_Trades"+DoubleToStr(MagicNumber,0))>=NumTradesForReverse) {
	GlobalVariableSet("_Trades"+DoubleToStr(MagicNumber,0),0);			
	if (GlobalVariableGet("_Last1"+DoubleToStr(MagicNumber,0))==OP_BUY) OP1=OP_SELL; else OP1=OP_BUY;
	if (GlobalVariableGet("_Last2"+DoubleToStr(MagicNumber,0))==OP_BUY) OP2=OP_SELL; else OP2=OP_BUY;				
}
}
}


if (GlobalVariableGet("_CanClose"+DoubleToStr(MagicNumber,0))==0 && NewOrders==true) {
//Set intitial orders
SetOrders();
}



Comment("NewOrders=",NewOrders," Balance=",AccountBalance(),"\n",Sym1," Lot=",Ilo1," ",Sym2," Lot=",Ilo2,"\nFloating profit=",CalcProfit()," Expected profit=",Profit*Ilo1*10,"\nTrades=",GlobalVariableGet("_Trades"+DoubleToStr(MagicNumber,0)));

if (SetNewOrders==false) NewOrders=false;
if (SetNewOrders==true) NewOrders=true;

//Check for profit
Commissions=Commission1*Ilo1+Commission2*Ilo1;

if ( (CalcProfit()-Commissions) >= (Profit*Ilo1*10) ) {
GlobalVariableSet("_CanClose"+DoubleToStr(MagicNumber,0),1);
}    

CloseAll();


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


double CalcProfit() {
//Calculating profit for opened positions
int cnt;
double _Profit;
_Profit=0;   

for(cnt=0; cnt<OrdersTotal(); cnt++)
{     
  OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ((OrderSymbol()==Sym1 || OrderSymbol()==Sym2) && ((OrderMagicNumber()==MagicNumber) || MagicNumber==0)) {
  _Profit=_Profit+OrderProfit(); 
  }   
}
return(_Profit);
}

void CloseAll() {
int _total=OrdersTotal(); // number of orders  
int _ordertype;// order type   
if (_total==0) {return;}
int _ticket; // ticket number
double _priceClose;// price to close orders;
//Closing all opened positions
if (GlobalVariableGet("_CanClose"+DoubleToStr(MagicNumber,0))==1) {
for(int _i=_total-1;_i>=0;_i--)
     {
     if (OrderSelect(_i,SELECT_BY_POS))
        {
        _ordertype=OrderType();
        _ticket=OrderTicket();
        if (((OrderMagicNumber()==MagicNumber) || MagicNumber==0)) {
        switch(_ordertype)
           {
           case 0:
              // close buy                
              _priceClose=MarketInfo(OrderSymbol(),MODE_BID);
              Print("Close on ",_i," position order with ticket ¹",_ticket);
              OrderClose(_ticket,OrderLots(),_priceClose,0,Red);
              //break;
           case 1:
              // close sell
              _priceClose=MarketInfo(OrderSymbol(),MODE_ASK);
              Print("Close on ",_i," position order with ticket ¹",_ticket);
              OrderClose(_ticket,OrderLots(),_priceClose,0,Red);
//               break;
           default:
              // values from  1 to 5, deleting pending orders
              Print("Delete on ",_i," position order with ticket ¹",_ticket);
              OrderDelete(_ticket);  
//               break;
           }    
        }
        
        
        }
}


}
return;
}



void SetOrders() {
//Setting initial orders
double OpenPrice=0;

if (CntOrd(OP1,MagicNumber,Sym1)==0) {
  if (OP1==OP_BUY) OpenPrice=MarketInfo(Sym1,MODE_ASK);
  if (OP1==OP_SELL) OpenPrice=MarketInfo(Sym1,MODE_BID);
  Last1=OP1;
  GlobalVariableSet("_Last1"+DoubleToStr(MagicNumber,0),OP1);
  OrderSend(Sym1,OP1,Ilo1,OpenPrice,0,0,0,"HedgeTrader",MagicNumber,0,Red);
  //return;
}

if (CntOrd(OP2,MagicNumber,Sym2)==0) {
  if (OP2==OP_BUY) OpenPrice=MarketInfo(Sym2,MODE_ASK);
  if (OP2==OP_SELL) OpenPrice=MarketInfo(Sym2,MODE_BID);
  Last2=OP2;
  GlobalVariableSet("_Last2"+DoubleToStr(MagicNumber,0),OP2);
  OrderSend(Sym2,OP2,Ilo2,OpenPrice,0,0,0,"HedgeTrader",MagicNumber,0,Green);
  //return;
}



}



int CntOrd(int Type, int Magic, string Symb) {
//return number of orders with specific parameters
int _CntOrd;
_CntOrd=0;
for(int i=0;i<OrdersTotal();i++)
{
  OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
 
  if (OrderSymbol()==Symb) {
     if ( OrderType()==Type && ((OrderMagicNumber()==Magic) || Magic==0)) _CntOrd++;
  }
}
return(_CntOrd);
}

double TradeLot(double MyBalance) {
double _Ilo=0;
//AccountEquity()
_Ilo=MathFloor(MyBalance/Delta)/10;
if (_Ilo<0.1) _Ilo=0.1;		
return (_Ilo);

}

Link to comment
Share on other sites

Re: Hedge Trading #1 - EUR & CHF

 

well this is the best hedge expert i ever saw...

you can set it ti buy or sell the pairs then it will track the positions tell they reach the take profit you choose and close the tow positions

 

33633373 2009.11.09 02:10 buy 19.60 usdchf 1.01740 0.00000 0.00000 2009.11.09 02:34 1.01572 0.00 0.00 0.00 -3,241.84

33633426 2009.11.09 02:13 buy 19.60 eurusd 1.48581 0.00000 0.00000 2009.11.09 02:34 1.48778 0.00 0.00 0.00 3,861.20

33634049 2009.11.09 02:59 buy 0.10 usdchf 1.01493 0.00000 0.00000 2009.11.09 12:41 1.00732 0.00 0.00 0.00 -75.55

33634050 2009.11.09 02:59 buy 0.10 eurusd 1.48968 0.00000 0.00000 2009.11.09 12:41 1.49943 0.00 0.00 0.00 97.50

 

 

Hi deadsoul,

do you attach the EA on the two charts usdchf and eurusd? Same magic number for both charts?

What TF do you use?

 

thx

newbee

Link to comment
Share on other sites

Re: Hedge Trading #1 - EUR & CHF

 

now it's working after i've removed all charts and reload charts, no more zero divide error!

4xroxtx ea provided by liverpoolrulez has no auto ratio feature and has more complicated settings inside.

i shall use hedgeea 6.6 on my live alpari uk instead of rubbish 4xroxtx ea.

 

Can you share hedgeea 6.6 please! Old link is dead. Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...