Close trades based on crossover instead of Trend Reversal

 
handleHull=iCustom(_Symbol,PERIOD_CURRENT,"Hull",Hull_Period,Hull_Power,Hull_Price);

slowHandleHull=iCustom(_Symbol,PERIOD_CURRENT,"Hull",Slow_Hull_Period,Slow_Hull_Power,Slow_Hull_Price);
   
ArrayFree(hullVal);
   ArrayFree(slowHullVal);
   CopyBuffer(handleHull,1,0,2,hullVal);
   CopyBuffer(slowHandleHull,1,0,2,slowHullVal);



if(hullVal[1]==1&&hullVal[0]==0){

 closeOrderBuy();
bb=true;
}
if(hullVal[1]==0&&hullVal[0]==1){

 closeOrderSell();
ss=true;

I am using an EA which closes trades based on the above logic, but it often results in premature closure of trades when the fast MA reverses signal.

I would like to adapt the closeOrderBuy() trigger to be based only when the fast MA crosses the slow MA in a downtrend and vice versa for closeOrderSell(). This requires the actual trendline values rather than the trend direction. However, I think that the handleHull and slowHandleHull will result in trend directions, not trendline values.

Would it be possible to improve the attached Indicator or above logic to also obtain the trendline value of each candle? I struggle with this step.

Files:
Hull.mq5  5 kb
 
oneflewoverthecuckoosnest :

I am using an EA which closes trades based on the above logic, but it often results in premature closure of trades when the fast MA reverses signal.

I would like to adapt the closeOrderBuy() trigger to be based only when the fast MA crosses the slow MA in a downtrend and vice versa for closeOrderSell(). This requires the actual trendline values rather than the trend direction. However, I think that the handleHull and slowHandleHull will result in trend directions, not trendline values.

Would it be possible to improve the attached Indicator or above logic to also obtain the trendline value of each candle? I struggle with this step.

There are two questions:

  1. Do you create an indicator handle ONCE (in OnInit)?
  2. Are you using 'ArraySetAsSeries' for 'hullVal' and 'slowHullVal' arrays?
 

Hello!

I was able to interpret the hullVal and slowHullVal and determine that hullVal[2] and slowHullVal[2] represent the trendline values, and make the required logic adjustments.


Thank you for your response :)

Reason: