Trailing stop- Why compiler print 'OrderModify' should be checked.

 

Hey.  I will ask for help. Why  compiler print "OrderModify" should be checked

//+------------------------------------------------------------------+
//|                                     USDPLN expert pozostałe .mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
      {
      string morning="";                              
      if (Hour()>6 && Minute()>5)
      {  
      morning="buy";
      }
      string evening="";                              
      if (Hour()<9)
      {  
      evening="buy";
      }
      string trade="";                              
      int Orders=OrdersTotal();
      if (Orders==0)
      {  
      trade="buy";
      }
      double 2;
      double two=1;
      double three=0;
      double four=-1;
      double five=-2;
      one*Close[1];
      two=two*Close[2];
      three=three*Close[3];
      four=four*Close[4];
      five=five*Close[5];
      double counter_b;
      counter_b=one+two+three+four+five;
      double denominator_b;
      denominator_b= 10;
      double b;
      b=counter_b/denominator_b;
      double counter_a;
      counter_a=Close[5]+Close[4]+Close[3]+Close[2]+Close[1];
      double denomimator_a=5;
      double a=counter_a/denomimator_a;
      double one_prim;
      a+b*2;
      double two_prim;
      two_prim=a+b;
      double three_prim;
      three_prim=a;
      double four_prim;
      four_prim=a-b;
      double five_prim;
      five_prim=a-2*b;
      double counter_1;
      counter_1=MathPow(Close[1]-one_prim,2);
      double counter_2;
      counter_2=MathPow(Close[2]-two_prim,2);
      double counter_3;
      counter_3=MathPow(Close[3]-three_prim,2);
      double counter_4;
      counter_4=MathPow(Close[4]-four_prim,2);
      double counter_5;
      counter_5=MathPow(Close[5]-five_prim,2);
      double counter_S;
      counter_S=counter_1+counter_2+counter_3+counter_4+counter_5;
      double denominator_S=3;
      double S;
      S=MathSqrt(counter_S/denominator_S);
      double average;
      average=(Close[5]+Close[4]+Close[3]+Close[2]+Close[1])/5;
      double V;
      V=(S/average)*100;
     Comment(" b=",b," \n a=",a," \n average=",average,"\n Counter S=",counter_S," \n S=",S," \n V=",V);
      if (morning=="buy" && evening=="buy"&& trade=="buy" && b>0 && b<=0.002 && V<0.003)
            {
            //--- get minimum stop level
            double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
            Print("Minimum Stop Level=",minstoplevel," points");
            double price=Ask;
            //--- calculated SL and TP prices must be normalized
            double stoploss=NormalizeDouble(Ask-100*Point,Digits);
            //   double takeprofit=NormalizeDouble(Bid+80*Point,Digits);
            double takeprofit=NormalizeDouble(Ask+125*Point,Digits);;
            //--- place market order to buy 1 lot
            int ticket=OrderSend(Symbol(),OP_BUY,0.1,price,5,stoploss,takeprofit,"My Order",16384,0,clrGreen);
            if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            }
            else
            Print("OrderSend placed successfully");
            //---
            for (int c=OrdersTotal()-1;c>=0;c--)
            {
               if (OrderSelect(c,SELECT_BY_POS,MODE_TRADES))
                  if (OrderSymbol()==Symbol())
                  if (OrderType()==OP_BUY)
                  {
               if (OrderStopLoss()<Ask-(100*Point))
               OrderModify(OrderTicket(),OrderOpenPrice(),Ask-(100*Point),OrderTakeProfit(),0,clrGreen);
            }
     }  
     }
 
  }   
//+------------------------------------------------------------------+
 
CatDog:

Hey.  I will ask for help. Why "OrderModify" should be checked? 

To check that it was successful.

 

Ok. I have corrected the code. I am posting a new code. The compiler doesn't report any error. But OrderModify on chart doesn't work. Why?  Please help! 

//+------------------------------------------------------------------+
//|                                     USDPLN expert pozostałe .mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
      {
      string morning="";                              
      if (Hour()>6 && Minute()>5)
      {  
      morning="buy";
      }
      string evening="";                              
      if (Hour()<9)
      {  
      evening="buy";
      }
      string trade="";                              
      int Orders=OrdersTotal();
      if (Orders==0)
      {  
      trade="buy";
      }
      double 2;
      double two=1;
      double three=0;
      double four=-1;
      double five=-2;
      one*Close[1];
      two=two*Close[2];
      three=three*Close[3];
      four=four*Close[4];
      five=five*Close[5];
      double counter_b;
      counter_b=one+two+three+four+five;
      double denominator_b;
      denominator_b= 10;
      double b;
      b=counter_b/denominator_b;
      double counter_a;
      counter_a=Close[5]+Close[4]+Close[3]+Close[2]+Close[1];
      double denomimator_a=5;
      double a=counter_a/denomimator_a;
      double one_prim;
      a+b*2;
      double two_prim;
      two_prim=a+b;
      double three_prim;
      three_prim=a;
      double four_prim;
      four_prim=a-b;
      double five_prim;
      five_prim=a-2*b;
      double counter_1;
      counter_1=MathPow(Close[1]-one_prim,2);
      double counter_2;
      counter_2=MathPow(Close[2]-two_prim,2);
      double counter_3;
      counter_3=MathPow(Close[3]-three_prim,2);
      double counter_4;
      counter_4=MathPow(Close[4]-four_prim,2);
      double counter_5;
      counter_5=MathPow(Close[5]-five_prim,2);
      double counter_S;
      counter_S=counter_1+counter_2+counter_3+counter_4+counter_5;
      double denominator_S=3;
      double S;
      S=MathSqrt(counter_S/denominator_S);
      double average;
      average=(Close[5]+Close[4]+Close[3]+Close[2]+Close[1])/5;
      double V;
      V=(S/average)*100;
     Comment(" b=",b," \n a=",a," \n average=",average,"\n Counter S=",counter_S," \n S=",S," \n V=",V);
      if (morning=="buy" && evening=="buy"&& trade=="buy" && b>0 && b<=0.002 && V<0.003)
            {
            //--- get minimum stop level
            double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
            Print("Minimum Stop Level=",minstoplevel," points");
            double price=Ask;
            //--- calculated SL and TP prices must be normalized
            double stoploss=NormalizeDouble(Ask-100*Point,Digits);
            //   double takeprofit=NormalizeDouble(Bid+80*Point,Digits);
            double takeprofit=NormalizeDouble(Ask+125*Point,Digits);;
            //--- place market order to buy 1 lot
            int ticket=OrderSend(Symbol(),OP_BUY,0.1,price,5,stoploss,takeprofit,"My Order",16384,0,clrGreen);
            if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            }
            else
            Print("OrderSend placed successfully");
            //---
            for (int c=OrdersTotal()-1;c>=0;c--)
            {
               if (OrderSelect(c,SELECT_BY_POS,MODE_TRADES)
               if (OrderStopLoss()<NormalizeDouble(Ask-100*Point,Digits))
               int modify=OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,OrderTakeProfit(),0,clrGreen);
            }
     }  
     }
 
//+------------------------------------------------------------------+
 
CatDog: Why  compiler print "OrderModify" should be checked? 

So you know if there are problems.

CatDog: The compiler doesn't report any error. But OrderModify on chart doesn't work. Why?  Please help! 

There are problems. You would know why if you had checked your return codes for errors, and reported them including GLE/LE, your variable values and the market.  That way we would know that at least you are calling your code. Do you really expect us to debug your code for you? You aren't calling the modify code for trailing at all.
          Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

 
CatDog:

Ok. I have corrected the code. I am posting a new code. The compiler doesn't report any error. But OrderModify on chart doesn't work. Why?  Please help! 

You haven't corrected the code, you have silenced the compiler.

int modify=OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,OrderTakeProfit(),0,clrGreen);

OrderModify() does not return an int.

Where is the code to check whether it was successful or not?

Strange that you check the return for OrderSend()

            int ticket=OrderSend(Symbol(),OP_BUY,0.1,price,5,stoploss,takeprofit,"My Order",16384,0,clrGreen);
            if(ticket<0)
            {
            Print("OrderSend failed with error #",GetLastError());
            }
            else
            Print("OrderSend placed successfully");

When an OrderSend or OrderModify fails you should print out the error plus the details so that you can see what went wrong.

Why are you trying to modify all orders in a loop?

 

I am not a programmer. The code places orders. Profitabillity in 2019 is about 25 % but lossy transactions are 40 %. I want to do trailing stop. How to choose an order? How to modify them? Help me. ;-) The code places order well. But order modification doesn't work. Calculation are from the statistic manual. I wrote it myself. Help me.

 
CatDog: I am not a programmer. … I want … Help me.
    1. MT4: Learn to code it.
      MT5: Begin learning to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
    2. or pay (Freelance) someone to code it.
                Hiring to write script - General - MQL5 programming forum
    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help

  1. I already told you what is happening and if you had checked your return code you would have known. If you use the debugger, you will learn why. What help do you possibly want subject to № 1.1