BUILDING AN EA, HEDGING STRATEGY

 

Hello everybody. I am trying to build an EA using Hedging Strategy. I just thinking that it will works eventhough it will give a small profit but still it is a profit.

I want to use moving averages like 5 and 21.

If the 5MA crosses above 21MA, it will execute a Buy Position. OR if the 5MA crosses below the 21MA, it will execute a Sell Position using a lotsize of 0.01

The target will be to have a profit of 2.50.

if the target >= profit, automatically close the Open Position (1 open trade). 

if the target < the profit, let the Open Position run but if the MA Crosses, just execute Buy/Sell Position using the first lotsize x 2 or 0.02.

if the target is >= profit, automatically close all the Open Position (2 open trades).

if the target < profit, let the 2 open position run but if the MA crosses, just execute another Buy/Sell Position using the first lotsize x 4 or 0.04.

if the target >= profit, close all the open positions (3 open trades)

if the target < profit, just let the open positions run but if the MA crosses, just execute Buy/Sell Poisition using lotzise x 8 or 0.08.

if the target >= profit, close  all the open positions (4 open trades)

and so on...

Anyway, I am here in the Philippines and Hedging is allowed by my broker. 

As of now, I only have this and i feel to difficult to complete my EA. I beg someone to help me to complete my EA. As of now, my EA Opens Buy/Sell Positions without target and Close and also the hedging part. I hope someone will help me to build my EA. God Bless you all..

 

 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 
Nieco Pama:

Hello everybody. I am trying to build an EA using Hedging Strategy. I just thinking that it will works eventhough it will give a small profit but still it is a profit.

I want to use moving averages like 5 and 21.

If the 5MA crosses above 21MA, it will execute a Buy Position. OR if the 5MA crosses below the 21MA, it will execute a Sell Position using a lotsize of 0.01

The target will be to have a profit of 2.50.

if the target >= profit, automatically close the Open Position (1 open trade). 

if the target < the profit, let the Open Position run but if the MA Crosses, just execute Buy/Sell Position using the first lotsize x 2 or 0.02.

if the target is >= profit, automatically close all the Open Position (2 open trades).

if the target < profit, let the 2 open position run but if the MA crosses, just execute another Buy/Sell Position using the first lotsize x 4 or 0.04.

if the target >= profit, close all the open positions (3 open trades)

if the target < profit, just let the open positions run but if the MA crosses, just execute Buy/Sell Poisition using lotzise x 8 or 0.08.

if the target >= profit, close  all the open positions (4 open trades)

and so on...

Anyway, I am here in the Philippines and Hedging is allowed by my broker. 

As of now, I only have this and i feel to difficult to complete my EA. I beg someone to help me to complete my EA. As of now, my EA Opens Buy/Sell Positions without target and Close and also the hedging part. I hope someone will help me to build my EA. God Bless you all.

extern double Lot    = 0.01;

extern double Target = 0.50;

int Magic            = 030381;

extern int FastMA = 5;

int FastMAShift = 0, FastMAMethod = 0, FastMAApplied = 0;

extern int SlowMA = 21;

int SlowMAShift = 0, SlowMAMethod = 0, SlowMAApplied = 0;

double PreviousFast, CurrentFast, PreviousSlow, CurrentSlow;

int OnInit()

{

return(0);

}


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

// expert deinitialization function

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

int deinit()

{

return(0);

}

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

// expert start function

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

int start()

          {       

            if (IsNewCandle()) CheckMA();

            return(0);

          }

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

bool IsNewCandle()

{

   if (Bars == BarsOnChart)

   return (false);

   BarsOnChart=Bars;

   return(true);

}

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

// indicators

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

 void CheckMA()

         {

            PreviousFast = iMA(NULL, 0, FastMA, FastMAShift, FastMAMethod, FastMAApplied,2);

            CurrentFast = iMA(NULL, 0, FastMA, FastMAShift, FastMAMethod, FastMAApplied,1);

            PreviousSlow = iMA(NULL, 0, SlowMA, SlowMAShift, SlowMAMethod, SlowMAApplied,2);

            CurrentSlow = iMA(NULL, 0, SlowMA, SlowMAShift, SlowMAMethod, SlowMAApplied,1);

            if (PreviousFast < PreviousSlow && CurrentFast > CurrentSlow)OpenOrder(0);

            if (PreviousFast > PreviousSlow && CurrentFast < CurrentSlow)OpenOrder(1);

         }

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

// to open trade positions

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

int OpenOrder(int direction)

        {        

            if (direction==0)

                OrderSend (Symbol(), OP_BUY, Lot*1, Ask, 3, 0, 0, NULL, Magic, 0, Blue);

            

            if (direction==1)

                 OrderSend (Symbol(), OP_SELL, Lot*1, Bid, 3, 0, 0, NULL, Magic, 0, Red);

            return(0);

         }


Hi ! 

You could find help all across the forum. This thread initiated by myself may help you in some points : 

https://www.mql5.com/en/forum/227775

Courage ! It's not easy to manage these kind of strategies ! 

Hedge saved you, who will save Hedge ?
Hedge saved you, who will save Hedge ?
  • 2018.02.16
  • www.mql5.com
Hi, I was "playing" with hedging to explore possibilities : it's very tempting, since it allows purely & simply to recover from a bad position...