Trailing Stops and Trailing Profit - page 7

 
Arav007:

Here it is.

Regards


See https://www.mql5.com/en/forum/150195/page6#924239 for a better way
 

I've seen it and tested it too.

It also doesn't solve the problem with 'Stop Loss' and 'Least Profit Locking' which I just need to make this EA complete.

 

This is beginning of your code

if(OrdersTotal()>0)
   {//----------------------------------------------------------------->1
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {//--------------------------------------------------------------->2    
     if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
     if(OrderSymbol() == Symbol() && OrderMagicNumber() ==Magic_Number_1)
       {
       if (OrderProfit()<0.03)
         {
         if(OrderType()==OP_BUY)
           {  
           bOrderClosed = closeBuyOrder(iOrderType_Buy); //Closing Buy order    
           if(bOrderClosed)
             {
             Print("Buy Order 1 Closed");
             }
            else
               {
               iLastError = GetLastError();                                       
               }//end else if(bOrderClosed)
           }//end if(OrderType()==OP_BUY)
       if(OrderType()==OP_SELL)
          {  
          bOrderClosed = closeSellOrder(iOrderType_Sell); //Closing Sell order
          if(bOrderClosed)
            {
            Print("Sell Order 1 Closed");
            }
           else
              {
              iLastError = GetLastError();
              }//end else if(bOrderClosed)
          }//end if(OrderType()==OP_SELL)
        }// if (OrderProfit()<0.03)                          
      }// if(OrderSymbol() == Symbol() && OrderMagicNumber() ==Magic_Number_1)

explain what is this code doing and

why has it do this.... and when does it happen

what do you want this code is doing

do you know iLastError if there is an error ??

 

ohh, Thanks. You have opened my eyes.

It's closing all the open orders whenever it's getting executed because the Condition is:

if (OrderProfit()<0.03)

So it'll close all the just opened orders naturally.

My aim was if a trade goes into profit say $0.1 and then if that trade turns back, it'll get closed with the least profit of say $0.01.

Probably it's not possible by 'OrderProfit()' function.

I'd have to use the trailing stops thing.

 
Arav007:

I've seen it and tested it too.

It also doesn't solve the problem with 'Stop Loss' and 'Least Profit Locking' which I just need to make this EA complete.


what did you wanted to code ???

what problem is there with stoploss

at breakeven you have least profit locking for first two trades like you wanted,..... i thought

 
deVries:


what did you wanted to code ???

what problem is there with stoploss

at breakeven you have least profit locking for first two trades like you wanted,..... i thought


Please Pardon me.

I couldn't set the parameters correctly.

Yes, this is it! Thanks a lot.

SL Moved for First Two trades and the TP too.

I used this settings now:

extern double BreakEven =5;

extern double BreakEvenSL =1;

extern double TrailingStop =10;

extern double TrailingStep =3;

Just for clarify the concept:

If the market moves 5 pips in profit from open price, the Stop Loss will be set at 1 pip profit. Then the function of Trailing Stop will start.

With a Trailing Stop of 10, if the market moves 10 pips in profit from the opening price, the Stop Loss will become at 3 pips in profit, right?

And then if the market reaches 10 pips more i.e. 20 pips in total, the SL will be at 6 pips in profit?

Regards