Trying to fix my pending order grid with trailing stop

To add comments, please log in or register
marth tanaka
240
marth tanaka  
William Roeder
20210
William Roeder  
marth tanaka: my trailing stop is faulty I think.
  1. You think? And then state two problems?

  2. Advice ignored
              I always get 1? - Fundamental Analysis - MQL4 and MetaTrader 4 - MQL4 programming forum #4 № 1
              I always get 1? - Fundamental Analysis - MQL4 and MetaTrader 4 - MQL4 programming forum #4 № 2

  3. Because we live in the US, we are subject to FIFO rules. On most brokers, all SL must be equal and moving one automatically moves the others.
              NFA Enforces FIFO Rule, Bans Forex Hedging in US Forex Accounts - Trading Heroes
              FAQ: FIFO in the Forex Market - BabyPips.com
marth tanaka
240
marth tanaka  
William Roeder:
  1. You think? And then state two problems?

  2. Advice ignored
              I always get 1? - Fundamental Analysis - MQL4 and MetaTrader 4 - MQL4 programming forum #4 № 1
              I always get 1? - Fundamental Analysis - MQL4 and MetaTrader 4 - MQL4 programming forum #4 № 2

  3. Because we live in the US, we are subject to FIFO rules. On most brokers, all SL must be equal and moving one automatically moves the others.
              NFA Enforces FIFO Rule, Bans Forex Hedging in US Forex Accounts - Trading Heroes
              FAQ: FIFO in the Forex Market - BabyPips.com
1. I dont get what you mean. Could you elaborate?
2. No I took this advice. I already fixed my problem and learned from it before you commented on my last post.
3. Not everyone here lives in the US. My broker doesnt use the First in first out rule.
marth tanaka
240
marth tanaka  
so I tried a totally new trailing stop loss function and I get the same exact error when I trade realtime! (not during the compiler)

Here is my error: 2019.06.03 23:34:29.408 2019.05.01 10:50:00  nameofmyEA EURUSD,M5: OrderModify error 1


Below is my new trailing stop
void BuyTrailingStopFunc()
{
//trailing stop
int total;
   int cnt;
      
       total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // 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);
                    
                    }
                 }
              }
           }
        
        }
       }


}
void SellTrailingStopFunc()
{
//trailing stop
int total;
   int cnt;
      
       total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_SELL)   // long position is opened
           {
            // check for trailing stop
            
            // 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);
             
                    }
                 }
              }
           }
        }
       }


}

Please guys help if you can! Ive been smacking my head at this for the past few days now and I feel like I am at a stop.
marth tanaka
240
marth tanaka  
Ok I think I got this guys. Please check my code and confirm so others facing this issue can also be helped. Here is my new trailing stop loss codes
void BuyTrailingStopFunc()
{
//trailing stop
int total;
   int cnt;
      
       total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                    
                    
                 }
              }
           }
        
        }
       }


}
void SellTrailingStopFunc()
{
//trailing stop
int total;
   int cnt;
      
       total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_SELL)   // long position is opened
           {
            // check for trailing stop
            
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
             
                    
                 }
              }
           }
        }
       }


}
William Roeder
20210
William Roeder  
marth tanaka:
1. I dont get what you mean. Could you elaborate?
2. No I took this advice. I already fixed my problem and learned from it before you commented on my last post.
3. Not everyone here lives in the US. My broker doesnt use the First in first out rule.
  1. You said "my trailing stop is faulty I think." And then went on to state Error 1 and never modified problems. Are you unsure that those two are normal?

  2. You edited your original post, it initially showed:
    int return_price(int ttype)

    You have still ignored I always get 1? - Fundamental Analysis - MQL4 programming forum #4 № 2

  3. Not according to your profile.

  4.             if(TrailingStop>0){                 
                   if((OrderOpenPrice()-Ask)>(Point*TrailingStop)){
                      if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)){
                         OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                        }
    
    TrailingStop is constant inside the loop. Simplify, move it outside.
  5. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you. Always use strict. Fixing the warnings will save you hours of debugging.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  6. Don't keep recomputing the same thing over and over, especially in different ways. Simplify.
                if(TrailingStop>0){                 
                   double SL=Ask+Point*TrailingStop);
                   if(OrderTakeProfit()>SL || OrderStopLoss()==0){
                         OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Red);
                        }
To add comments, please log in or register