Download MetaTrader 5
To add comments, please log in or register
MQL5 language supports OpenCL. Try it!
macdulio_
37
macdulio_ 2016.09.05 08:02 
#property copyright "Copyright 2016, Macdulio"
#property link "macdulio.blogspot.co.uk"


#property indicator_buffers 7
#property indicator_color1 Crimson
#property indicator_color2 Blue
#define  NL    "\n"
extern int       Range_n=34;
extern int shift = 5;
extern double Lots=48;
double HiBuffer[],LoBuffer[];
    double open_price[];
       double stop_loss_price[];
  double take_profit_price[];  
double buy[];
double sell[];
double ramp[];
double UR[];
double DR[];
double URE[];
double BE[];
double SE[];
double SE60[];
double BU[];
double BU60[];
  int Hi20[];
  int Lo20[]; 
extern int Target = 13;
extern int StopLoss = 27; 
 int bars_count = 20;  
  double HPR[];
  double LPR[];
  double LCR[];
  double HCR[];
  double bline[];
  double sline[];

int init()
  {
  
   SetIndexBuffer(0,buy);
   SetIndexStyle(0,DRAW_LINE,2,4,Green);
   SetIndexLabel(0, "Highest(" + DoubleToStr(Range_n,0)+")");

   SetIndexBuffer(1,sell);
   SetIndexStyle(1,DRAW_LINE,2,4,Red);
   SetIndexLabel(1, "Lowest(" + DoubleToStr(Range_n,0)+")");
   
   SetIndexStyle(2,DRAW_ARROW,EMPTY,3,Purple);
   SetIndexArrow(2,254);
   SetIndexBuffer(2,take_profit_price);
   SetIndexEmptyValue(2,0.0);
   
   SetIndexStyle(3,DRAW_ARROW,EMPTY,3,Red);
   SetIndexArrow(3,253);
   SetIndexBuffer(3,stop_loss_price);
   SetIndexEmptyValue(3,0.0);
   
//   SetIndexStyle(4,DRAW_ARROW,EMPTY,3,DarkGreen);
   SetIndexArrow(4,200);
   SetIndexBuffer(4,LCR);
   SetIndexEmptyValue(4,0.0);
   
//   SetIndexStyle(5,DRAW_ARROW,EMPTY,3,Crimson);
   SetIndexArrow(5,202);
   SetIndexBuffer(5,HCR);
   SetIndexEmptyValue(5,0.0);


   SetIndexStyle(6,DRAW_ARROW,EMPTY,5,MidnightBlue);
   SetIndexArrow(6,224);
   SetIndexBuffer(6,open_price);
   SetIndexEmptyValue(6,0.0);

  
//----
   return(0);
  }


