Indicator showing only sell arrows

To add comments, please log in or register
Stanislav Ivanov
6607
Stanislav Ivanov  

im having a problem with an indicator that shows arrow(buy and sell) on macd crosses, stoch signals and MA cross. The code seems ok, but when i use the indicator only sell arrows show . 

This is the code.


  double Macd0,Macd1,ma[10],stoch[10],stoch2[10];
  //-----------------------
  bool mabuy=false,masell=false;
   for( int i =0;i<=9;i++)
   {  
if(allowMA==true)
   {
    ma[i]=iMA(NULL,0,maperiod,i,mamethod,maprice,i);
   if( Close[i]>=ma[i] )
    {
    mabuy=true;
    }
//------------------------------------------   
   if( Close[i]<=ma[i] )
    {
    masell=true;
    }
   } 
else mabuy=true; masell=true; 
   }  
//------------------------+
//------------------------+
bool stochbuy=false,stochsell=false;
   for(  i =0;i<=9;i++)
   {
if(allowStoch==true)
   {  
   stoch[i]=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,mamethod,0,MODE_MAIN,i);
   stoch2[i]=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,mamethod,0,MODE_MAIN,i+1);
//---------------
   if(stoch[i]>stoch2[i] && stoch[i]<50)
    {
    stochbuy=true;
    }
//---------------
   if(stoch2[i]>stoch[i] && stoch[i]>50 )
    {
    stochsell =true;
    }
   }
   
else stochbuy=true;stochsell=true; 
} 
//------------------------------
  //----------------------
  for ( i = Bars - 1; i >= 0; i --)
  {
    Macd0 = iMACD(NULL , 0 , FastEMA , SlowEMA ,SignalSMA , PRICE_CLOSE , MODE_MAIN , i);
    Macd1 = iMACD(NULL , 0 , FastEMA , SlowEMA ,SignalSMA , PRICE_CLOSE , MODE_MAIN , i+1);
    buy [i] = 0; sell [i] = 0;
    if (Macd0 > 0 && Macd1 < 0 && mabuy==true && stochbuy==true)
    {
      buy [i] = Low [i] - 5 * Point;
      if (Period () >= PERIOD_M30) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_H1) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_H4) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_D1) buy [i] -= 8 * Point;
      if (Period () >= PERIOD_W1) buy [i] -= 12 * Point;
      if (Period () >= PERIOD_MN1) buy [i] -= 60 * Point;
    }
    if (Macd0 < 0 && Macd1 > 0&& masell==true && stochsell==true)
    {
      sell [i] = High [i] + 5 * Point;
      if (Period () >= PERIOD_M30) sell [i] += 8 * Point;
      if (Period () >= PERIOD_H1) sell [i] += 8 * Point;
      if (Period () >= PERIOD_H4) sell [i] += 8 * Point;
      if (Period () >= PERIOD_D1) sell [i] += 8 * Point;
      if (Period () >= PERIOD_W1) sell [i] += 12 * Point;
      if (Period () >= PERIOD_MN1) sell [i] += 60 * Point;
    }     
  }
To add comments, please log in or register