I cant find the problem in my EA

 

Hi 
I wrote an EA without sending/closing orders.

for now I just want EA show me some Comments and an alert.
It's not working well  and I can't find problems.





Funny part is if I put Bullish(Calculate_Bullish_Volume()) and bearish (Calculate_Bearish_Volume()) in the comment Bullish is stop working and returns 0.

But in a comment without bearish bullish is working.(however I think its not working perfectly)

its not the only problem of this EA.
please help me to find reasons and solutions.

I hope you understand my English  .
I know its not very easy ;)


All the parts will be using in this EA but I made some parts comment (gray  ) because I think they work well.

//+------------------------------------------------------------------+
//|                                        Seyed Speed Of Volume.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict


input long Intended_Speed=1000;
input bool Mode_Ask_or_Bid=false;  //ask=true,Bid=false
/*input int Period_=14;
input color Text_Color=clrYellow;
input int Text_Size=10;
input int Text_Distance=3;
input bool Text_Linear_view;
input ENUM_ANCHOR_POINT anchor=ANCHOR_CENTER;
input bool Text_Background=false;
*/
datetime LastTickTime=TimeCurrent()-1;
long LastVol=0;
double LastTickPrice=0;
long LastBullVol=0;
long LastBearVol=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//--- 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

/*   for(int i=0;i<200;i++)//ta 200 candle ro pak mikone , agar kabayad bejash az kalamey Period    
      //estefade konimchon agar user period ro bala bebare bad dobare paeen biare ye tedad az candlhaye ghadimi pak nemishan
     {
      ObjectDelete(ChartID(),string(i));
     }

 TextCreate();
*/
   Comment("    C 14 :"," ",Volume[13],
           "    C 13 :"," ",Volume[12],
           "    C 12 :"," ",Volume[11],
           "    C 11 :"," ",Volume[10],
           "    C 10 :"," ",Volume[9],
           "    C 9  :"," ",Volume[8],
           "    C 8  :"," ",Volume[7],
           "    C 7  :"," ",Volume[6],
           "    C 6  :"," ",Volume[5],
           "    C 5  :"," ",Volume[4],
           "    C 4  :"," ",Volume[3],
           "    C 3  :"," ",Volume[2],
           "    C 2  :"," ",Volume[1],
           "    C 1  :"," ",Volume[0],
"\nBullish  ",Calculate_Bull_Volume(),
"\nBearish  ",Calculate_Bear_Volume(),


           "\nSpeed : ",Speed(),"  TPM",
           "\nBull Speed  ",BullSpeed(),
           
            "\nBull Speed  ",BullSpeed(),
           "\nBear Speed  ",BearSpeed(),
           "\nTimeDiff  ",TimeDifference());

   if(Speed()>=Intended_Speed)
     {
      Alert(" Market is going fast  ",Speed(),"  TPM");
     }

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
long Speed()
  {
 static  long Spe=0;
   if(TimeDifference()>=1)
     {Alert("Timedif",TimeDifference());

      Spe=(Volume[0]-LastVol)/TimeDifference();
     }
   LastVol=Volume[0];
   return(Spe);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Price()
  {
   double Pr=0;
   if(Mode_Ask_or_Bid)
     {
      Pr=Ask;
     }
   else
     {
      Pr=Bid;
     }
   return(Pr);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool Direction()// dorost kar mikone
  {

   bool dir=false;
   if(LastTickPrice!=Price())
     {
      if(Price()>LastTickPrice)
        {
         dir=true;

        }
      else
        {
         dir=false;
        }
      LastTickPrice=Price();//Alert(LastTickPrice,"   ",Price());
     }
   return(dir);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int Calculate_Bull_Volume()
  {
   static int bullmove=0;
   static datetime renew=iTime(Symbol(),PERIOD_CURRENT,1);
   if(renew<iTime(Symbol(),PERIOD_CURRENT,0))
     {
      bullmove=0;
      renew=iTime(Symbol(),PERIOD_CURRENT,0);
     }

   if(Direction())
     {
      bullmove++;
     }
   return(bullmove);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int Calculate_Bear_Volume()
  {
   static int bearmove=0;
   static datetime renew=iTime(Symbol(),PERIOD_CURRENT,1);
   if(renew<iTime(Symbol(),PERIOD_CURRENT,0))
     {
      bearmove=0;
      renew=iTime(Symbol(),PERIOD_CURRENT,0);
     }

   if(!Direction())
     {
      bearmove--;
     }

   return(bearmove);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double BullSpeed()
  {
   double bullsp=0;
   if(TimeDifference()>=1)
     {
      if(Calculate_Bull_Volume()>LastBullVol)
        {
         bullsp=NormalizeDouble((Calculate_Bull_Volume()-LastBullVol)/TimeDifference(),2);
         LastBullVol=Calculate_Bull_Volume();
        
        }
     }

   return(bullsp);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
 int BearSpeed()
  {
   int bearSp=0;
   if(TimeDifference()>=1)
     {
      if(Calculate_Bear_Volume()>LastBearVol)
        {
         bearSp=NormalizeDouble((Calculate_Bear_Volume()-LastBearVol)/TimeDifference(),2);
        }
     }
   return(bearSp);
  }
//+------------------------------------------------------------------+
long TimeDifference()
  {
   long diff=0;
   if(LastTickTime!=TimeCurrent())
     {

      if(TimeCurrent()-LastTickTime>=1)
        {
         diff=(TimeCurrent()-LastTickTime);
         LastTickTime=TimeCurrent();
        }
     }

   return(diff);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

/*void TextCreate()
  {
   double Posit;
   for(int i=0;i<Period_;i++)
     {

      datetime time=iTime(Symbol(),PERIOD_CURRENT,i);
      if(Text_Linear_view)
        {
         Posit=TexePosition();
        }

      else  {Posit=Low[i];}

      ObjectCreate(ChartID(),string(i),OBJ_TEXT,0,time,Posit-(Text_Distance*0.0001));

      ObjectSetString(ChartID(),string(i),OBJPROP_TEXT,DoubleToString(Volume[i],0));
      //--- 
      ObjectSet(string(i),OBJPROP_ANGLE,270);
      //--- set color
      ObjectSetInteger(ChartID(),string(i),OBJPROP_COLOR,Text_Color);
      //--- set font size
      ObjectSetInteger(ChartID(),string(i),OBJPROP_FONTSIZE,Text_Size);
      //--- set anchor type
      ObjectSetInteger(ChartID(),string(i),OBJPROP_ANCHOR,anchor);
      //--- display in the foreground (false) or background (true)
      ObjectSetInteger(ChartID(),string(i),OBJPROP_BACK,Text_Background);
      //--- set text font
      ObjectSetString(ChartID(),string(i),OBJPROP_FONT,"Arial");

     }
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double TexePosition()
  {

   double LowestLow=1000000000000000;
   for(int i=0;i<Period_;i++)
     {

      if(iLow(Symbol(),PERIOD_CURRENT,i)<LowestLow)
        {
         LowestLow=iLow(Symbol(),PERIOD_CURRENT,i);
        }

     }

   return(LowestLow);
  }
//+------------------------------------------------------------------+
*/
 
Reza nasimi:

Hi 
I wrote an EA without sending/closing orders.

for now I just want EA show me some Comments and an alert.
It's not working well  and I can't find problems.





Funny part is if I put Bullish(Calculate_Bullish_Volume()) and bearish (Calculate_Bearish_Volume()) in the comment Bullish is stop working and returns 0.

But in a comment without bearish bullish is working.(however I think its not working perfectly)

its not the only problem of this EA.
please help me to find reasons and solutions.

I hope you understand my English  .
I know its not very easy ;)


All the parts will be using in this EA but I made some parts comment (gray  ) because I think they work well.


This doesn't provide the reason, but here are some ideas to simplify and shrink your code.

class BBvol
{
   datetime m_last_time;
   double   m_last_price;
public:
   int bear,bull;
   BBvol():bear(0),bull(0),m_last_time(Time[0]),m_last_price(Bid){}
   void Refresh()
   {
      if(m_last_time != Time[0])
      {
         m_last_time = Time[0];
         bear = 0;
         bull = 0;
      }
      if(Bid > m_last_price)
         bull++;
      else
      if(Bid < m_last_price)
         bear++;
      m_last_price = Bid;
   }
};
void OnTick()
{
   static BBvol vol;
   vol.Refresh();
   string res="";
   for(int i=13;i>=0;i--)
      res+= "   C"+string(i+1)+": "+string(Volume[i]);
   res+="\n\nBear volume = "+string(vol.bear);
   res+="\nBull volume = "+string(vol.bull);
   Comment(res);
}
 
nicholishen:

This doesn't provide the reason, but here are some ideas to simplify and shrink your code.


Thank you very much  Nicholishen.

your codes are  much more better . 

can you help also for timing ?

what do you think about my TimeDifference()

I'm not happy with it.
Reason: