Hedge help

 

Hi,

please one question:

1- I open order manual trade

2- I want code for open hedge trade immediately when I open (step 1) 

Thank you

 
ziadsy:

Hi,

please one question:

1- I open order manual trade

2- I want code for open hedge trade immediately when I open (step 1) 

Thank you

WhY?

 
"Hedging" in Forex trading -Why do it?
"Hedging" in Forex trading -Why do it?
  • 2017.01.19
  • www.mql5.com
if I may offer my opinion..... Hedging is a method to limit risk. Consider this scenario...
 
nicholi shen:

WhY?

I test it
 
Thank you for this tip
Can you give me the code please
 
if(trader_wants_to_give_money_to_broker_for_no_benefit)
   do_offset_order_hedge();
 
ziadsy:
Thank you for this tip
Can you give me the code please

When you hedge directly after you opened a position it's called a lock. It's a strategy which made its proof so far, but you have to close the negative position before to let run the positive one (logical!)

The code maybe different for MT4 & MT5, I don't remember as I didn't use MT4 for a while now 

For MT5 it would be something like this (to copy paste in a script file) : 

void OnStart()
  {
// Select last position
   PositionSelectByTicket(PositionGetTicket(PositionsTotal()-1));
// Prepare order
   MqlTradeRequest request={0};
   request.action=TRADE_ACTION_DEAL;
   request.type=(PositionGetInteger(POSITION_TYPE)==0)?ORDER_TYPE_SELL:ORDER_TYPE_BUY;
   request.symbol=PositionGetString(POSITION_SYMBOL);
   request.volume=PositionGetDouble(POSITION_VOLUME);
   request.price=(request.type==ORDER_TYPE_BUY)?SymbolInfoDouble(request.symbol,SYMBOL_ASK):SymbolInfoDouble(request.symbol,SYMBOL_BID);
   if(PositionGetDouble(POSITION_SL)!=NULL) request.sl=(request.type==ORDER_TYPE_BUY)?request.price-MathAbs(PositionGetDouble(POSITION_PRICE_OPEN)-PositionGetDouble(POSITION_SL)):request.price+MathAbs(PositionGetDouble(POSITION_PRICE_OPEN)-PositionGetDouble(POSITION_SL)); else request.sl=0;
   if(PositionGetDouble(POSITION_TP)!=NULL) request.tp=(request.type==ORDER_TYPE_BUY)?request.price+MathAbs(PositionGetDouble(POSITION_PRICE_OPEN)-PositionGetDouble(POSITION_TP)):request.price-MathAbs(PositionGetDouble(POSITION_PRICE_OPEN)-PositionGetDouble(POSITION_TP)); else request.tp=0;
// Send order
   MqlTradeResult result={0};
   if(OrderSend(request,result)) { Print(__FUNCTION__,":",result.comment); }
  }

By running the script, it will lock the last opened order with the same tp/sl as the previous one (don't forget to close the losing position first !)

Merry Xmas :)

 
Icham Aidibe:

When you hedge directly after you opened a position it's called a lock. It's a strategy which made its proof so far, but you have to close the negative position before to let run the positive one (logical!)

The code maybe different for MT4 & MT5, I don't remember as I didn't use MT4 for a while now 

For MT5 it would be something like this (to copy paste in a script file) : 

By running the script, it will lock the last opened order with the same tp/sl as the previous one (don't forget to close the losing position first !)

Merry Xmas :)

There's no proven benefit to "lock". You might as well just close the trade because it's the same net effect without the additional swap and commissions. 

 
nicholi shen:

There's no proven benefit to "lock". You might as well just close the trade because it's the same net effect without the additional swap and commissions. 

Well. Some EA are based only on locking, one could find plenty across the market : sterile debate.

 
Icham Aidibe: Well. Some EA are based only on locking, one could find plenty across the market : sterile debate.

You will also find thousands of websites claiming that the Earth is flat, but that does not make it true.

So, saying that "hedging lock" is a "proven benefit" is just as fake and ignorant as saying the Earth is flat!

 
Fernando Carreiro:

You will also find thousands of websites claiming that the Earth is flat, but that does not make it true.

So, saying that "hedging lock" is a "proven benefit" is just as fake and ignorant as saying the Earth is flat!

Fernando, locking strategies are efficients when some use it, including me - I don't care it didn't work for you, or nicholshen, you probably didn't apply it correctly, swap & commissions aren't an argument as it's drowned in only a hundred points of profit. 

I won't either interrupt my morning coffee, open a terminal and make few of them to prove something to someone somewhere.

That said, I'm bored by pointless polemics, so "OK YOU ARE RIGHT!", pass you way or let me pass mine.

Reason: