hello can you help me to find Hidden trailing stop

 

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:

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^^

 

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.

 
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;
}

 
very good ! but make sure to check the return value from orderclose to see if the transaction was successful .
 
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:
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());
        }

     }
  }
 

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());
           }
        }
     }
  }
//+------------------------------------------------------------------+
 

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

 

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.

 
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