Here is the rule corrected from AndyG Daily and H4 engulfing Price Action thread : http://www.forexfactory.com/showthread.php?t=429442 .
I test it it gives good result but the TP sometimes is very big and we need to exit manually
// ================================================================
// R RULE
// P_H4 P_D1
//=================================================================
Set_Rule (OP_BUYSELL, T_START, R_R, P_SIGNAL);
static double Bull_high = 0;
static double Bull_low = 0;
static double Bear_high = 0; static double Bear_low = 0;
static double Buy_SL, Buy_TP, Sell_SL, Sell_TP;
if (AndS (BAR, S_BULL_ENGULFING, P_D1))
{
Bull_high = SValue (HIGH, S_PREVIOUS, P_D1); // find the bull engulfing bar so I mark the high
Bull_low = SValue (LOW, S_PREVIOUS, P_D1);
}
if (AndS (BAR, S_BEAR_ENGULFING, P_D1))
{
Bear_low = SValue (LOW, S_PREVIOUS, P_D1); // find the bear engulfing bar so I mark the low
Bear_high = SValue (HIGH, S_PREVIOUS, P_D1);
}
if (Bull_high != 0 && SValue (CLOSE, S_PREVIOUS, P_H4) > Bull_high && RValue (OP_BUYSELL, T_BUYNBRTRADE, R_R) == 0)
{
Set_Rule (OP_BUY, T_STATUS, R_R, P_SIGNAL); // I do a Buy Trade ,
Buy_SL = (Ask - Bull_low)/ SYS_POINT;
Buy_TP = Buy_SL;
Bear_low = 0;
}
if (Bear_low != 0 && SValue (CLOSE, S_PREVIOUS, P_H4) < Bear_low && RValue (OP_BUYSELL, T_SELLNBRTRADE, R_R) == 0)
{
Set_Rule (OP_SELL, T_STATUS, R_R, P_SIGNAL); // I sell
Sell_SL = (Bear_high - Bid) / SYS_POINT;
Sell_TP = Sell_SL;
Bull_high = 0;
}
if (RValue (OP_BUYSELL, T_BUYNBRTRADE, R_R) != 0)
{
Set_Rule (OP_BUYSELL, T_BUYLOTSL, R_R, P_SIGNAL, Buy_SL); // Stop Loss low of the engulfing bar
Set_Rule (OP_BUYSELL, T_BUYLOTTP, R_R, P_SIGNAL, Buy_TP); // Take Profit
}
if (RValue (OP_BUYSELL, T_SELLNBRTRADE, R_R) != 0)
{
Set_Rule (OP_BUYSELL, T_SELLLOTSL, R_R, P_SIGNAL, Sell_SL); // High of the engulfing bar
Set_Rule (OP_BUYSELL, T_SELLLOTTP, R_R, P_SIGNAL, Sell_TP); // Take Profit
}