Need help with XO clean_mtf + alerts + lines 2 indicator for call buffer problem in EA

#1
Do you know this indicator. XO clean_mtf + alerts + lines 2

Code: Select all

   //------------------------------------------------------------------
//------------------------------------------------------------------
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers    2
#property indicator_color1     LimeGreen
#property indicator_color2     PaleVioletRed
#property indicator_width1     2
#property indicator_width2     2
#property indicator_level1     0

//
//
//
//
//

extern ENUM_TIMEFRAMES TimeFrame         = PERIOD_CURRENT;
extern double          BoxPeriod         = 6.5;
extern bool            alertsOn          = true;
extern bool            alertsOnCurrent   = true;
extern bool            alertsMessage     = true;
extern bool            alertsSound       = false;
extern bool            alertsNotify      = true;
extern bool            alertsEmail       = true;
extern bool            ShowLines         = false;
extern string          LinesIdentifier   = "XOLines1";
extern color           LinesColorForUp   = LimeGreen;
extern color           LinesColorForDown = Red;
extern ENUM_LINE_STYLE LinesStyle        = STYLE_DOT;

//
//
//
//
//

double Hi[];
double Lo[];
double no[];
double kr[];
double trend[];

//
//
//
//
//

string indicatorFileName;
bool   returnBars;

//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------

int init()
{  
   IndicatorBuffers(5);   
      SetIndexBuffer(0,kr); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"XO Up");
      SetIndexBuffer(1,no); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,"XO Down");
      SetIndexBuffer(2,Hi);
      SetIndexBuffer(3,Lo);
      SetIndexBuffer(4,trend);

      //
      //
      //
      //
      //
      
         indicatorFileName = WindowExpertName();
         returnBars        = (TimeFrame==-99);
         TimeFrame         = MathMax(TimeFrame,_Period);

      //
      //
      //
      //
      //
      
   IndicatorShortName(timeFrameToString(TimeFrame)+" XO ("+DoubleToStr(BoxPeriod,2)+")");
   return(0);
}


//
//
//
//
//

int deinit()
{
   int lookForLength = StringLen(LinesIdentifier);
   for (int i=ObjectsTotal(); i>=0; i--)
      {
         string name = ObjectName(i);
         if (StringSubstr(name,0,lookForLength)==LinesIdentifier) ObjectDelete(name);
      }
   return(0);
}


//------------------------------------------------------------------
//
//------------------------------------------------------------------

int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-counted_bars,Bars-1);
           if (returnBars) { kr[0] = limit+1; return(0); }
         
   //
   //
   //
   //
   //
    
   if (TimeFrame == Period())
   {
     double pipMultiplier = 1; if(Digits==3 || Digits==5) pipMultiplier = 10;
     for(int i=limit; i>=0; i--)
     {         
        if (i>=(Bars-2)) { Hi[i+1]=Close[i]; Lo[i+1]=Close[i]; continue; }
           double cur      = Close[i];
                  Hi[i]    = Hi[i+1];
                  Lo[i]    = Lo[i+1];
                  no[i]    = no[i+1];
                  kr[i]    = kr[i+1];
                  trend[i] = trend[i+1];

                  if (cur > (Hi[i]+BoxPeriod*Point*pipMultiplier)) 
                  {
                       Hi[i]    = cur;
                       Lo[i]    = cur-BoxPeriod*Point*pipMultiplier;
                       kr[i]    = kr[i+1]+1;
                       no[i]    = 0;
                       trend[i] = 1;
                  }
                  if (cur < (Lo[i]-BoxPeriod*Point*pipMultiplier)) 
                  {
                       Lo[i]    = cur;
                       Hi[i]    = cur+BoxPeriod*Point*pipMultiplier;
                       no[i]    = no[i+1]-1;
                       kr[i]    = 0;
                       trend[i] = -1;
                  }
                  if (ShowLines)
                  {
                    deleteLine(i);
                       if (trend[i]!=trend[i+1])
                       if (trend[i]==1)
                             drawLine(i,LinesColorForUp);
                       else  drawLine(i,LinesColorForDown);
                  } 
      }                 
      manageAlerts();
      return(0);
   }
   
   //
   //
   //
   //
   //
   
   limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
   for (i=limit;i>=0;i--)
   {
      int y = iBarShift(NULL,TimeFrame,Time[i]);
         kr[i]    = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BoxPeriod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,false,0,y);
         no[i]    = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BoxPeriod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,false,1,y);
         trend[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BoxPeriod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,false,4,y);
         if (ShowLines)
         {
            deleteLine(i);
            if (trend[i]!=trend[i+1])
            if (trend[i]==1)
                  drawLine(i,LinesColorForUp);
            else  drawLine(i,LinesColorForDown);
         }                  
   }
   return(0);         
}

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

void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar] == 1) doAlert(whichBar,"up");
         if (trend[whichBar] ==-1) doAlert(whichBar,"down");
      }         
   }
}

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message =  StringConcatenate(timeFrameToString(_Period)+" "+Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," XO trend changed to ",doWhat);
          if (alertsMessage) Alert(message);
          if (alertsNotify)  SendNotification(StringConcatenate(Symbol(), Period() ," XO " +" "+message));
          if (alertsEmail)   SendMail(StringConcatenate(Symbol(),"XO "),message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}

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

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

void deleteLine(int i)
{
   ObjectDelete(LinesIdentifier+":"+Time[i]);
}
void drawLine(int i, color theColor)
{
   string name = LinesIdentifier+":"+Time[i];
   if (ObjectFind(name)<0)
       ObjectCreate(name,OBJ_VLINE,0,Time[i],0);
       ObjectSet(name,OBJPROP_COLOR,theColor);
       ObjectSet(name,OBJPROP_BACK,true);
       ObjectSet(name,OBJPROP_STYLE,LinesStyle);[img][/img]  
I like it signal .So I decide to call its buffer.
I call its timeframe variable in parameter because I want to use its timeframe function .
But in real running ,it has false signals .I run with 1DAY timeframe in 1HR chart .
In up signal ,all buy and Down signal all sell.
But sell also open in up signals.vise versa.
Why it happen.
Can someone help me.
It up and down histogram also has value in zero line.

but I call as

if( xxoup >0 && xxodn == 0 ) return(buy);
I not still understand why it produce false signal.

Please suggest me.What is problem .

I like this indicator to catch whole trend .So I need to get solution.
Screenshot_20.png
Screenshot_21.png
Screenshot_23.png


Re: Need help with XO clean_mtf + alerts + lines 2 indicator for call buffer problem in EA

#2
kyawswarlin wrote:
Wed Oct 28, 2020 3:51 am
Do you know this indicator. XO clean_mtf + alerts + lines 2

Code: Select all

   //------------------------------------------------------------------
//------------------------------------------------------------------
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers    2
#property indicator_color1     LimeGreen
#property indicator_color2     PaleVioletRed
#property indicator_width1     2
#property indicator_width2     2
#property indicator_level1     0

//
//
//
//
//

extern ENUM_TIMEFRAMES TimeFrame         = PERIOD_CURRENT;
extern double          BoxPeriod         = 6.5;
extern bool            alertsOn          = true;
extern bool            alertsOnCurrent   = true;
extern bool            alertsMessage     = true;
extern bool            alertsSound       = false;
extern bool            alertsNotify      = true;
extern bool            alertsEmail       = true;
extern bool            ShowLines         = false;
extern string          LinesIdentifier   = "XOLines1";
extern color           LinesColorForUp   = LimeGreen;
extern color           LinesColorForDown = Red;
extern ENUM_LINE_STYLE LinesStyle        = STYLE_DOT;

//
//
//
//
//

double Hi[];
double Lo[];
double no[];
double kr[];
double trend[];

//
//
//
//
//

string indicatorFileName;
bool   returnBars;

//------------------------------------------------------------------
//                                                                  
//------------------------------------------------------------------

int init()
{  
   IndicatorBuffers(5);   
      SetIndexBuffer(0,kr); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"XO Up");
      SetIndexBuffer(1,no); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,"XO Down");
      SetIndexBuffer(2,Hi);
      SetIndexBuffer(3,Lo);
      SetIndexBuffer(4,trend);

      //
      //
      //
      //
      //
      
         indicatorFileName = WindowExpertName();
         returnBars        = (TimeFrame==-99);
         TimeFrame         = MathMax(TimeFrame,_Period);

      //
      //
      //
      //
      //
      
   IndicatorShortName(timeFrameToString(TimeFrame)+" XO ("+DoubleToStr(BoxPeriod,2)+")");
   return(0);
}


//
//
//
//
//

int deinit()
{
   int lookForLength = StringLen(LinesIdentifier);
   for (int i=ObjectsTotal(); i>=0; i--)
      {
         string name = ObjectName(i);
         if (StringSubstr(name,0,lookForLength)==LinesIdentifier) ObjectDelete(name);
      }
   return(0);
}


//------------------------------------------------------------------
//
//------------------------------------------------------------------

int start()
{
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-counted_bars,Bars-1);
           if (returnBars) { kr[0] = limit+1; return(0); }
         
   //
   //
   //
   //
   //
    
   if (TimeFrame == Period())
   {
     double pipMultiplier = 1; if(Digits==3 || Digits==5) pipMultiplier = 10;
     for(int i=limit; i>=0; i--)
     {         
        if (i>=(Bars-2)) { Hi[i+1]=Close[i]; Lo[i+1]=Close[i]; continue; }
           double cur      = Close[i];
                  Hi[i]    = Hi[i+1];
                  Lo[i]    = Lo[i+1];
                  no[i]    = no[i+1];
                  kr[i]    = kr[i+1];
                  trend[i] = trend[i+1];

                  if (cur > (Hi[i]+BoxPeriod*Point*pipMultiplier)) 
                  {
                       Hi[i]    = cur;
                       Lo[i]    = cur-BoxPeriod*Point*pipMultiplier;
                       kr[i]    = kr[i+1]+1;
                       no[i]    = 0;
                       trend[i] = 1;
                  }
                  if (cur < (Lo[i]-BoxPeriod*Point*pipMultiplier)) 
                  {
                       Lo[i]    = cur;
                       Hi[i]    = cur+BoxPeriod*Point*pipMultiplier;
                       no[i]    = no[i+1]-1;
                       kr[i]    = 0;
                       trend[i] = -1;
                  }
                  if (ShowLines)
                  {
                    deleteLine(i);
                       if (trend[i]!=trend[i+1])
                       if (trend[i]==1)
                             drawLine(i,LinesColorForUp);
                       else  drawLine(i,LinesColorForDown);
                  } 
      }                 
      manageAlerts();
      return(0);
   }
   
   //
   //
   //
   //
   //
   
   limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period()));
   for (i=limit;i>=0;i--)
   {
      int y = iBarShift(NULL,TimeFrame,Time[i]);
         kr[i]    = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BoxPeriod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,false,0,y);
         no[i]    = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BoxPeriod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,false,1,y);
         trend[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,BoxPeriod,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsNotify,alertsEmail,false,4,y);
         if (ShowLines)
         {
            deleteLine(i);
            if (trend[i]!=trend[i+1])
            if (trend[i]==1)
                  drawLine(i,LinesColorForUp);
            else  drawLine(i,LinesColorForDown);
         }                  
   }
   return(0);         
}

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

void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1;
      if (trend[whichBar] != trend[whichBar+1])
      {
         if (trend[whichBar] == 1) doAlert(whichBar,"up");
         if (trend[whichBar] ==-1) doAlert(whichBar,"down");
      }         
   }
}

//
//
//
//
//

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //
       //
       //
       //
       //

       message =  StringConcatenate(timeFrameToString(_Period)+" "+Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," XO trend changed to ",doWhat);
          if (alertsMessage) Alert(message);
          if (alertsNotify)  SendNotification(StringConcatenate(Symbol(), Period() ," XO " +" "+message));
          if (alertsEmail)   SendMail(StringConcatenate(Symbol(),"XO "),message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}

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

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

void deleteLine(int i)
{
   ObjectDelete(LinesIdentifier+":"+Time[i]);
}
void drawLine(int i, color theColor)
{
   string name = LinesIdentifier+":"+Time[i];
   if (ObjectFind(name)<0)
       ObjectCreate(name,OBJ_VLINE,0,Time[i],0);
       ObjectSet(name,OBJPROP_COLOR,theColor);
       ObjectSet(name,OBJPROP_BACK,true);
       ObjectSet(name,OBJPROP_STYLE,LinesStyle);[img][/img]  
I like it signal .So I decide to call its buffer.
I call its timeframe variable in parameter because I want to use its timeframe function .
But in real running ,it has false signals .I run with 1DAY timeframe in 1HR chart .
In up signal ,all buy and Down signal all sell.
But sell also open in up signals.vise versa.
Why it happen.
Can someone help me.
It up and down histogram also has value in zero line.

but I call as

if( xxoup >0 && xxodn == 0 ) return(buy);
I not still understand why it produce false signal.

Please suggest me.What is problem .

I like this indicator to catch whole trend .So I need to get solution.
Without seeing your iCustom call, have no idea.

Re: Need help with XO clean_mtf + alerts + lines 2 indicator for call buffer problem in EA

#3
Finally I get one response from forum.Thanks you.
Here is my custom call for

Code: Select all

extern ENUM_TIMEFRAMES TimeFrame         = PERIOD_CURRENT;
 SetIndexBuffer(0,kr); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"XO Up");
      SetIndexBuffer(1,no); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,"XO Down");
      SetIndexBuffer(2,Hi);
      SetIndexBuffer(3,Lo);
      SetIndexBuffer(4,trend);

double xxoup = iCustom(NULL,0,"XO clean_mtf + alerts + lines nmc",TimeFrame,0,0);
double xxodn = iCustom(NULL,0,"XO clean_mtf + alerts + lines nmc",TimeFrame,1,0);
if( xxoup >0 && xxodn == 0 ) return(buy);
if( xxodn <0 && xxodn == 0 ) return(sell);

I use timeframe 1DAY in 1HR Chart.
It make false singnal that mean sell in blue box (XO UP)and sometime buy in red box(XO DOWN).
I want is to sell in all red box and buy in all blue box.
Wrong buffer calling?
also need to call buffer 2 and 3 to show up and down direction.