Wrong Assignment in MQL5 Libarary(m_base_price)

 

In object filter, it's impossiable to assign m_base_price in object m_signal.

//+------------------------------------------------------------------+ //| Generating a buy signal.                                         | //| INPUT:  price      - reference for placing the price of opening, | //|         sl         - reference for placing the stop loss price,  | //|         tp         - reference for the take profit price,        | //|         expiration - reference for placing the expiration time.  | //| OUTPUT: true if there is a signal, otherwise - false.            | //| REMARK: no.                                                      | //+------------------------------------------------------------------+ bool CExpertSignal::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)   {    bool   result   =false;    double direction=Direction(); //m_signal.CheckOpenLong is calling m_signal.Direction() //--- the "prohibition" signal    if(direction==EMPTY_VALUE) return(false); //--- check of exceeding the threshold value    if(direction>=m_threshold_open)      {       //--- there's a signal       result=true;       //--- try to get the levels of opening       if(!OpenLongParams(price,sl,tp,expiration)) result=false;      } //--- zeroize the base price    m_base_price=0.0; //m_signal.m_base_price is zeroized to 0.0 //--- return the result    return(result);   }


//+------------------------------------------------------------------+
//| Detecting the "weighted" direction.                              |
//| INPUT:  no.                                                      |
//| OUTPUT: >0 - if the probability of price growth is greater,      |
//|         =0 - if the direction is not determined                  |
//|              (small probability),                                |
//|         <0 - if the probability of price falling is greater.     |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
double CExpertSignal::Direction()
  {
   CExpertSignal *filter;
   long           mask;
   double         direction;
   double         result=m_weight*(LongCondition()-ShortCondition());
   int            number=0;      // number of "voted"
//---
   int            total=m_filters.Total();
//--- for debugging
//printf(__FUNCTION__+" : %s %d",EnumToString(m_period),total);
//--- loop by filters
   for(int i=0;i<total;i++)
     {
      //--- mask for bit maps
      mask=((long)1)<<i;
      //--- check of the flag of ignoring the signal of filter
      if((m_ignore&mask)!=0) continue;
      filter=m_filters.At(i);
      direction=filter.Direction();                                    //m_signal.Direction() is calling filer.Direction()
      //--- the "prohibition" signal
      if(direction==EMPTY_VALUE) return(EMPTY_VALUE);
      //--- check of flag of inverting the signal of filter
      if((m_invert&mask)!=0) result-=direction;
      else                   result+=direction;
      number++;
     }
//--- normalization
   if(number!=0) result/=number;
//--- return the result
   return(result);
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Detecting the "weighted" direction.                              |
//| INPUT:  no.                                                      |
//| OUTPUT: >0 - if the probability of price growth is greater,      |
//|         =0 - if the direction is not determined                  |
//|              (small probability),                                |
//|         <0 - if the probability of price falling is greater.     |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
double CExpertSignal::Direction()
  {
   CExpertSignal *filter;
   long           mask;
   double         direction;
   double         result=m_weight*(LongCondition()-ShortCondition());         //filter.Direction is calling filter.LongCondition()


//+------------------------------------------------------------------+
//| "Voting" that price will grow.                                   |
//| INPUT:  no.                                                      |
//| OUTPUT: number of "votes" that price will grow.                  |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
int CSignalMA::LongCondition()
  {
   int result=0;
   int idx   =StartIndex();
//--- analyze positional relationship of the close price and the indicator at the first analyzed bar
   if(DiffCloseMA(idx)<0.0)
     {
      //--- the close price is below the indicator
      if(IS_PATTERN_USAGE(1) && DiffOpenMA(idx)>0.0 && DiffMA(idx)>0.0)
        {
         //--- the open price is above the indicator (i.e. there was an intersection), but the indicator is directed upwards
         result=m_pattern_1;
         //--- consider that this is an unformed "piercing" and suggest to enter the market at the current price
         m_base_price=0.0;                                                      //filter.m_base_price is assigned to 0.0,  but this should be m_signal.m_base_price
        }
     }
   else
     {
      //--- the close price is above the indicator (the indicator has no objections to buying)
      if(IS_PATTERN_USAGE(0))
         result=m_pattern_0;
      //--- if the indicator is directed upwards
      if(DiffMA(idx)>0.0)
        {
         if(DiffOpenMA(idx)<0.0)
           {
            //--- if the model 2 is used
            if(IS_PATTERN_USAGE(2))
              {
               //--- the open price is below the indicator (i.e. there was an intersection)
               result=m_pattern_2;
               //--- suggest to enter the market at the "roll back"
               m_base_price=m_symbol.NormalizePrice(MA(idx));     //filter.m_base_price is assigned to 0.0,  but this should be m_signal.m_base_price           
              }
           }
         else
           {
            //--- if the model 3 is used and the open price is above the indicator
            if(IS_PATTERN_USAGE(3) && DiffLowMA(idx)<0.0)
              {
               //--- the low price is below the indicator
               result=m_pattern_3;
               //--- consider that this is a formed "piercing" and suggest to enter the market at the current price
               m_base_price=0.0;                              //filter.m_base_price is assigned to 0.0,  but this should be m_signal.m_base_price                                     
              }
           }
        }
     }
//--- return the result
   return(result);
  }


//+------------------------------------------------------------------+
//| Detecting the levels for buying .                                |
//| INPUT:  price      - reference for placing the price of opening, |
//|         sl         - reference for placing the stop loss price,  |
//|         tp         - reference for the take profit price,        |
//|         expiration - reference for placing the expiration time.  |
//| OUTPUT: true in case of successful execution, otherwise - false. |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CExpertSignal::OpenLongParams(double& price,double& sl,double& tp,datetime& expiration)
  {
   CExpertSignal *general=NULL;
   if(m_general!=-1) general=m_filters.At(m_general);
//---
   if(general==NULL)
     {
      //--- if a base price is not specified explicitly, take the current market price
      if(m_base_price==0.0) m_base_price=m_symbol.Ask();                        //This variable m_base_price is  declared in object m_signal, not in filter.
      price      =m_symbol.NormalizePrice(m_base_price-m_price_level*PriceLevelUnit());
      sl         =(m_stop_level==0.0)?0.0:m_symbol.NormalizePrice(price-m_stop_level*PriceLevelUnit());
      tp         =(m_take_level==0.0)?0.0:m_symbol.NormalizePrice(price+m_take_level*PriceLevelUnit());
      expiration+=m_expiration*PeriodSeconds(m_period);
     }
   else
     {
      return(general.OpenLongParams(price,sl,tp,expiration));
     }
//--- ok
   return(true);
  }
 
kwang1:


The solution should be :
double CExpertSignal::Direction()
->
double CExpertSignal::Direction(double& base_price)

and

int CSignalMA::LongCondition()
->
int CSignalMA::LongCondition(double& base_price)

Is it correct???



Files:
 
kwang1:


//+------------------------------------------------------------------+
//| Generating a buy signal.                                         |
//| INPUT:  price      - reference for placing the price of opening, |
//|         sl         - reference for placing the stop loss price,  |
//|         tp         - reference for the take profit price,        |
//|         expiration - reference for placing the expiration time.  |
//| OUTPUT: true if there is a signal, otherwise - false.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CExpertSignal::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)
  {
   bool   result   =false;
   double direction=Direction(m_base_price);
   printf("1111,%f",m_base_price);
//--- the "prohibition" signal
   if(direction==EMPTY_VALUE) return(false);
//--- check of exceeding the threshold value
   if(direction>=m_threshold_open)
     {
      //--- there's a signal
      result=true;
      //--- try to get the levels of opening
      if(!OpenLongParams(price,sl,tp,expiration)) result=false;
     }
//--- zeroize the base price
   m_base_price=0.0;
//--- return the result
   return(result);
  }
//+------------------------------------------------------------------+
//| Detecting the "weighted" direction.                              |
//| INPUT:  no.                                                      |
//| OUTPUT: >0 - if the probability of price growth is greater,      |
//|         =0 - if the direction is not determined                  |
//|              (small probability),                                |
//|         <0 - if the probability of price falling is greater.     |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
double CExpertSignal::Direction(double& price)
  {
   CExpertSignal *filter;
   long           mask;
   double         direction;
   double         result=m_weight*(LongCondition(price)-ShortCondition(price));
   int            number=0;      // number of "voted"
//---
   int            total=m_filters.Total();
//--- for debugging
//printf(__FUNCTION__+" : %s %d",EnumToString(m_period),total);
//--- loop by filters
   for(int i=0;i<total;i++)
     {
      //--- mask for bit maps
      mask=((long)1)<<i;
      //--- check of the flag of ignoring the signal of filter
      if((m_ignore&mask)!=0) continue;
      filter=m_filters.At(i);
      direction=filter.Direction(price);
      //--- the "prohibition" signal
      if(direction==EMPTY_VALUE) return(EMPTY_VALUE);
      //--- check of flag of inverting the signal of filter
      if((m_invert&mask)!=0) result-=direction;
      else                   result+=direction;
      number++;
     }
//--- normalization
   if(number!=0) result/=number;
//--- return the result
   return(result);
  }
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| "Voting" that price will fall.                                   |
//| INPUT:  no.                                                      |
//| OUTPUT: number of "votes" that price will fall.                  |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
int CSignalStoch::ShortCondition(double& price)
  {
   int result=0;
   int idx   =StartIndex();
   //--- check direction of the main line
   if(DiffMain(idx)<0.0)
     {
      //--- main line is directed downwards, confirming a possibility of falling of price
      if(IS_PATTERN_USAGE(0))
         result=m_pattern_0;      // "confirming" signal number 0
      //--- if the model 1 is used, look for a reverse of the main line
      if(IS_PATTERN_USAGE(1) && DiffMain(idx+1)>0.0)
         result=m_pattern_1;      // signal number 1
      //--- if the model 2 is used, look for an intersection of the main and signal line
      if(IS_PATTERN_USAGE(2) && DiffMainSignal(idx)<0.0 && DiffMainSignal(idx+1)>0.0)
         result=m_pattern_2;      // signal number 2
      //--- if the models 3 or 4 are used, look for divergences
      if((IS_PATTERN_USAGE(3) || IS_PATTERN_USAGE(4)))
        {
         //--- perform the extended analysis of the oscillator state
         ExtStateStoch(idx);
         //--- if the model 3 is used, look for the "divergence" signal
         if(IS_PATTERN_USAGE(3) && CompareMaps(1,1))      // 0000 0001b
            result=m_pattern_3;   // signal number 3
         //--- if the model 4 is used, look for the "double divergence" signal
         if(IS_PATTERN_USAGE(4) && CompareMaps(0x11,2))   // 0001 0001b
            return(m_pattern_4);  // signal number 4
        }
     }
     price=20;
//--- return the result
   return(result);
  }
 
kwang1:




Everything was done as planned.