How to close trades after a certain amount of time has passed - page 2 12 New comment [Deleted] 2006.06.02 12:04 #11 This is what I am using in an EA that uses MA line as a trailing stop. I will not offer any explanations, I think you can work it out. //this goes inside start TrailingAlls(TrailStart, SMA1); void TrailingAlls(int start, double currvalue) { int profit; double stoptrade; double stopcal; // if(stop==0) return; int trade; for(trade=OrdersTotal()-1;trade>=0;trade--) { if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber) continue; if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) { profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0); if(profit<start) continue; stoptrade=OrderStopLoss(); // stopcal=Bid-(stop*Point); stopcal=NormalizeDouble(currvalue, Digits); if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade)) OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue); }//Long if(OrderType()==OP_SELL) { profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0); if(profit<start) continue; stoptrade=OrderStopLoss(); // stopcal=Ask+(stop*Point); stopcal=NormalizeDouble(currvalue, Digits); if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade)) OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red); }//Shrt } }//for } Coding help..How do I Ask! return value of 'OrderModify' zhu28ming 2006.06.05 06:20 #12 Maji: Thanks, Would you please writer in MQ program, so we will have no problem to use it? Thanks again. [Deleted] 2006.06.05 12:11 #13 zhu28ming:Maji: Thanks, Would you please writer in MQ program, so we will have no problem to use it? Thanks again. Sorry, I am not that conversant in MQL. Maji 12 New comment
This is what I am using in an EA that uses MA line as a trailing stop.
I will not offer any explanations, I think you can work it out.
//this goes inside start
TrailingAlls(TrailStart, SMA1);
void TrailingAlls(int start, double currvalue)
{
int profit;
double stoptrade;
double stopcal;
// if(stop==0) return;
int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
if(profit<start)
continue;
stoptrade=OrderStopLoss();
// stopcal=Bid-(stop*Point);
stopcal=NormalizeDouble(currvalue, Digits);
if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
}//Long
if(OrderType()==OP_SELL)
{
profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
if(profit<start)
continue;
stoptrade=OrderStopLoss();
// stopcal=Ask+(stop*Point);
stopcal=NormalizeDouble(currvalue, Digits);
if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
}//Shrt
}
}//for
}
Maji:
Thanks, Would you please writer in MQ program, so we will have no problem to use it?
Thanks again.
Maji:
Thanks, Would you please writer in MQ program, so we will have no problem to use it?
Thanks again.Sorry,
I am not that conversant in MQL.
Maji