int start()
  {
   int    i, j, k, counter, counterh, counterl, bucounter, secounter, h66, l33, h20, l20;     

  double iHi[];
  double iLo[]; 
  double xHi[];
  double xLo[];  
  int SPRD[];  


  string symbol = Symbol();
  ArrayResize(open_price, Bars);
  ArrayResize(stop_loss_price, Bars);
  ArrayResize(take_profit_price, Bars); 
  
  ArrayResize(buy, Bars);
  ArrayResize(sell, Bars);
  ArrayResize(ramp, Bars);
  
  ArrayInitialize(open_price, 0);
    ArrayInitialize(stop_loss_price, 0);
    ArrayInitialize(take_profit_price, 0);
    
    
  ArrayInitialize(buy, 0);
  ArrayInitialize(sell, 0);
  ArrayInitialize(ramp, 0);      
  ArrayResize(iHi, Bars);
  ArrayResize(iLo, Bars);
  ArrayInitialize(iHi, 0);
  ArrayInitialize(iLo, 0);     
  ArrayResize(xHi, Bars);
  ArrayResize(xLo, Bars);
  ArrayInitialize(xHi, 0);
  ArrayInitialize(xLo, 0);   
  ArrayResize(UR, Bars); 
  ArrayInitialize(UR, 0);    
  ArrayResize(DR, Bars); 
  ArrayInitialize(DR, 0);       
  ArrayResize(URE, Bars); 
  ArrayInitialize(URE, 0);
  ArrayResize(SE, Bars); 
  ArrayInitialize(SE, 0);  
  ArrayResize(BE, Bars); 
  ArrayInitialize(BE, 0);   
  ArrayResize(BU, Bars); 
  ArrayInitialize(BU, 0);     
  ArrayResize(SE60, Bars); 
  ArrayInitialize(SE60, 0);      
  ArrayResize(BU60, Bars); 
  ArrayInitialize(BU60, 0);     
  ArrayResize(SPRD, Bars); 
  ArrayInitialize(SPRD, 0);    
  ArrayResize(Hi20, Bars);
  ArrayResize(Lo20, Bars);
  ArrayInitialize(Hi20, 0);
  ArrayInitialize(Lo20, 0);       
   
  ArrayResize(LPR, Bars); 
  ArrayInitialize(LPR, 0); 
  ArrayResize(HPR, Bars); 
  ArrayInitialize(HPR, 0); 
  
  
  ArrayResize(LCR, Bars); 
  ArrayInitialize(LCR, 0); 
  ArrayResize(HCR, Bars); 
  ArrayInitialize(HCR, 0);
  
   double distance;
  double lowest_price;
  double highest_price;
        
//--------------------------------------------------------------------

   double lots=Lots;
      
lowest_price = Low[iLowest(NULL, 0, MODE_LOW, 1,1)];
//highest_price =  High[iHighest(NULL, 5, MODE_HIGH, bars_count)];
highest_price =  High[iHighest(NULL, 0, MODE_HIGH, 1,1)];
distance = iHighest(NULL,0,MODE_HIGH,22,1)- iLowest(NULL,0,MODE_LOW,22,1); 

  for (i = Bars ; i >= 0; i--) {
    iHi[i]=iHighest(NULL,0,MODE_HIGH,Range_n,i);
    iLo[i]=iLowest(NULL,0,MODE_LOW,Range_n,i); }
   
   

   
   
   h66=0;
   l33=0;
         h20=0;
   l20=0;
   for (i = 0 ; i <= 100; i++) {    
      if (iRSI(Symbol(),0,6,PRICE_CLOSE,i)<63  && iRSI(Symbol(),0,6,PRICE_CLOSE,i+1)>63) { h66 = h66+1; HCR[i]=High[i]+5*Point;}
      if (iRSI(Symbol(),0,6,PRICE_CLOSE,i)>33  && iRSI(Symbol(),0,6,PRICE_CLOSE,i+1)<33) { l33 = l33+1; LCR[i]=Low[i]-5*Point;}

 
   j=20; 
   while(j>=0){
     if (iRSI(Symbol(),0,6,PRICE_CLOSE,j)<66 && iRSI(Symbol(),0,6,PRICE_CLOSE,i+1)>66) h20 = h20+1;
     if (iRSI(Symbol(),0,6,PRICE_CLOSE,j)>33 && iRSI(Symbol(),0,6,PRICE_CLOSE,i+1)>33) l20 = l20+1;
    j--;
   }     


            counterh = 0; counterl=0;
               for (k = i+20 ; k >= i+0; k--) {    
             if (HCR[k]>0)  counterh=counterh+1; 
             if (LCR[k]>0)  counterl=counterl+1;
             if (counterh==1) Hi20[k]=High[k];
             if (counterl==1) Lo20[k]=Low[k];
            }



     }   
      
      HPR[0]=h66;
   LPR[0]=l33;
  
               for (j = 20 ; j >= 0; j--) {    
           //     if (Hi20[j]>0 && counterl==0) sell[j]=Low[j]-5*Point;
            //     if (Lo20[j]>0 && counterh==0) buy[j]=High[j]+5*Point;
              
             if (Lo20[j]>0 && counterl==0 && High[j+1]>High[j] && High[j+1]-(High[j+1]-Low[j+1])/2>High[j]) bline[j]=High[j+1]-(High[j+1]-Low[j+1])/2+2*Point; else
                  if (Lo20[j]>0 && counterl==0 && High[j+1]>High[j] && High[j+1]>High[j]) bline[j]=High[j+1]+2*Point; else  bline[i]=bline[i+1]; 
                  
           
             
      //       if (LCR[j]>0 && h66<2 && l33>2) buy[j]=High[j]+7*Point;
   
      }    


   if(Bars<Range_n) return(0);
   i=Bars-Range_n-3; 

    for (i = Bars ; i >= 0; i--) {                   // Loop for uncounted bars
   

      xHi[i]=iHigh(NULL,0,iHi[i]); 
      xLo[i]=iLow(NULL,0,iLo[i]);
      if (Lo20[i]>0 && counterl<1 && High[i+1]>High[i] && High[i+1]-(High[i+1]-Low[i+1])/2>High[i])
          HiBuffer[i]=High[i+1]-(High[i+1]-Low[i+1])/2+2*Point;  
          else if (Lo20[i]>0 && counterl<1 && High[i+1]>High[i])   
                   HiBuffer[i]=High[i+1]+2*Point;  
                      else if (HiBuffer[i+1]!=HiBuffer[i+9]) HiBuffer[i] = HiBuffer[i+1];
                      else  HiBuffer[i] = 0;
                      
       //               else  HiBuffer[i] =  HiBuffer[i+1];
      if (Hi20[i]>0 && counterh<1 && Low[i+1]<Low[i] && High[i+1]-(High[i+1]-Low[i+1])/2<Low[i])
          LoBuffer[i]=High[i+1]-(High[i+1]-Low[i+1])/2-2*Point;
          else if (Hi20[i]>0 && counterh<1 && Low[i+1]<Low[i])
                   LoBuffer[i] = LoBuffer[i+1]-2*Point;  
     
                           else if (LoBuffer[i+1]!=LoBuffer[i+9]) LoBuffer[i] = LoBuffer[i+1];
                          else LoBuffer[i] = 1000;                   
    //                    else LoBuffer[i] = LoBuffer[i+1];  
    
    }   
  
         if ((Hour()>6 && Hour()<15)|| (Hour()>17 && Hour()<22) 
  //             &&iRSI(NULL,60,9,PRICE_CLOSE,0)>45
               &&iClose(Symbol(),0,0)>iClose(Symbol(),1440,2)
  //             &&Close[0]> iMA(Symbol(),1440,2,0,MODE_EMA,PRICE_OPEN,0)
               &&iStochastic(NULL,1440,6,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,1440,6,3,3,MODE_SMA,0,MODE_SIGNAL,0)
  //             &&iStochastic(NULL,240,6,1,1,MODE_SMA,0,MODE_MAIN,1)>iStochastic(NULL,5,6,1,1,MODE_SMA,0,MODE_MAIN,0)
               && iClose(Symbol(),30,1)> iClose(Symbol(),30,0)
 //           &&iClose(Symbol(),0,1)>iMA(Symbol(),0,50,0,MODE_SMA,PRICE_OPEN,0)
  //          && iClose(Symbol(),0,1)>iMA(Symbol(),0,188,0,MODE_EMA,PRICE_OPEN,0)
  //         &&iClose(Symbol(),0,1)>iMA(Symbol(),0,8,0,MODE_SMA,PRICE_OPEN,0&&iClose(Symbol(),0,1)>iMA(Symbol(),0,21,0,MODE_EMA,PRICE_OPEN,0)&&iMA(Symbol(),0,188,0,MODE_EMA,PRICE_OPEN,0)>iMA(Symbol(),0,2100,0,MODE_EMA,PRICE_OPEN,0)
 //           &&iClose(Symbol(),1440,0)<iHigh(Symbol(),1440,1)-(iHigh(Symbol(),1440,1)-iLow(Symbol(),1440,1))/3
            &&iMACD(NULL,240,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>0
            &&iClose(Symbol(),1440,0)>iClose(Symbol(),1440,1))
{            
HPR[0] = High[iHighest(NULL, 5, MODE_HIGH, bars_count)]; 
distance = highest_price-lowest_price;}

LPR[0] = Low[iLowest(NULL, 5, MODE_LOW, bars_count,1)];   
    
    counter = 0; 
   i=Bars-Range_n-60;   
   while(i>=0)                      
   {
     
  //    if (LoBuffer[i+1]<=LoBuffer[i+16] && HiBuffer[i+1]<=HiBuffer[i+16]) 
 //    if (High[i+1]>iHi[i+1]&&Close[i+1]>Open[i+1]&&Close[i+2]>Open[i+2]) 
 //     sell[i]=HiBuffer[i]; 
     if (Open[i+1]<High[i+1]-(High[i+1]-Low[i+1])*.55 && Close[i+1]<High[i+1]-(High[i+1]-Low[i+1])*.55  
     && !(Open[i+2]>High[i+2]-(High[i+2]-Low[i+2])*.55 && Close[i+2]>High[i+2]-(High[i+2]-Low[i+2])*.55)
     && !(Open[i+3]>High[i+3]-(High[i+3]-Low[i+3])*.55 && Close[i+3]>High[i+3]-(High[i+3]-Low[i+3])*.55)
     && !(Open[i+4]>High[i+4]-(High[i+4]-Low[i+4])*.55 && Close[i+4]>High[i+4]-(High[i+4]-Low[i+4])*.55)
     
     && Open[i+1]!=Close[i+1] && High[i+1]-Low[i+1]>11*Point) SE[i]=High[i+1]+5*Point; 
     
     
          if (Open[i+1]>High[i+1]-(High[i+1]-Low[i+1])*.55 && Close[i+1]>High[i+1]-(High[i+1]-Low[i+1])*.55  
     && !(Open[i+2]<High[i+2]-(High[i+2]-Low[i+2])*.55 && Close[i+2]<High[i+2]-(High[i+2]-Low[i+2])*.55)
     && !(Open[i+3]<High[i+3]-(High[i+3]-Low[i+3])*.55 && Close[i+3]<High[i+3]-(High[i+3]-Low[i+3])*.55)
     && !(Open[i+4]<High[i+4]-(High[i+4]-Low[i+4])*.55 && Close[i+4]<High[i+4]-(High[i+4]-Low[i+4])*.55)
     
     && Open[i+1]!=Close[i+1] && High[i+1]-Low[i+1]>11*Point) BU[i]=Low[i+1]-5*Point; 
 
    
 
       if (LoBuffer[i+1]<=LoBuffer[i+16] && LoBuffer[i+1]<=LoBuffer[i+32] && HiBuffer[i+1]<=HiBuffer[i+16] ) {  
      if ((Low[i+1]<LoBuffer[i+2]||Low[i+2]<LoBuffer[i+3])
      &&buy[i+1]==0&&buy[i+2]==0&&buy[i+3]==0&&buy[i+4]==0
    &&Close[i+1]>LoBuffer[i+1]-2*shift*Point
             &&Open[i+2]>Low[i+2]+(High[i+2]-Low[i+2])*.5
         &&Close[i+1]<Open[i+1]&&Close[i+2]<Open[i+2] &&Open[0]<(Low[1]+(High[1]-Low[1])*1.4)&&(Close[3]>Open[3]||Close[4]>Open[4]||Close[5]>Open[5])

       
       )
       
        BU60[0]=0;
        SE60[0]=0;
       bucounter = 0;
       secounter = 0;
   
       for (j = i ; j <= Range_n-60; j++) {    
         if (BU[j]>0) bucounter = bucounter+1;
         if (SE[j]>0) secounter = secounter+1;
         BU60[j]=bucounter;
         SE60[j]=secounter;
       }
       
                if (Hi20[i]>0 && counterl==0  && High[i]-Low[i]<25*Point
              
          ) sell[i]=Ask; else sell[i]=0;
      
      
               if (Lo20[i]>0 && counterh==0 && High[i]-Low[i]<30*Point
   
         ) buy[i]=Ask; else buy[i]=0;
 
      
        if (buy[i] > 0 
        
        && buy[i+1]==0  
             &&iMA(Symbol(),0,14,0,MODE_EMA,PRICE_OPEN,0)>iMA(Symbol(),0,14,0,MODE_SMA,PRICE_OPEN,44)
             &&iMA(Symbol(),30,2,0,MODE_SMA,PRICE_OPEN,0)>iMA(Symbol(),30,4,0,MODE_SMA,PRICE_OPEN,0)
             &&!(iMA(Symbol(),1440,2,0,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),1440,4,0,MODE_SMA,PRICE_CLOSE,0)&&iMA(Symbol(),1440,21,0,MODE_SMA,PRICE_CLOSE,0)<iMA(Symbol(),1440,34,0,MODE_SMA,PRICE_CLOSE,0)&&iMA(Symbol(),1440,34,0,MODE_SMA,PRICE_CLOSE,0)<iMA(Symbol(),1440,55,0,MODE_SMA,PRICE_CLOSE,0)&&iMA(Symbol(),1440,2,0,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),1440,21,0,MODE_SMA,PRICE_CLOSE,0))
             && (iMACD(Symbol(),30,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>0.000500  || iMACD(Symbol(),30,12,26,9,PRICE_CLOSE,MODE_MAIN,0)<-0.000500) 

  ) { open_price[i] = High[i+1]+2*Point;
      stop_loss_price[i] = NormalizeDouble(open_price[i] - ((StopLoss-MarketInfo(Symbol(), MODE_SPREAD)) * Point), Digits);
      take_profit_price[i] = NormalizeDouble(open_price[i] + ((Target+MarketInfo(Symbol(), MODE_SPREAD)) * Point), Digits);}
 
 
  
  if (sell[i]>0 && sell[i+1]==0  
    &&iMA(Symbol(),0,14,0,MODE_EMA,PRICE_OPEN,0)<iMA(Symbol(),0,14,0,MODE_SMA,PRICE_OPEN,55)
  &&!(iMA(Symbol(),1440,2,0,MODE_SMA,PRICE_OPEN,0)>iMA(Symbol(),1440,55,0,MODE_SMA,PRICE_OPEN,44)&&iMA(Symbol(),1440,4,0,MODE_SMA,PRICE_OPEN,0)<iMA(Symbol(),1440,55,0,MODE_SMA,PRICE_OPEN,44))
  )  {  open_price[i] = Low[i+1]-2*Point;
       stop_loss_price[i] = NormalizeDouble(open_price[i] + ((StopLoss-MarketInfo(Symbol(), MODE_SPREAD)) * Point), Digits);
       take_profit_price[i] = NormalizeDouble(open_price[i]  - ((Target+MarketInfo(Symbol(), MODE_SPREAD)) * Point), Digits);
     } 
 
 
              } 
         i--;
 }
           
   for (i = 0 ; i <= Range_n-60; i++) {           
    
        
       

  
}  
  
    return(0);
  }
//+------------------------------------------------------------------+
Keith Watford
Moderator
9597
Keith Watford 2016.09.05 09:11  
What objects? There are no objects created in your code.
macdulio_
37
macdulio_ 2016.09.05 09:37  
GumRai:
What objects? There are no objects created in your code.
Drawings I mean
Keith Watford
Moderator
9597
Keith Watford 2016.09.05 09:40  

Show the section of code that creates the objects, I can't see where.

Check that Objects are not deleted in DeInit.

macdulio_
37
macdulio_ 2016.09.05 09:59  
Before

 

The drawings are plotted most of the time, but sometimes they disappear. Is this a screen bug or is there something wrong with the code? Some array goes empty? It happens after a screen shift.

 

After 

Keith Watford
Moderator
9597
Keith Watford 2016.09.05 10:22  

As per my previous post

GumRai:

Show the section of code that creates the objects, I can't see where.

Check that Objects are not deleted in DeInit.

macdulio_
37
macdulio_ 2016.09.05 10:32  
GumRai:

As per my previous post

As per my previous post, 

Drawings I mean

Keith Watford
Moderator
9597
Keith Watford 2016.09.05 11:20  
macdulio_:

As per my previous post, 

Drawings I mean

You have edited your previous post, so I didn't see it.

Before you edited your post, you had a screenshot of the Objects list.

The drawings in mq4 are referred to as Objects, or buffers.

As you are obviously not prepared to show the code that creates the objects or check in DeInit to see if the objects are being deleted, there's not much that we can offer in advice

whroeder1
14457
whroeder1 2016.09.05 13:03  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Half of your code takes values from bar "i" and half from bar one. What you have is total nonsense. That is why.
macdulio_
37
macdulio_ 2016.09.05 14:38  
GumRai:

You have edited your previous post, so I didn't see it.

Before you edited your post, you had a screenshot of the Objects list.

The drawings in mq4 are referred to as Objects, or buffers.

As you are obviously not prepared to show the code that creates the objects or check in DeInit to see if the objects are being deleted, there's not much that we can offer in advice

Dude,

There is no other code.

You do not seem to want to help me.

Forgive me for not knowing the definition of objects in the case of MT4. 

 

Initially I thought that these drawings were listed on the objects list. They weren't.

Fernando Carreiro
2353
Fernando Carreiro 2016.09.05 15:02  
macdulio_:

Dude,

There is no other code.

You do not seem to want to help me.

Forgive me for not knowing the definition of objects in the case of MT4.

Initially I thought that these drawings were listed on the objects list. They weren't.

Dude, it seems that you are the one that is not understanding things and not being totally forthcoming!

The "drawings" as you call them are called "Graphical Chart Objects" or "Objects" for short, and they are created either by code using the function "ObjectCreate()" or manually when you add them yourself to a chart.

Yes, they are listed in the Objects List, but some may be hidden and so you have to click on the "List All" to see the full list.

However, in the code that you have provided, there are neither any "ObjectCreate()" functions nor any "ObjectDelete()" functions, so the code you have shown does not create nor remove any of those Objects ("drawings" as you call them).

So, that means that, they are either created or deleted by OTHER code and not the part that you have shown or that you have other 3rd party things running that you are have not mentioned. Your screenshots show that your chart has an EA attached, called "Turn_Around_RSI_4_Greg_E_sharpER_NE_LR2", so consider the fact that those Objects (drawings) are being generated and deleted by that EA.

PS! When adding code, please use the SRC button (the toolbar) in order to properly format it. So please, go back to your initial post, edit it, and replace your code using the SRC button so that it can be more readable.

/ /12
To add comments, please log in or register