We made this EA for scalping! The EA should close every scalping-order with 1 pip profit! In order not to close the long term orders we used the command OrderOpenTime(). The scalping orders are set manually! It acts like TP but only with 1 pip profit!
externdouble TPforBuys=1;
externdouble TPforSells=1;
externdouble 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 Buysif(Bid>TPB)
{
if( TimeCurrent()-OrderOpenTime() <= (TimeForEA * 60) ) // no need to check type and symbol hereif( !OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 1000, White) )
{
Print("OrderClose failed, error: ", GetLastError());
}
elsecontinue; // 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 Sellsif(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);
}
You mean this way?
I don't know . . . does that do what you want ?
Of course! sorry! I didn´t think about about it!
We made this EA for scalping! The EA should close every scalping-order with 1 pip profit! In order not to close the long term orders we used the command OrderOpenTime(). The scalping orders are set manually! It acts like TP but only with 1 pip profit!
Thank you
Ah I see, you don't want the EA to close the non-scalping, short term, orders . . .
OK, some comments . . .
1. Your loop does virtually nothing, you need to enclose in braces, { } what you want done within the loop . . .
2. You have 2 OrderSelect() calls, if you put everything into the loop you will only need one . . .
3. the close buys section should only be executed for Buy orders, the close sells should only be executed for Sell orders
4. your 1 pip profit is hard coded for 4 digit pairs, so it won't work for pairs like USDJPY
Maybe something like this . . . .
Maybe something like this . . . .