Download MetaTrader 5

hello can you help me to find Hidden trailing stop

To add comments, please log in or register
Do you have Mac OS? Find out how to install MetaTrader on it!
Mahfoud Allali
324
Mahfoud Allali 2015.11.07 00:59 

hello can you help me to find Hidden trailing stop

i search in the web but i can't find it i find just hidden stoploss and takeprofit 


Mahfoud Allali
324
Mahfoud Allali 2015.11.07 08:56  
Mahfoud Allali:

hello can you help me to find Hidden trailing stop

i search in the web but i can't find it i find just hidden stoploss and takeprofit 


 up^^

Marco vd Heijden
Moderator
4708
Marco vd Heijden 2015.11.07 09:34  

In stead of sending order modification to the server save the new value in a variable and then scan for crossovers and send order close on cross.

Mahfoud Allali
324
Mahfoud Allali 2015.11.07 15:26  
Marco vd Heijden:

In stead of sending order modification to the server save the new value in a variable and then scan for crossovers and send order close on cross.

TNX MAN :D 


void TrailingPositions() {
  double pBid, pAsk, pp;

  pp = MarketInfo(OrderSymbol(), MODE_POINT);
  if (OrderType()==OP_BUY) {
    pBid = MarketInfo(OrderSymbol(), MODE_BID);
    if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) {
      if (OrderStopLoss()<pBid-(TrailingStop*pp)) {
         stoplossbuy=pBid-TrailingStop*pp;
        return;
      }
    }
  }
  if (OrderType()==OP_SELL) {
    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
    if (!ProfitTrailing || OrderOpenPrice()-pAsk>TrailingStop*pp) {
      if (OrderStopLoss()>pAsk+(TrailingStop*pp) || OrderStopLoss()==0) {
         stoplosssell=pAsk+TrailingStop*pp;
        return;
      }
    }
  }
}



//________________________________________________________________________________________________________________________//


void hidden_stop_loss()
{
  int totalorders = OrdersTotal();
  for(int i=totalorders-1;i>=0;i--)
 {
    if(OrderSelect(i, SELECT_BY_POS)==true)
    bool result = false;
    if ( OrderSymbol()==Symbol()  )
     {
  if (OrderType() == OP_BUY &&  stoplossbuy>=Bid )  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
  if (OrderType() == OP_SELL &&  stoplosssell<=Ask  )  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
  
      }
  }
  return;
}

Marco vd Heijden
Moderator
4708
Marco vd Heijden 2015.11.07 16:26  
very good ! but make sure to check the return value from orderclose to see if the transaction was successful .
Mahfoud Allali
324
Mahfoud Allali 2015.11.07 20:17  
Marco vd Heijden:
very good ! but make sure to check the return value from orderclose to see if the transaction was successful .
In reality I do not know how I do it and I have so much of warnings in my ea 
can you help me :D 

Mahfoud Allali
324
Mahfoud Allali 2015.11.07 20:28  
Mahfoud Allali:
In reality I do not know how I do it and I have so much of warnings in my ea 
can you help me :D 

 //Closeall
 
void closeall()
  {

   int total=OrdersTotal();
   for(int cnt=OrdersTotal()-1; cnt<total; cnt++)
     {
      OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

      if(OrderType()==OP_BUY)
        {
         OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet);
        }

      if(OrderType()==OP_SELL) 
        {
         OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet);
        }

      if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT) 
        {
         OrderDelete(OrderTicket());
        }

     }
  }
Marco vd Heijden
Moderator
4708
Marco vd Heijden 2015.11.07 22:30  

Orderselect and Orderclose return a value that needs to be checked to see if the operation was successful.

However if you run your code in OnTick() and the operation fails, it will simply try again on next tick.

//+------------------------------------------------------------------+
//Closeall

void closeall()
  {
   bool select,close;

   for(int i=0; i<OrdersTotal(); i++)
     {
      select=OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
      if(select==1)
        {

         if(OrderType()==OP_BUY)
           {
            close=OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet);
            if(close==0)
              {
               Alert("BUY CLOSE ERROR!!");
              }
           }

         if(OrderType()==OP_SELL)
           {
            close=OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet);
            if(close==0)
              {
               Alert("SELL CLOSE ERROR!!");
              }
           }

         if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
           {
            OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
Mahfoud Allali
324
Mahfoud Allali 2015.11.07 23:52  

Thank you very much, man. 

But I think there is something wrong in the code Hidden trailing stop

when i use trailing stop 100 and 30 he give me same result

This is illogical

 

trailingstop 100  

 

 

 

 

 

extern bool          ProfitTrailing = True;  
extern int             TrailingStop = 30;    
  

//+-------------------------------------------------------------------------------------------+
double stoplossbuy;
double stoplosssell;


//+-------------------------------------------------------------------------------------------+

  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {

      TrailingPositions();
      trailingclose();

    }
  }







//________________________________________________________________________________________________________________________//
 

//Closeall

void closeall()
  {
   bool select,close;

   for(int i=0; i<OrdersTotal(); i++)
     {
      select=OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
      if(select==1)
        {

         if(OrderType()==OP_BUY)
           {
            close=OrderClose(OrderTicket(),OrderLots(),Bid,0,Violet);
            if(close==0)
              {
               Alert("BUY CLOSE ERROR!!");
              }
           }

         if(OrderType()==OP_SELL)
           {
            close=OrderClose(OrderTicket(),OrderLots(),Ask,0,Violet);
            if(close==0)
              {
               Alert("SELL CLOSE ERROR!!");
              }
           }

         if(OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)
           {
            OrderDelete(OrderTicket());
           }
        }
     }
  }

//________________________________________________________________________________________________________________________//
//________________________________________________________________________________________________________________________//

void TrailingPositions() {
  double pBid, pAsk, pp;

  pp = MarketInfo(OrderSymbol(), MODE_POINT);
  if (OrderType()==OP_BUY) {
    pBid = MarketInfo(OrderSymbol(), MODE_BID);
    if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) {
      if (OrderStopLoss()<pBid-(TrailingStop*pp)) {
         stoplossbuy=pBid-TrailingStop*pp;
        return;
      }
    }
  }
  if (OrderType()==OP_SELL) {
    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
    if (!ProfitTrailing || OrderOpenPrice()-pAsk>TrailingStop*pp) {
      if (OrderStopLoss()>pAsk+(TrailingStop*pp)) {
         stoplosssell=pAsk+TrailingStop*pp;
        return;
      }
    }
  }
}



//________________________________________________________________________________________________________________________//


void trailingclose()
{
  int totalorders = OrdersTotal();
  for(int i=totalorders-1;i>=0;i--)
 {
    if(OrderSelect(i, SELECT_BY_POS)==true)
    bool result = false;
    if ( OrderSymbol()==Symbol()  )
     {
  if (OrderType() == OP_BUY &&  stoplossbuy>=Bid )
  {
  closeall();
  }
  if (OrderType() == OP_SELL &&  stoplosssell<=Ask  )  
  {
  closeall();
  }
      }
  }
  return;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

 I have searched for the errors but I did not find anything

Marco vd Heijden
Moderator
4708
Marco vd Heijden 2015.11.08 01:03  

check expert properties in tester.

these variables stay the same if you change and recompile the code.

so you have to go in and either press reset, or change it in the input parameter box.

Mahfoud Allali
324
Mahfoud Allali 2015.11.08 12:09  
Marco vd Heijden:

check expert properties in tester.

these variables stay the same if you change and recompile the code.

so you have to go in and either press reset, or change it in the input parameter box.

Yes I know it has changed the trailing stop value and Walken result itself

To add comments, please log in or register