Add trailing stop into your expert advisor and do not use MetaTrader trailing. ;)
Now there is no IsTrailingActive( ) function.
I do not want to have auto matic trailing stop in my code, I want it to be optional and use it on special situations which can not be programmed.
My question again :
BUT.. how can I turn my code off when and if I decide to start a trailing stop loss from the MT4 menu manually. Is there a function that recognises that a MT4 menu fired trailing stop is running on a particular order...???
I am wrting some code to move my stop loss to breakeven after certain number of x pips profits has been secured.
I am wrting some code to move my stop loss to breakeven after certain number of x pips profits has been secured.
BUT.. how can I turn my code off when and if I decide to start a trailing stop loss from the MT4 menu manually. Is there a function that recognises that a MT4 menu fired trailing stop is running on a particular order...???
What does this do, can it help me ???
bool IsTradeAllowed( )
Returns TRUE if the expert is allowed to trade and a thread for trading is not occupied, otherwise returns FALSE.
extern string Trailing_Stop_is_On/Off= "1: On / 0.Off" ;
extern bool Run_Trailing_Stop=1 ;// Run_Trailing_Stop is a Global variable
int start() {
switch( Run_Trailing_Stop){
case 1 : for(i=0; i<= OrdersTotal() ; i++) // Trailing stop runs here
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symb ) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else // go to short position
{
// check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>Point*TrailingStop)
{
if((OrderStopLoss()>Ask+Point*TrailingStop) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
// Trailing Stop
case 0: for(i=0; i<= OrdersTotal() ; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symb ) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// check for trailing stop
if(TrailingStop>0) return ; // Trailing stop don't run here
}}}
} // End of switch
} // End of start
P.S : Note that The Code of Trailing Stop take on this site don't now .If you have an other one I need it .Thanks
P.S : Note that The Code of Trailing Stop take on this site don't now .If you have an other one I need it .Thanks
Two points . . .
if you are going to post code: please use the SRC button to post code: How to use the SRC button.
please do not dredge up 6 year old threads unless you have a very good reason . . . the users in this thread are probably long gone.
Thread start date - 2006.12.10
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
BUT.. how can I turn my code off when and if I decide to start a trailing stop loss from the MT4 menu manually. Is there a function that recognises that a MT4 menu fired trailing stop is running on a particular order...???
What does this do, can it help me ???
bool IsTradeAllowed( )
Returns TRUE if the expert is allowed to trade and a thread for trading is not occupied, otherwise returns FALSE.