Programme errors

 

Hi, This is my first ever programme, i keep getting these errors when trying to proof my code.

Could somebody help me sort out the errors and check my code to see if it makes sense? 

thank you!


• 3 different empty control statements

if (Trend<0.0);

        { 

         if(EMA13M15<EMA21M15); //true

           

            if(EMA8M15<EMA13M15);


2 errors of return value of 'order modify' should be checked


and when i try to run the program my debug looks like this


2020.03.09 11:51:07.779 2019.04.09 17:19:00  Sell Bot GBPUSD,M15: OrderSend error 4107

2020.03.09 11:51:07.779 2019.04.09 17:19:00  Sell Bot GBPUSD,M15: invalid price for OrderSend function

2020.03.09 11:51:07.587 2019.04.09 17:18:56  Sell Bot GBPUSD,M15: OrderSend error 4107

2020.03.09 11:51:07.587 2019.04.09 17:18:56  Sell Bot GBPUSD,M15: invalid price for OrderSend function

2020.03.09 11:51:07.395 2019.04.09 17:18:52  Sell Bot GBPUSD,M15: OrderSend error 4107

2020.03.09 11:51:07.395 2019.04.09 17:18:52  Sell Bot GBPUSD,M15: invalid price for OrderSend function

2020.03.09 11:51:07.203 2019.04.09 17:18:48  Sell Bot GBPUSD,M15: OrderSend error 4107

2020.03.09 11:51:07.203 2019.04.09 17:18:48  Sell Bot GBPUSD,M15: invalid price for OrderSend function


#property copyright "Michael Ieuan Fripp"
#property version "1.00"
#property strict
void OnTick()
{  

   int LowestCandle=iLowest(_Symbol,PERIOD_M15,MODE_LOW,5,0);
   double StopLoss = Open[LowestCandle]+3;
   double Takeprofit1 = (-Open[LowestCandle]-Close[LowestCandle]*2);
   double SellEntry = (Close[LowestCandle]-3);
   double EMAhour = iMA(_Symbol,PERIOD_H1,18,0,MODE_SMA,PRICE_CLOSE,0);
   double OLDEMAH1 = iMA(_Symbol,PERIOD_H1,18,0,MODE_SMA,PRICE_CLOSE,10);
   double Trend = EMAhour-OLDEMAH1;
   double EMA8M15 = iMA(_Symbol,PERIOD_M15,8,0,MODE_SMA,PRICE_CLOSE,0);
   double EMA13M15 = iMA(_Symbol,PERIOD_M15,13,0,MODE_SMA,PRICE_CLOSE,0);
   double EMA21M15 = iMA(_Symbol,PERIOD_M15,21,0,MODE_SMA,PRICE_CLOSE,0);
   int Trailing_Stop = 5;


   if (Trend<0.0);
        { 
         if(EMA13M15<EMA21M15); //true
           
            if(EMA8M15<EMA13M15);
              {
               //Order Execution Short
               //if There are 0 orders already
                 if (OrdersTotal()==0)
                   {
                     int Sellticket = OrderSend(_Symbol,OP_SELL,0.10,SellEntry,2,StopLoss,Takeprofit1,NULL,0);
                     
                     
                     
                     if(OrderType()==OP_BUY && Bid-OrderOpenPrice() > Trailing_Stop*Point && OrderMagicNumber()==0 && OrderStopLoss()< Bid - Trailing_Stop*Point )
            {
                    OrderModify(OrderTicket(),OrderOpenPrice(),Bid - Trailing_Stop*Point,OrderTakeProfit(),0,Blue);
                    Sleep(10000);
            }
      if(OrderType()==OP_SELL && OrderOpenPrice()-Ask > Trailing_Stop*Point && OrderMagicNumber()==0 && OrderStopLoss()> Ask + Trailing_Stop*Point)
            {
                    OrderModify(OrderTicket(),OrderOpenPrice(),Bid + Trailing_Stop*Point,OrderTakeProfit(),0,Blue);
                    Sleep(10000);
            }
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                   }
              }          
           }
        } 
   
          

Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
[in,out]  Pointer to a structure of MqlTradeResult type describing the result of trade operation in case of a successful completion (if true is returned). parameter are filled out correctly. If there are no errors, the server accepts the order for further processing. If the order is successfully accepted by the trade server, the OrderSend...
 
if(EMA13M15<EMA21M15);

To begin with remove the semicolons after an if()

if(EMA13M15<EMA21M15)
  {
  }

Please avoid leaving so many empty lines in your code and use the styler to tidy up your code. It will make it easier to read and find errors.

I will move this to the MQL4/MT4 section.

 
Keith Watford:

To begin with remove the semicolons after an if()

Please avoid leaving so many empty lines in your code and use the styler to tidy up your code. It will make it easier to read and find errors.

I will move this to the MQL4/MT4 section.

OK great, thanks keith! 

Thanks for the constructive criticism, ill get right on that 

 
double SellEntry = (Close[LowestCandle]-3);

if the close price is 1.0000 you are setting the entry at minus 2.000

Same with your other variables.

if(OrderType()==OP_BUY)

You must select an order first.

 
mikefripp:

Hi, This is my first ever programme, i keep getting these errors when trying to proof my code.

Could somebody help me sort out the errors and check my code to see if it makes sense? 

thank you!


• 3 different empty control statements

if (Trend<0.0);

        { 

         if(EMA13M15<EMA21M15); //true

           

            if(EMA8M15<EMA13M15);


2 errors of return value of 'order modify' should be checked


Hi Mike.

With your invalid prices error, the price needs to be whats availiable; so your SellEntry price variable won't necessarily get filled. Check out Bid and Ask in the MQL4 reference.

This would probably be ok, unless you're creating an order on a different symbol than the chart you're on.

int Sellticket = OrderSend(_Symbol,OP_SELL,0.10,Bid,2,StopLoss,Takeprofit1,NULL,0);

And thinking about your program logic, it looks like...

"If a valid trend, and no orders, then place an order". But then, "If a valid trend, and no orders, then modify an existing order".

That wont work will it?

Reason: