Bar by bar trailing stop

 

I'm looking for a bar by bar trailing stop (EA I guess).

Once the bar closes I would like the stop moved under it by so many pips (I can set how many 2, 5, etc).

I searched and couldnt find anything.

Thanks

I'm new to site... hello!

 
int start()
  {
//----
if (Fun_New_Bar())
   {
   Trailing_Stop();
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
void Trailing_Stop()
   {
   bool TrailingStop = true;
   int Magic = 12345;
   for(int cnt = OrdersTotal(); cnt >= 0; cnt--)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      //----
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
         {       
         if(OrderType() == OP_BUY)
         if(TrailingStop) 
            {                                       
            OrderModify(OrderTicket(), OrderOpenPrice(), iLow(NULL,0,1), 0, 0, CLR_NONE);
            return(0);                                              
            }
         if(OrderType() == OP_SELL) 
         if(TrailingStop) 
            {                       
            OrderModify(OrderTicket(), OrderOpenPrice(), iHigh(NULL,0,1), 0, 0, CLR_NONE);
            return(0);
            }
         }
      } 
   }

bool Fun_New_Bar()
   {
   static datetime New_Time = 0;
   bool New_Bar = false;
   if (New_Time!= Time[0])
      {
      New_Time = Time[0];
      New_Bar = true;
      }
   return(New_Bar);
   }

didn't checked

 
qjol:

didn't checked

This doesn't seem to do anything.

I made it an EA in mataeditor. It compiled with no errors. I closed and reopened mt4.

I added the EA to the chart. Left the default setting. It doesnt move the stop. I'm doing something wrong, maybe?


Oh, thank you for helping... :)

 

Do you have such an open order with MAGIC no. 12345

(int Magic = 12345;

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic))

 
qjol:

Do you have such an open order with MAGIC no. 12345

(int Magic = 12345;

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic))


I did some reading on magic number. I put in comment 12345, MAGIC no. 12345, and a random number I made up when placing the order and nothing worked.

Do I need something in the comment when I start a trade? What do I need to do?

 

as far as i know there is no way to use MAGIC no. manually only with OrderSend(), & comment has nothing to do with that (MAGIC No.)

 

just change:

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

to:

if(OrderSymbol() == Symbol())
 
enotrek:

just change:

to:


What he is gonna be with the rest of that same symbol that he dont want to use it
 

i guessed he just wanted to test it.


if he wants to use it on special trades, I suggest he makes a comment to those trades and use that to trail them.

 
enotrek:

i guessed he just wanted to test it.


if he wants to use it on special trades, I suggest he makes a comment to those trades and use that to trail them.

And this is done how? Sorry I dont know.


And to qjol am I doing something wrong or is code wrong?

 

this is only an example

Reason: