Download MetaTrader 5
To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
Black_Jack822
57
Black_Jack822 2016.03.04 10:27 
Hi All. I have a script which makes a "screenshot" with assigned "hotkey" to it and I'm trying to combine this "hotkey" with Stochastic alert indicator to get a screenshot whenever stochastic arrow/signal appears on the screen.
At the moment it makes a screenshot when I switch between time frames and stochastic signal is already on the screen but it doesn't when fresh arrow/signal pops up on the screen.
Can someone tell me please what I've done wrong?

Regards.


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1  Yellow
#property indicator_color2  Yellow
#property indicator_width1  1
#property indicator_width2  1
//----
extern bool    SoundON=true;
extern int     MaximumBars=100;
extern int     ArrowUP = 217;
extern int     ArrowDOWN = 218;
extern int     Sgnal_gap1 = 1;

//---- input parameters
extern int KPeriod=14;
extern int DPeriod=3;
extern int Slowing=9;
extern int MA_Method=0;  
extern int PriceField=1;  
extern int OverBoughtLevel  =85;
extern int OverSoldLevel    =15;
extern double Sgnal_gap        =0.5;
extern bool show_KD_cross=false;
extern bool show_K_OBOScross=true;
extern bool show_D_OBOScross=false;
 
double CrossUp[];
double CrossDown[];
int flagval1=0;
int flagval2=0;
string AlertPrefix;
 
//+----------------------------PRINTSCREEN--------------------------------------+
#import "user32.dll"
void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);
#define  VK_Z 0x5A                
#define  VK_MENU 0x12               
#define  KEYEVENTF_KEYUP 0x0002    
//+-----------------------------------------------------------------------------+

string GetTimeFrameStr() 
{
   switch(Period())
   {
      case 1 : string TimeFrameStr="1M"; break;
      case 5 :  TimeFrameStr="5M"; break;
      case 15 : TimeFrameStr="15M"; break;
      case 30 : TimeFrameStr="30M"; break;
      case 60 : TimeFrameStr="1H"; break;
      case 240 : TimeFrameStr="4H"; break;
      case 1440 : TimeFrameStr="1D"; break;
      case 10080 : TimeFrameStr="1W"; break;
      case 43200 : TimeFrameStr="1MN"; break;
      default : TimeFrameStr=Period();
   } 
   return (TimeFrameStr);
   }                                                                
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, ArrowUP);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, ArrowDOWN);
   SetIndexBuffer(1, CrossDown);
   AlertPrefix=Symbol()+" ("+GetTimeFrameStr()+")";

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start() 
  {
   int limit, i, counter;
   double tmp=0;
   double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
   double Range, AvgRange;
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(i=1; i<=MaximumBars; i++) 
     {
      counter=i;
      Range=0;
      AvgRange=0;
      for(counter=i ;counter<=i+9;counter++)
        {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
        }
        
      Range=AvgRange/10;
      
      fastMAnow=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i);
      fastMAprevious=iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1);

      CrossUp[i]=EMPTY_VALUE;
      CrossDown[i]=EMPTY_VALUE;
      
      if (((show_KD_cross)  &&(fastMAnow > slowMAnow)     && (fastMAprevious < slowMAprevious))||
         ((show_K_OBOScross)&&(fastMAnow > OverSoldLevel) && (fastMAprevious < OverSoldLevel)) ||
         ((show_D_OBOScross)&&(slowMAnow > OverSoldLevel) && (slowMAprevious < OverSoldLevel)))
       
        {
         if (i==1 && flagval1==0)
        {
           flagval1=1;
           flagval2=0;
            
           if (SoundON)
           Alert("CROSS UP on "+ AlertPrefix);
            
//+----------------------------PRINTSCREEN--------------------------------------+
         keybd_event(VK_MENU,0,0,0);                    
         keybd_event(VK_Z,0,0,0);
         keybd_event(VK_Z,0,KEYEVENTF_KEYUP,0);        
         keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0); 
//+-----------------------------------------------------------------------------+ 
 
           } 
         CrossUp[i]=Low[i] -Range*Sgnal_gap1;
         CrossDown[i]=EMPTY_VALUE;
 
        }
      else 
      if (((show_KD_cross)  &&(fastMAnow < slowMAnow)       && (fastMAprevious > slowMAprevious)) ||
         ((show_K_OBOScross)&&(fastMAnow < OverBoughtLevel) && (fastMAprevious > OverBoughtLevel))||
         ((show_D_OBOScross)&&(slowMAnow < OverBoughtLevel) && (slowMAprevious > OverBoughtLevel)))
           {
         if (i==1 && flagval2==0)
         {
            flagval2=1;
            flagval1=0;
               
            if (SoundON) 
            Alert("CROSS DOWN on "+ AlertPrefix); 
               
//+----------------------------PRINTSCREEN--------------------------------------+
         keybd_event(VK_MENU,0,0,0);                    
         keybd_event(VK_Z,0,0,0);
         keybd_event(VK_Z,0,KEYEVENTF_KEYUP,0);        
         keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0); 
//+-----------------------------------------------------------------------------+  
                       
         }
            CrossDown[i]=High[i] + Range*Sgnal_gap1;
            CrossUp[i]=EMPTY_VALUE;
         }
     }
//----
   return(0);
  }
Files:
/
To add comments, please log in or register