SOLVED - 1 profit pip scalping - code modification

 

Hi Gurus,

RaptorUK has published (in this post: https://forum.mql4.com/47032/page5 ) this kind of code to close each 1 pip profit trade.


This kind of code should close each trade with 1 pip profit (1pip profit = 0.08E for example). But its not. Its closing each trade with 2 profit pips.

Because I`m not master of mq4 maybe somebody could help to change this code.


This is the result of that script:


Instead of 1 profit pip, its closing 2 pips.

extern double TPforBuys=1;
extern double TPforSells=1;
extern double TimeForEA=120;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{

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

return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
for(int a=OrdersTotal()-1;a>=0;a--)
   {
   double TPbuy = TPforBuys / 10000;
   
   if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
   OrderType()==OP_BUY && OrderSymbol()==Symbol() )  // order type and Symbol checked here
      {
      double TPB=OrderOpenPrice()+ TPbuy;
      
      // Close Buys
      if(Bid>TPB)
         {
         
         if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) )  // no need to check type and symbol here
            if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
               {
               Print("OrderClose failed, error: ", GetLastError());
               }
            else continue;        // if order has been closed move to the next position, no need to check if it's a SELL
         } // end of if(Bid>TPB)
      } // end of if( OrderSelect(a 
      
   double TPsell = TPforSells / 10000;
   
   if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) && 
   OrderType()==OP_SELL && OrderSymbol()==Symbol() )
      {
      double TPS=OrderOpenPrice()- TPsell;

      // Close Sells
      if(Ask<TPS)
         {
   
         if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) )
            if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
               Print("OrderClose failed, error: ", GetLastError());
            
         } // end of if(Ask<TPS)
      } // end of if( OrderSelect(a
   } // end of for(int a=OrdersTotal()

return(0);
}


Would be great if somebody could help me to change that script.


greetings


Dlugi

 
dlugi:

Hi Gurus,

RaptorUK has published (in this post: https://forum.mql4.com/47032/page5 ) this kind of code to close each 1 pip profit trade.


No, he hasn't.

It is not my code, I modified the code posted by ats

 

Hi RaptorUK, ups, sorry fot that mistake...


do You know maybe how to modificate it to close 1 profit pips ?

 

Got IT :D


extern double TPforBuys=0;
extern double TPforSells=0;
extern double TimeForEA=120;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{

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

return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
for(int a=OrdersTotal()-1;a>=0;a--)
{
double TPbuy = TPforBuys-1 / 10000;

if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) &&
OrderType()==OP_BUY && OrderSymbol()==Symbol() ) // order type and Symbol checked here
{
double TPB=OrderOpenPrice()+ TPbuy;

// Close Buys
if(Bid>TPB)
{

if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) ) // no need to check type and symbol here
if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
{
Print("OrderClose failed, error: ", GetLastError());
}
else continue; // if order has been closed move to the next position, no need to check if it's a SELL
} // end of if(Bid>TPB)
} // end of if( OrderSelect(a

double TPsell = TPforSells-1 / 10000;

if( OrderSelect(a,SELECT_BY_POS, MODE_TRADES) &&
OrderType()==OP_SELL && OrderSymbol()==Symbol() )
{
double TPS=OrderOpenPrice()- TPsell;

// Close Sells
if(Ask<TPS)
{

if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) )
if( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
Print("OrderClose failed, error: ", GetLastError());

} // end of if(Ask<TPS)
} // end of if( OrderSelect(a
} // end of for(int a=OrdersTotal()

return(0);

}



Thanks ;)

 
dlugi:

Got IT :D


Please use this to post code . . . it makes it easier to read.



Please edit your post.

 
dlugi:

Hi Gurus,

RaptorUK has published (in this post: https://forum.mql4.com/47032/page5 ) this kind of code to close each 1 pip profit trade.


This kind of code should close each trade with 1 pip profit (1pip profit = 0.08E for example). But its not. Its closing each trade with 2 profit pips.

Because I`m not master of mq4 maybe somebody could help to change this code.


This is the result of that script:


Instead of 1 profit pip, its closing 2 pips.


Would be great if somebody could help me to change that script.


greetings


Dlugi

Hey maybe this code is used on a uh   …..whats it called? the spread...rather than next to no spread..You know.  

Regards,

Will