Log in

Avoid EA trading after price GAP

By geeegee 2082 days ago Comments (4)
Because after gap some indicators behavior is not usable for EA decision, I use simple code to avoid EA trading after GAP. At params section of EA add:

extern int MinGapSize = 3;
extern int BackGapBars = 10;

.... add check of Gap before decision of trading

if (NotGap()) {
    if (.....) Buy=true;
    if (.....) Sell=true;
}

........ and this is fuction to check GAP bigger than MinGapSize inside last BackBGapBars:

bool NotGap() // check if there is not a gap at current position or BackGapBars back
{   bool result=true; 
     double GapPrice1=High[0]; 
     double GapPrice2=Open[0];
     double GapPoint = MarketInfo(Symbol(), MODE_POINT);
     int GapSpread = MarketInfo(Symbol(), MODE_SPREAD);
     for (int ii=0;ii<=BackGapBars;ii++) 
        {
           if(Open[ii] > High[ii+1] + (MinGapSize + GapSpread)*GapPoint)
                       { result=false; GapPrice1=High[ii+1]; GapPrice2=Open[ii];}
        if(Open[ii] < Low[ii+1] - (MinGapSize + GapSpread)*GapPoint)
                       { result=false; GapPrice1=Low[ii+1]; GapPrice2=Open[ii];}
        } 
if (!result) 

  string Suffix=TimeToStr(Time[0]);
  if (ObjectFind("GAP"+Suffix)==-1) 
  { 
     ObjectCreate("GAP"+Suffix, OBJ_RECTANGLE, 0, Time[0], GapPrice1, Time[1], GapPrice2);
     ObjectSet("GAP"+Suffix,OBJPROP_COLOR,SteelBlue);
   }
}
return(result); 
}

thats all. See the picture for bad behavior of indicators after gap and marked not to trade space:
 NoTradeGap

Comments

  • jaguar1637 2080 days ago

    Yes, I appreciate a lot this function 

    I have many project, and a long term regards the Partial autocorrelation function

     becoz, a gap means price manipulation by huge volumes, this implies the current price reachs the Partial autocorrelation (working like a donchian channel) . I just found something in MQ5 and I am going to send you 

    rgds

  • jaguar1637 2080 days ago

    Hi Geeege

    THis is the code for ACF. From this it could be possible to write the Partial ACF

    //+-------------------------------------------------------------------------+
    void ACF(double x[], double& a[])
    {

    int p = MathPow(2, NN);
    int n=ArraySize(x);
    double rxx[],r,E,tmp;
    ArrayResize(rxx,p+1);
    int i,j,k,kh,ki;

    for(j=0;j<=p;j++)
    {
    rxx[j]=0.0;
    for(i=j;i<n;i++)
    rxx[j]+=x[i]*x[i-j];
    }
    E=rxx[0];

    Print(" E=rxx[0] "+E);

    for(k=1;k<=p;k++)
    {

    r=-rxx[k];
    for(i=1;i<k;i++)
    r-=a[i]*rxx[k-i];
    if ( E != 0)
    r/=E;

    a[k]=r;
    kh=k/2;
    for(i=1;i<=kh;i++)
    {
    ki=k-i;
    tmp=a[i];
    a[i]+=r*a[ki];
    if(i!=ki)
    a[ki]+=r*tmp;
    }

    E*=(1-r*r);
    }
    }

  • geeegee 2079 days ago

    This kind of price gap happen mainly from friday to sunday - as first big gap on the picture. The second one could be caused by other reasons - maybe some manipulations ... The second one do not influences indicators significantly due to its size ... size (pips) which triggers function and duration depend on settings of params ... Some indicators are not influenced much or scalping not may not to care about it. IMHO ACF can handle the second case, I am not sure if it can handle the first big one. There are some strategies waiting for this big gap and assumes that price wil go back to direction and/or level before price gap. I tested it and it is not the rule ...nothing to be trusted for trading...

  • jaguar1637 2079 days ago

    well , this price gap can happen quite every day, when Swiss banks need to set the CHF currency closed by  1.20