max and min order open price

To add comments, please log in or register
mohsenvixa
26
mohsenvixa  

Hi

I wrote a program that works well in the tester strategy.

But when I run it on the real market, it does not work.(I don't Know , why???!!!)

My strategy:

When the price falls below the order open price, buy again.


Can you guide me?

Thanks.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
bool BuyMode;
bool SellMode;
double slB;
double slS;
extern double LotSize=0.1;
int MagicNumber=4562226;
extern int addLot=1;
double P,S1,R1,S2,R2,S3,R3;
double Q,x;
extern int exite=35;
int ticket;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

if (Volume[0]>1) 
   return(0); 
  
// BUY AND SELL MODES------------------------------------------------+

BuyMode  =  iRSI(NULL,0,4,PRICE_CLOSE,2)<30 && iRSI(NULL,0,4,PRICE_CLOSE,1)>30 ;

//Orders Counting & Close Orders------------------------------------+

   int orderscnt=0;
   int part=0;
for(int i=OrdersTotal()-1;i>=0;i--)
     {
      //--------------------------------------
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if((OrderSymbol()==Symbol()) && ((OrderType()==OP_SELL) || (OrderType()==OP_BUY)))
        {
         orderscnt++;
        
        }

      //-Close Positione Buy if
      if((OrderSymbol()==Symbol()) && (OrderType()==OP_BUY)  &&  iBands(0,0,exite,1,0,PRICE_CLOSE,MODE_UPPER,1)<Close[1])
        {
           OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(OrderClosePrice(),Digits),1,Black);
     
     }

     }
     
 //--------------------------------------------------------------------------+    
int j,active ;
double MaxPrice=0, MinPrice=100000 ; 
int MinTicket,MaxTicket ; 
active = OrdersTotal() ;
for (j=active-1; j>=0; j--)
    {
     if ( OrderSelect(j,SELECT_BY_POS,MODE_TRADES) )
       {
        if ( OrderType() == OP_BUY && OrderSymbol()==Symbol() ) //or other checks to filter out orders from other charts
          {
           if ( MinPrice > OrderOpenPrice() ) { MinPrice=OrderOpenPrice() ; MinTicket = OrderTicket() ; }
           if ( MaxPrice < OrderOpenPrice() ) { MaxPrice=OrderOpenPrice() ; MaxTicket = OrderTicket() ; }
if ((OrderType()==OP_BUY)&&(MinPrice < Ask))
{
return(0);
}          
} 
}
}  
//+------------------------------------------------------------------+
//| order management                                                 |
//+------------------------------------------------------------------+

   if(ordercount()==0)                  
   { LotSize=0.01;
   }
   if(ordercount()==1)
   {LotSize=0.01;
   }
   if(ordercount()==2)
   {LotSize=0.02;
   }
// Buy AND Sell Orders ----------------------------------------------+


   if((BuyMode) && (orderscnt<7))
     {
      ticket=OrderSend(Symbol(),OP_BUY,LotSize*addLot,Ask,2,0,0,"Nothing",MagicNumber,0,Blue);

     }

 
   if((SellMode) && (orderscnt<7))
     {
      ticket=OrderSend(Symbol(),OP_SELL,LotSize*addLot,Bid,2,slS,0,"Nothing",MagicNumber,0,Red);
     }

   return(0);
  }

//+------------------------------------------------------------------+
//| order counting                                                   |
//+------------------------------------------------------------------+
int ordercount()                        
{
   int total=0;                          
   int i;                               
   for(i=0; i<OrdersTotal(); i++)        
                                        
   {
       OrderSelect(i,SELECT_BY_POS,MODE_TRADES);  
       if(OrderSymbol()!=Symbol() ||     
       OrderMagicNumber()!=MagicNumber) 
       continue;                        
                                        
                                        
       total++;                         
   }
   return(total);                       
                                         
}


whroeder1
18071
whroeder1  
  1. if (Volume[0]>1) 
       return(0); 
    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. ticket=OrderSend(Symbol(),OP_BUY,LotSize*addLot,Ask,2,0,0,"Nothing",MagicNumber,0,Blue);
    
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);  
    Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

mohsenvixa
26
mohsenvixa  
whroeder1:
  1. For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

Thanks whroeder1.

My problem has been resolved.

I replaced the code below and deleted the code (((   if (voulme[0]>1)    ))).

datetime Time0 = 0;
 
void start()
{
  if (Time0 != Time[0] && iRSI(NULL,0,4,PRICE_CLOSE,2)<30 && iRSI(NULL,0,4,PRICE_CLOSE,1)>30 )
  {
     ticket=OrderSend(Symbol(),OP_BUY,LotSize*addLot,Ask,2,0,0,"Nothing",MagicNumber,0,Blue);
    Time0 = Time[0];
  }
paulinayat
4
paulinayat  

Can you tell me that code:

modify stoploss :

every buy and sell orders open , when market goes up buy order stoploss will go up distance pips to distance pips

and when every open sell order market goes down stoploss will go down distance to distance pips every signal order.

mohsenvixa
26
mohsenvixa  
paulinayat:

Can you tell me that code:

modify stoploss :

every buy and sell orders open , when market goes up buy order stoploss will go up distance pips to distance pips

and when every open sell order market goes down stoploss will go down distance to distance pips every signal order.

I don't have stoploss.

my profit is small and I think I do not need it.I use martingle.


To add comments, please log in or register