Hull Moving Average's Trend System - page 9

 

Hi, I'm studing the HMA Trend EA and I found problems to understand the function "WaitWhileBusy". This function is called just before the OrderClose.

I can't understand the loop behind this calling while it is enough clear that it is used to check for problems in the order transmission.

Could you help me to understand the program flow around this function?


//+------------------------------------------------------------------+
//| Close at market price |
//+------------------------------------------------------------------+
bool CloseNow(int ticket)
{
if (OrderSelectEx(ticket, SELECT_BY_TICKET))
{
if (OrderType() == OP_BUY)
{
OrderCloseEx(ticket, OrderLots(), Bid, close_slippage);
}else if (OrderType() == OP_SELL){
OrderCloseEx(ticket, OrderLots(), Ask, close_slippage);
}
}
}

..............................


bool OrderCloseEx(int ticket, double lots, double price, int slippage, color Color=CLR_NONE)
{
if(!WaitWhileBusy())
{
Print("Error in OrderCloseEx(): Timeout encountered");
return(false);
}
SetBusyState();
bool ret = OrderClose(ticket, lots, price, slippage, Color);
Sleep(6000);
ReleaseBusyState();
return(ret);
}

........

//+------------------------------------------------------------------+
//| Calling state functions |
//+------------------------------------------------------------------+
bool WaitWhileBusy()
{
datetime OldCurTime;
int timeoutsec=6;

OldCurTime=CurTime();
while (GlobalVariableCheck("InTrade") || !IsTradeAllowed()) {
if(OldCurTime + timeoutsec <= CurTime()) {
return(false);
}
Sleep(1000);
}
return(true);
}


void SetBusyState()
{
GlobalVariableSet("InTrade", CurTime()); // set lock indicator
}

void ReleaseBusyState()
{
GlobalVariableDel("InTrade"); // clear lock indicator
}

scorpion:
The system was posted by bradman when he needed this system coded. The system is simple. Long when HMA trend is up, and short when HMA trend is down. Attached is the EA, automated script for metatrader 4, and indicator of this system. You must install both of them. This expert advisor features:
  • You can trade multiple charts or currencies at the same time
  • Stop loss, take profit, breakeven
  • Trailing stop
  • Configurable settings
  • Many hidden features. (Advance users, put "extern" to reveal them)
How to use:
  • To enable stop loss, set SL_Mode = 1, then you configure SL to suit your style.
  • To enable trailing stop, set TS_Mode = 1. Trailing stop will hit when profit is x pips as specified in TS_Trigger.
  • Configure the indicator by settting HMA_Period and HMA_Mode.
Cheers!
 

Hello Scorpion, I'm trying to understand the EA code.

I'm not able to get what the following parte of code does.

Can you help me?

............

bool OrderCloseEx(int ticket, double lots, double price, int slippage, color Color=CLR_NONE)

{

if(!WaitWhileBusy())

{

Print("Error in OrderCloseEx(): Timeout encountered");

return(false);

}

SetBusyState();

bool ret = OrderClose(ticket, lots, price, slippage, Color);

Sleep(6000);

ReleaseBusyState();

return(ret);

}

...................

//+------------------------------------------------------------------+

//| Calling state functions |

//+------------------------------------------------------------------+

bool WaitWhileBusy()

{

datetime OldCurTime;

int timeoutsec=6;

OldCurTime=CurTime();

while (GlobalVariableCheck("InTrade") || !IsTradeAllowed()) {

if(OldCurTime + timeoutsec <= CurTime()) {

return(false);

}

Sleep(1000);

}

return(true);

}

 

The part above seems to be checking if the trading terminal is busy and would pause the EA for a few millisecond before sending the order again

 

Have installed the EA but it closes the trades with several minutes or seconds after they open. All were loses. I have added a zero to sl and tp since I have a five digit broker but it still closes the positions almost immediatly. Any suggestions on what is going on and how to correct it.

 

many thanks Scorpion !

 
scorpion:
The system was posted by bradman when he needed this system coded. The system is simple. Long when HMA trend is up, and short when HMA trend is down. Attached is the EA, automated script for metatrader 4, and indicator of this system. You must install both of them. This expert advisor features:
  • You can trade multiple charts or currencies at the same time
  • Stop loss, take profit, breakeven
  • Trailing stop
  • Configurable settings
  • Many hidden features. (Advance users, put "extern" to reveal them)
    • To enable stop loss, set SL_Mode = 1, then you configure SL to suit your style.
    • To enable trailing stop, set TS_Mode = 1. Trailing stop will hit when profit is x pips as specified in TS_Trigger.
    • Configure the indicator by settting HMA_Period and HMA_Mode.
Cheers!

Hi Scorpion

If one sets HMA_Period in the EA to 50, should one set the HMA to 50?

HMA mode refers to what?

Thanks

Harryg

 

Please elaborate on the operation of HMA_mode.

 
scorpion:
The system was posted by bradman when he needed this system coded. The system is simple. Long when HMA trend is up, and short when HMA trend is down. Attached is the EA, automated script for metatrader 4, and indicator of this system. You must install both of them. This expert advisor features:
  • You can trade multiple charts or currencies at the same time
  • Stop loss, take profit, breakeven
  • Trailing stop
  • Configurable settings
  • Many hidden features. (Advance users, put "extern" to reveal them)
  • How to use:
    • To enable stop loss, set SL_Mode = 1, then you configure SL to suit your style.
    • To enable trailing stop, set TS_Mode = 1. Trailing stop will hit when profit is x pips as specified in TS_Trigger.
    • Configure the indicator by settting HMA_Period and HMA_Mode.
Cheers!
 

Hey Scorpion,

I was searching for a basic HMA system and came across yours. However, I am not able to get the EA and indicator to work on my MT4 platform. When I try to edit the file it showing up with a bunch of HTML in the code. What would I be doing wrong?

scorpion:
The system was posted by bradman when he needed this system coded. The system is simple. Long when HMA trend is up, and short when HMA trend is down. Attached is the EA, automated script for metatrader 4, and indicator of this system. You must install both of them. This expert advisor features:
  • You can trade multiple charts or currencies at the same time
  • Stop loss, take profit, breakeven
  • Trailing stop
  • Configurable settings
  • Many hidden features. (Advance users, put "extern" to reveal them)
  • How to use:
    • To enable stop loss, set SL_Mode = 1, then you configure SL to suit your style.
    • To enable trailing stop, set TS_Mode = 1. Trailing stop will hit when profit is x pips as specified in TS_Trigger.
    • Configure the indicator by settting HMA_Period and HMA_Mode.
Cheers!
 

I would like to know if anyone can help me programming and testing this system please:

Time frame 1 hour
Only open trade between 0700 to 1600 GMT
Trading EUR USD

Ex.

long trade.

Entry (use values of close of the bars)

Price oscillator rising (5 25).

Hull moving average under the close(I don’t know the parameters, is a code from pro real .time)

Enter at 3 pips higher than the high of the candle that gives the entry sign.

Exit

Stop loss at the other side (low) of the bar with same buffer (3 pips).

Exit trailing stop at the low of the previous two bars.

Money management

Risk only 3%(or less depending on the results of the Ea) of the account, according to the initial stop loss. Has to be prepared to trade any unit only carrying multiples of lot. Meaning that, the position will be bigger if the stop loss is clothier.

Note: The Ea has to be prepared to invert the order if the stop is trigger or if the buy does no happen and there is an opposite signal.

To test afterwards

Even to put it more interesting I would only the trades if in the timeframe of 1m it is at the same direction of the biggest time frame