function definition unexpected ????? - page 2

 
RaptorUK:
Maybe someone else will look at your code,  I'm not in the state it's in.


no problem buddy ,enjoy your weekend , i am not in a rush.

 

many thanks!!  

 
er007:

every thing seems to be ok white the code,but unexpected result (its closing the sell order permanently ) i do not understand  the logic is :delete the order sell _stop only if   ask> pend(H+P+Spread) , i have no idea whats want wrong.

  

Is this meant as a function: pend(H+P+Spread)? If yes, where is it? If no, what is it? Or have you defined 'pend' as static var somewhere else?

 

if  (Check1 >= Threshold && Check2 >= Threshold && O>L)  
  {   
    
      
    ticket2=OrderSend(Symbol(),OP_SELLSTOP,Lot,L-P,0,L-P+SL,L-P-TP,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);  // <-- place sellstop order and assigne it to ticket2
    
    if (ticket2==-1)
      {
         err=GetLastError();
         Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_SELLSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     

   ClosePendingOrder( symbol,ticket,ticket2);                            // <-- call ClosePendingOrder and one argument is ticket2
//}
//+------------------------------------------------------------------+
// int total=OrdersTotal();
//int TotalOrderCount(string Symbol, int ticket)
//{
 }<<<<<<<___________end of  start
 
 bool ClosePendingOrder(string symbol ,int  Ticket,int ticket2)
 {
     
     double H,Spread,P,pend;                                           // <-- Unless pend is defined as static var somewhere else, pend is initialised with 0                                                                         
     //int ticket2;
     
     if (Ask > pend)                                                   // <-- if (Ask>0)
   if(OrderSelect(ticket2,SELECT_BY_TICKET)==true);                    // <-- select order with ticket2   
     if(ticket2==OrderTicket())                                        // <-- ??? You selecet by ticket, of course this is true! (No need at all to do that).
  bool orderx= OrderDelete(ticket2,Red);                               // <-- Delete order with ticket2
     return(0);
              
 
 


}
 
kronin:

  

Is this meant as a function: pend(H+P+Spread)? If yes, where is it? If no, what is it? Or have you defined 'pend' as static var somewhere else?

 

 


hi kronin

pend =  (H+P+Spread);

 it is a global variable . 

 

#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
 
 
extern int Digits2Round = 2;  // Floating point rounding
 
extern int PercentOfFreeDepo = 1; // Risk Percent of depo
 
extern double MinLot = 0.10; // minimal lot for trading, if calculated lot is less than minimal (it depends on the equity)
 
extern int MagicNumber = 888; // This is magic number for the expert,
                              // It opens, modify and deletes orders with this MagicNumber
                              
extern double Threshold = 0.00050;  // Threshold for the pending order sending
 
extern double SL = 0.00050; // StopLoss
extern double TP = 0.00100; // TakeProfit
extern double P  = 0.00020; // Breakout points
 
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 

 //bool BuyEntered  = false;
   //bool SellEntered = false;
 //int ByEntered;
 string symbol;


 int ticket2;
  int ticket;
  int err;
  int q=0;
 
 
double L=iLow(NULL,NULL,1);
 double H=iHigh(NULL,NULL,1);
double C=iClose(NULL,NULL,0);
double O=iOpen(NULL,NULL,0);
double Spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;
double FreeDepo=NormalizeDouble(AccountBalance()-AccountMargin(),Digits2Round);
double Risk=NormalizeDouble((FreeDepo*PercentOfFreeDepo/100),Digits2Round);
double Lot=NormalizeDouble(Risk/(SL/0.0001)*0.1,Digits2Round);
double Check1=H-C;
double Check2=C-L;
 double pend=(H+P+Spread);
//===================== Lets determine lot size and risk ===================================
 
if ( Lot < MinLot )
 {
   Lot=MinLot;
 }
Comment( "\n","Acceptable risk is ",PercentOfFreeDepo, "% = ",Risk," of the free money ",FreeDepo," in lots = ",Lot);
 
//====================== checking for the orders opening
 for( q=0;q<OrdersTotal();q++)
 {
  if (OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol())
   {
// checking positions, if there are some opended orders, lets check them with the indicator
   if (OrderType()==OP_BUYSTOP)
     {
       return(0); 
     }
   if (OrderType()==OP_SELLSTOP)
     {
       return(0); 
     }
   }  
 }
 
 
//======================= condition for ORDER BUY ===============================

  

if  (Check1 >= Threshold && Check2 >= Threshold && O<H)     
  {    
    ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,H+P+Spread,0,H+P-SL+Spread,H+P+TP+Spread,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);
 
  
    
    if (ticket==-1)
      {
        err=GetLastError();
        Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_BUYSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     
  
    
  
 

   
   
   
   //================================ condition for ORDER SELL ==================== 



if  (Check1 >= Threshold && Check2 >= Threshold && O>L)  
  {   
    
      
    ticket2=OrderSend(Symbol(),OP_SELLSTOP,Lot,L-P,0,L-P+SL,L-P-TP,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);
    
    if (ticket2==-1)
      {
         err=GetLastError();
         Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_SELLSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     

   ClosePendingOrder( symbol,ticket,ticket2,pend);
//}
//+------------------------------------------------------------------+
// int total=OrdersTotal();
//int TotalOrderCount(string Symbol, int ticket)
//{
 }
 
 bool ClosePendingOrder(string symbol ,int  Ticket,int ticket2,double pend)
 {
     
     // double H,Spread,P;
     //int ticket2;
     
     if (Ask > pend)
     {
   //OrderSelect(ticket2,SELECT_BY_TICKET);
    //ticket2==OrderTicket())
  bool orderx= OrderDelete(ticket2,Red);
 
     return(0);
              
 }
 


}
thanks a lot.
 
 
 
er007:


hi kronin

pend =  (H+P+Spread);

 it is a global variable . 

No, it isn't. You defined it inside the start function.

ticket2 is overwritten with 0 on the next tick. Either you have to place it in global scope, or you have to select it again in the ClosePendingOrder() function (Select by position and filter for something you identify your order).

And read about timeseries. The second parameter is not intended to be NULL. 

 
kronin:

No, it isn't. You defined it inside the start function.

ticket2 is overwritten with 0 on the next tick. Either you have to place it in global scope, or you have to select it again in the ClosePendingOrder() function (Select by position and filter for something you identify your order).

And read about timeseries. The second parameter is not intended to be NULL. 


the compiler do not let me to put statement on the global scop so..?were do i put the "pend" so the function could read it properly ?

#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
 
 
extern int Digits2Round = 2;  // Floating point rounding
 
extern int PercentOfFreeDepo = 1; // Risk Percent of depo
 
extern double MinLot = 0.10; // minimal lot for trading, if calculated lot is less than minimal (it depends on the equity)
 
extern int MagicNumber = 888; // This is magic number for the expert,
                              // It opens, modify and deletes orders with this MagicNumber
                              
extern double Threshold = 0.00050;  // Threshold for the pending order sending
 
extern double SL = 0.00050; // StopLoss
extern double TP = 0.00100; // TakeProfit
extern double P  = 0.00020; // Breakout points
double H;  <<<<<<<<<<<<< g  
double Spread;<<<<<<<<<< l
double pend;<<<<<<<<<<<< o <<<<<<<<<<<<<<<<<<<<<<
int  ticket2;<<<<<<<<<<< b
                         a
                         l


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 

 //bool BuyEntered  = false;
   //bool SellEntered = false;
 //int ByEntered;
 string symbol;


 
  int ticket;
  int err;
  int q=0;
 

double L=iLow(NULL,NULL,1);
 double H=iHigh(NULL,NULL,1);
double C=iClose(NULL,NULL,0);
double O=iOpen(NULL,NULL,0);
 double Spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;
double FreeDepo=NormalizeDouble(AccountBalance()-AccountMargin(),Digits2Round);
double Risk=NormalizeDouble((FreeDepo*PercentOfFreeDepo/100),Digits2Round);
double Lot=NormalizeDouble(Risk/(SL/0.0001)*0.1,Digits2Round);
double Check1=H-C;
double Check2=C-L;

//===================== Lets determine lot size and risk ===================================
 
if ( Lot < MinLot )
 {
   Lot=MinLot;
 }
Comment( "\n","Acceptable risk is ",PercentOfFreeDepo, "% = ",Risk," of the free money ",FreeDepo," in lots = ",Lot);
 
//====================== checking for the orders opening
 for( q=0;q<OrdersTotal();q++)
 {
  if (OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol())
   {
// checking positions, if there are some opended orders, lets check them with the indicator
   if (OrderType()==OP_BUYSTOP)
     {
       return(0); 
     }
   if (OrderType()==OP_SELLSTOP)
     {
       return(0); 
     }
   }  
 }
 
 
//======================= condition for ORDER BUY ===============================

  

if  (Check1 >= Threshold && Check2 >= Threshold && O<H)     
  {    
    ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,H+P+Spread,0,H+P-SL+Spread,H+P+TP+Spread,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);
 
  
    
    if (ticket==-1)
      {
        err=GetLastError();
        Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_BUYSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     
  
    
  
 

   
   
   
   //================================ condition for ORDER SELL ==================== 



if  (Check1 >= Threshold && Check2 >= Threshold && O>L)  
  {   
    
      
    ticket2=OrderSend(Symbol(),OP_SELLSTOP,Lot,L-P,0,L-P+SL,L-P-TP,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);
    
    if (ticket2==-1)
      {
         err=GetLastError();
         Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_SELLSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     
pend =(H+P+Spread);  <<<<<<<<<<---------pend
   ClosePendingOrder( symbol,ticket,ticket2,pend);
//}
//+------------------------------------------------------------------+
// int total=OrdersTotal();
//int TotalOrderCount(string Symbol, int ticket)
//{
 }
  // 
 bool ClosePendingOrder(string symbol ,int  Ticket,int ticket2,double pend)
 {
    
     //int ticket2;
     
     if (Ask >pend)
     {
   OrderSelect(ticket2,SELECT_BY_POS);
   //if (ticket2 >0)
     
  bool orderx= OrderDelete(ticket2,Red);
 
     return(0);
              
 }
 


}
 
 
many thanks!
 
 
er007:


the compiler do not let me to put statement on the global scop so..?were do i put the "pend" so the function could read it properly ?

Declare it globally,  assign it anywhere you like,  just do it before you call the function . . .  and remove the same variable declared as part of the function declaration.

Change this

 bool ClosePendingOrder(string symbol ,int  Ticket, int ticket2, double pend)

 to this

 bool ClosePendingOrder(string symbol ,int  Ticket, int ticket2)

 
Which  ticket2  do you want to use in your function ?  the globally declared one or the locally declared one ? ?

 
RaptorUK:

Declare it globally,  assign it anywhere you like,  just do it before you call the function . . .  and remove the same variable declared as part of the function declaration.

Change this

 to this

 
Which  ticket2  do you want to use in your function ?  the globally declared one or the locally declared one ? ?


"Which  ticket2  do you want to use in your function ?  the globally declared one or the locally declared one ? ?"

i been checked them bout , it give the seem effect which is do not working properly (it does not close the sell order once the buy order get hit)

*i did modify the function according to your example .

any advice?

thanks. 

 
RaptorUK:

Sort your indenting and braces into some coherent and consistent style and you will probably see where your issue is.

kronin:

And read about timeseries. The second parameter is not intended to be NULL. 

 

You have been given plenty of advice, you don't seem to want to take it though. 

 

Sort your indenting and  {  }  braces and fix your timeseries calls. 

 
RaptorUK:

 

You have been given plenty of advice, you don't seem to want to take it though. 

 

Sort your indenting and  {  }  braces and fix your timeseries calls. 


what i am  missing here:

*i change the code to be more clear .

#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
 
 
extern int Digits2Round = 2;  // Floating point rounding
 
extern int PercentOfFreeDepo = 1; // Risk Percent of depo
 
extern double MinLot = 0.10; // minimal lot for trading, if calculated lot is less than minimal (it depends on the equity)
 
extern int MagicNumber = 888; // This is magic number for the expert,
                              // It opens, modify and deletes orders with this MagicNumber
                              
extern double Threshold = 0.00050;  // Threshold for the pending order sending
 
extern double SL = 0.00050; // StopLoss
extern double TP = 0.00100; // TakeProfit
extern double P  = 0.00020; // Breakout points
double H; // <<<<<<<<<<<<< g  
double Spread;//<<<<<<<<<< l
double pend;//<<<<<<<<<<<< o <<<<<<<<<<<<<<<<<<<<<<
int  ticket2; //<<<<<<<<<<< 
  int ticket;                     //  a
                        // l


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
 

 //bool BuyEntered  = false;
   //bool SellEntered = false;
 //int ByEntered;
 string symbol;


 //int ticket2;
//  int ticket;
  int err;
  int q=0;
 

double L=iLow(NULL,0,1);
 double H=iHigh(NULL,0,1);
double C=iClose(NULL,0,0);
double O=iOpen(NULL,0,0);
 double Spread=MarketInfo(Symbol(),MODE_SPREAD)*Point;
double FreeDepo=NormalizeDouble(AccountBalance()-AccountMargin(),Digits2Round);
double Risk=NormalizeDouble((FreeDepo*PercentOfFreeDepo/100),Digits2Round);
double Lot=NormalizeDouble(Risk/(SL/0.0001)*0.1,Digits2Round);
double Check1=H-C;
double Check2=C-L;

//===================== Lets determine lot size and risk ===================================
 
if ( Lot < MinLot )
 {
   Lot=MinLot;
 }
Comment( "\n","Acceptable risk is ",PercentOfFreeDepo, "% = ",Risk," of the free money ",FreeDepo," in lots = ",Lot);
 
//====================== checking for the orders opening
 for( q=0;q<OrdersTotal();q++)
 {
  if (OrderSelect(q, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol())
   {
// checking positions, if there are some opended orders, lets check them with the indicator
   if (OrderType()==OP_BUYSTOP)
     {
       return(0); 
     }
   if (OrderType()==OP_SELLSTOP)
     {
       return(0); 
     }
   }  
 }
 
 
//======================= condition for ORDER BUY ===============================

  

if  (Check1 >= Threshold && Check2 >= Threshold && O<H)     
  {    
    ticket=OrderSend(Symbol(),OP_BUYSTOP,Lot,H+P+Spread,0,H+P-SL+Spread,H+P+TP+Spread,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);
 
  
    
    if (ticket==-1)
      {
        err=GetLastError();
        Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_BUYSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     
  
    
  
 

   
   
   //================================ condition for ORDER SELL ==================== 



if  (Check1 >= Threshold && Check2 >= Threshold && O>L)  
  {   
    
      
    ticket2=OrderSend(Symbol(),OP_SELLSTOP,Lot,L-P,0,L-P+SL,L-P-TP,NULL,0,iTime( Symbol(), PERIOD_D1, 0 ) + 86400);
   
    if (ticket2==-1)
      {
         err=GetLastError();
         Print("error(",err,")");
      }
  }
else 
  {
    Comment("\n","Cannot set OP_SELLSTOP",
            "\n","The price is not satisfied to the market entry condition");
  }     

   // pend =(H+P+Spread); // <<<<<<<<<<---------pend
   ClosePendingOrder( symbol,ticket,ticket2);  <<<<<<<<----linke to the func
   
//}
//+------------------------------------------------------------------+
// int total=OrdersTotal();
//int TotalOrderCount(string Symbol, int ticket)
//{
 }
  // 
 bool ClosePendingOrder(string symbol ,int  ticket,int ticket2)<<<<<<<<<<<<<<<-----func
 {
    
     //int ticket2;
     OrderSelect(ticket, SELECT_BY_TICKET);
         
        
         if (ticket > 0 && OrderType()==OP_BUY)
             {
              OrderSelect(ticket2,SELECT_BY_TICKET);
               }
               if (ticket2>0 && OrderType() !=OP_SELL) 
                  
               {    
                  bool orderx= OrderDelete(ticket2,Red);   
             } 
     return(0);
              
    }
 

 it doesnt close the pending sell once the buy order hit!

 

 i am lost! 

 
RaptorUK:


Which  ticket2  do you want to use in your function ?  the globally declared one or the locally declared one ? ?

ticket and ticket2 are globally declared,  you don't need to pass then when you call the function . . .

change these

   ClosePendingOrder( symbol,ticket,ticket2);  <<<<<<<<----linke to the func
   

 bool ClosePendingOrder(string symbol ,int  ticket,int ticket2)  <<<<<<<<<<<<<<<-----func

to these 

   ClosePendingOrder( symbol );   // <<<<<<<<----linke to the func
   

 int ClosePendingOrder(string symbol)  //   <<<<<<<<<<<<<<<-----func
Reason: