Need help with ShellExecuteW to avoid multiple .exe files open once indicator loaded

 

Please help me with this indicator which provides buy/sell audio alert. I try to do some modification to this indicator in order write a file and run a external .EXE file. The write file code is working fine but once I load the indicator it just open the  so many .exe until the computer is hang. How to make this indicator below to just open 1 .exe file for the latest signal when i load the indicator and just 1 .exe file to following buy/sell signal?

//+------------------------------------------------------------------+
//|                                                                  |
//|                                                          Kalenzo |
//|                                                  simone@konto.pl |
//|                                    Modified by Newdigital        |
//|                                    Modified by Linuxser          |
//+------------------------------------------------------------------+
#define SW_HIDE             0
#define SW_SHOWNORMAL       1
#define SW_NORMAL           1
#define SW_SHOWMINIMIZED    2
#define SW_SHOWMAXIMIZED    3
#define SW_MAXIMIZE         3
#define SW_SHOWNOACTIVATE   4
#define SW_SHOW             5
#define SW_MINIMIZE         6
#define SW_SHOWMINNOACTIVE  7
#define SW_SHOWNA           8
#define SW_RESTORE          9
#define SW_SHOWDEFAULT      10
#define SW_FORCEMINIMIZE    11
#define SW_MAX              11

#import "shell32.dll"
#property copyright "Kalenzo"
#property link      "simone@konto.pl"

#property indicator_chart_window
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1

extern bool UseSound = False;
extern bool TypeChart = False;
extern bool UseAlert = true;
extern string NameFileSound = "alert.wav";
extern int    T3Period  = 14;
extern int    T3Price   = PRICE_CLOSE;
extern double b         = 0.618;
extern int Snake_HalfCycle=5; // Snake_HalfCycle = 4...10 or other
extern int Inverse = 0; //0=T3 crossing Snake, 1=Snake crossing T3
extern int DeltaForSell = 0;
extern int DeltaForBuy = 0;

#property indicator_buffers 2
//---- input parameters
//---- buffers
double UpBuffer[];
double DnBuffer[];
double alertBar;
int ShellExecuteW(int hWnd,int lpVerb,string lpFile,int lpParameters,int lpDirectory,int nCmdShow);
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

  // IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW,EMPTY);
   SetIndexStyle(1,DRAW_ARROW,EMPTY);
  
   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DnBuffer);
  
   SetIndexArrow(0,233);
   SetIndexArrow(1,234);

   SetIndexLabel(0,"Up Signal");
   SetIndexLabel(1,"Down Signal");

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  
   int handle;
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   handle=FileOpen ("signal.txt", FILE_WRITE, ';');
  
   for(int i = 0 ;i < limit ;i++)
   {       
   
      if( Inverse == 0)
      
      double pwma5 = iCustom(Symbol(),0,"Snake",Snake_HalfCycle,0,i+1);
      double cwma5 = iCustom(Symbol(),0,"Snake",Snake_HalfCycle,0,i);
      
      double pwma50 = iCustom(Symbol(),0,"T3_clean",T3Period,T3Price,b,0,i+1);
      double cwma50 = iCustom(Symbol(),0,"T3_clean",T3Period,T3Price,b,0,i);
      
/*    if( Inverse == 1)
      
       pwma5 = iCustom(Symbol(),0,"T3_clean",T3Period,T3Price,b,0,i+1);
       cwma5 = iCustom(Symbol(),0,"T3_clean",T3Period,T3Price,b,0,i);      

      
       pwma50 = iCustom(Symbol(),0,"Snake",Snake_HalfCycle,0,i+1);
       cwma50 = iCustom(Symbol(),0,"Snake",Snake_HalfCycle,0,i);
*/   
            
      if( cwma5 > (cwma50 +(DeltaForBuy*Point)) && pwma5 <= pwma50)
      {  
        UpBuffer[i] = iLow(Symbol(),0,i)-(3*Point);
        DnBuffer[i] = EMPTY_VALUE;
        
        
     
     FileWrite(handle, Symbol(), "B");
     FileClose(handle);
    
    
    ShellExecuteW(0,0,"C:\\BuySignal.exe",0,0,5);
    
      if (UseSound==1) PlaySound(NameFileSound);
      if (UseAlert==1 && Bars>alertBar) {Alert(Symbol(), "Buy signal", Period());alertBar = Bars;}
      if (TypeChart==1) Comment ("Buy signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
      }
      
      else if( pwma5 >= pwma50 && cwma5 < (cwma50 - (DeltaForSell*Point)))
      {
        UpBuffer[i] = EMPTY_VALUE;
        DnBuffer[i] = iHigh(Symbol(),0,i)+(3*Point);
        
     FileWrite(handle, Symbol(), "S");
     FileClose(handle);
     ShellExecuteW(0,0,"C:\\SellSignal.exe",0,0,5);
      
         
      if (UseSound==1) PlaySound(NameFileSound);
      if (UseAlert==1 && Bars>alertBar) {Alert(Symbol(), "Sell signal", Period());alertBar = Bars;} 
      if (TypeChart==1) Comment ("Sell signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
     
      }
      else
      {
        DnBuffer[i] = EMPTY_VALUE;
        UpBuffer[i] = EMPTY_VALUE;
      }
      
      
  
   }
//----

   return(0);
  }
//+------------------------------------------------------------------+
 
Use GlobalVariables.
 

You are

  1. Closing your file inside the for loop. All other writes fail. What are Function return values ? How do I use them ? - MQL4 forum
  2. Shelling inside the for loop for each bar that matched your criteria.

Only check outside the loop. Only sound when the current bar changes criteria not at each tick where is matches a criteria.

 
WHRoeder:

You are

  1. Closing your file inside the for loop. All other writes fail. What are Function return values ? How do I use them ? - MQL4 forum
  2. Shelling inside the for loop for each bar that matched your criteria.

Only check outside the loop. Only sound when the current bar changes criteria not at each tick where is matches a criteria.


I'm not a programmer. Can you pls give me a sample which runs 
ShellExecuteW(0,0,"C:\\SellSignal.exe",0,0,5); or ShellExecuteW(0,0,"C:\\BuySignal.exe",0,0,5);

just 1 time while load the indicator then just 1 time whenever has a new signal occurs?

 

Problem Solved....

Solution is

if(Bars>alertBar){ShellExecuteW(0,0,"C:\\BuySignal.exe",0,0,5);alertBar = Bars;}  or  if(Bars>alertBar){ShellExecuteW(0,0,"C:\\SellSignal.exe",0,0,5);alertBar = Bars;}
 
Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
 
buxboy4: I'm not a programmer. Can you pls give me a sample which runs just 1 time while load the indicator then just 1 time whenever has a new signal occurs?
  1. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  2. There are many examples had you bothered to search for them.
    static bool condition_current;
    bool condition_previous = condition_current;
    condition_current = ComputeYourCriteria();
    if(condition_current && !condition_previous){ // A new signal occurred
      :