Need help in programming

 

hello,

I am working to make some scalping EA. I'd like to use 15 minutes period. I used some custom indicators. I'd like to take about 5 pips per trade. I have problem with orders openings. When my programm is taking the profit the conditions are still vaild, so the EA is opening another order in the same direction, but signal is not valid in this time.

What should I do to my strategy could open only one order per signal?

 
Try putting a time_stamp on it. Or you can also use the if (ordertotals() < 1, then) function. If you require additional assistance, try posting your code using the SRC button above.
 

this is my code. please take a look

#property copyright "Copyright © 2010, Bzyqe, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int h_open=8;
extern int h_close=20;
extern int magic=19790704;
extern double Lots=0.01;

extern int SL=30;
extern int TP=5;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
double bb_UP,bb_DOWN;
int FTBlue1,FTRed1,FTBlue2,FTRed2;
bool O_BUY, O_SELL;
int h_current;
int ticket;
int order_type,i;

int last_order;
int zlecenie;
//Custom Indicators 


bb_UP=iCustom(NULL,0,"BBands_Stop_v1_BAR",20,2,0,1);
bb_DOWN=iCustom(NULL,0,"BBands_Stop_v1_BAR",20,2,1,1);
FTBlue1=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,4,8,9,1,1);
FTRed1=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,4,8,9,0,1);
FTBlue2=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,6,13,9,1,1);
FTRed2=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,6,13,9,0,1);

//Chceck Time

h_current=TimeHour(TimeCurrent());

if (h_current>=h_open && h_current<=h_close){

   if (bb_UP>1 && FTBlue1==1 && FTBlue2==1) O_BUY=true;
   if (bb_DOWN>1 && FTRed1==1 && FTRed2==1) O_SELL=true;
                                           }
if (OrdersTotal()<1)

/*1*/{
//BUY
 
 if (O_BUY==true) 
 /*2*/{
 
 ticket=OrderSend(Symbol(), OP_BUY, Lots,Ask,3,Ask-SL*Point,Ask+TP*Point,"BUY",magic+100,0,Green);  
 if(ticket<0)
      /*3*/ {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
      /*3*/ }       
/*2*/}

//SELL

 if (O_SELL==true) 
 /*2*/{

 ticket=OrderSend(Symbol(), OP_SELL, Lots,Bid,3,Bid+SL*Point,Bid-TP*Point,"SELL",magic,0,Red);
 if(ticket<0)
      /*3*/ {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
     /*3*/  }
     
/*2*/}
/*1*/}

Comment(bb_UP,",  ",bb_DOWN,"\n",
FTBlue1,",  ",FTRed1,"\n",
FTBlue1,",  ",FTRed1,"\n",
O_BUY,",  ",O_SELL,"\n",
h_current,"\n",

"\nEND OF RAPORT");


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

please help

 
bzyqe:

this is my code. please take a look

please help


Looking at your custom indicator calls it looks like you only need to run your code once when a new bar/candle forms i.e. every 15 minutes. This change to your code should give tthe result that you are looking for.

#property copyright "Copyright © 2010, Bzyqe, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int h_open=8;
extern int h_close=20;
extern int magic=19790704;
extern double Lots=0.01;

extern int SL=30;
extern int TP=5;

//================= Added Code Here ========================================
static datetime prevtime=0; // Global static variable for start time of last bar processed



//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
double bb_UP,bb_DOWN;
int FTBlue1,FTRed1,FTBlue2,FTRed2;
bool O_BUY, O_SELL;
int h_current;
int ticket;
int order_type,i;

int last_order;
int zlecenie;

//================= Added Code Here ========================================
if(prevtime == Time[0]) return(0); // If we have not progressed to a new bar since out last run then do nothing
   prevtime = Time[0];   
   
   
//Custom Indicators 


bb_UP=iCustom(NULL,0,"BBands_Stop_v1_BAR",20,2,0,1);
bb_DOWN=iCustom(NULL,0,"BBands_Stop_v1_BAR",20,2,1,1);
FTBlue1=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,4,8,9,1,1);
FTRed1=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,4,8,9,0,1);
FTBlue2=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,6,13,9,1,1);
FTRed2=iCustom(NULL,0,"FLATTRAND_w_MACD_mtf",15,6,13,9,0,1);

//Chceck Time

h_current=TimeHour(TimeCurrent());

if (h_current>=h_open && h_current<=h_close){

   if (bb_UP>1 && FTBlue1==1 && FTBlue2==1) O_BUY=true;
   if (bb_DOWN>1 && FTRed1==1 && FTRed2==1) O_SELL=true;
                                           }
if (OrdersTotal()<1)

/*1*/{
//BUY

if (O_BUY==true) 
/*2*/{

ticket=OrderSend(Symbol(), OP_BUY, Lots,Ask,3,Ask-SL*Point,Ask+TP*Point,"BUY",magic+100,0,Green);  
if(ticket<0)
      /*3*/ {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
      /*3*/ }       
/*2*/}

//SELL

if (O_SELL==true) 
/*2*/{

ticket=OrderSend(Symbol(), OP_SELL, Lots,Bid,3,Bid+SL*Point,Bid-TP*Point,"SELL",magic,0,Red);
if(ticket<0)
      /*3*/ {
        Print("OrderSend failed with error #",GetLastError());
        return(0);
     /*3*/  }
     
/*2*/}
/*1*/}

Comment(bb_UP,",  ",bb_DOWN,"\n",
FTBlue1,",  ",FTRed1,"\n",
FTBlue1,",  ",FTRed1,"\n",
O_BUY,",  ",O_SELL,"\n",
h_current,"\n",

"\nEND OF RAPORT");


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

Hope this helps.