Error lots constant cannot be modified.... I need help with this code

 
//+------------------------------------------------------------------+
//|                                            Trade Manager Test.mq4 |
//|                                                                 . |
//|                                                                   |
//+------------------------------------------------------------------+
//#property copyright "Copyright 2020, MetaQuotes Software Corp."
//#property link      "mystik5551@gmail.com"
#property version   "1.00"
#property strict

input double lots =0.1;
input int stoploss= 30;
input int takeprofit= 40;
input int magic1=302;
input int slippage= 3;
input double lotfactor= 0.50;
input int totalorders=8;
input int EnterHour =4;

//+------------------------------------------------------------------+
void openbuy()
   {
   OrderSend(Symbol(), OP_BUY,lots,Ask, slippage, Ask-stoploss*Point,Ask+takeprofit*Point,"Buy Trade",magic1,0,Blue);
   lots+=lotfactor;
   }
void openbuystop()
   {
   int ticket, expiration;
   double point;
   //----
   point=MarketInfo(Symbol(),MODE_POINT);
   expiration=NULL;
   double price = Ask+50*Point;
   //----
   while(true)
     {
      ticket= OrderSend(Symbol(), OP_BUYSTOP,lots,price,0, 0,price+takeprofit*Point,"BuyStop Trade",magic1,expiration,Green);
      if(ticket<=0)Print("Error = ", GetLastError());
      else{Print("ticket = ", ticket); break; }
      //---- 10 seconds wait
      Sleep(10000);  
     }
   lots+=lotfactor;
   }
  
void opensell()
   {
    OrderSend(Symbol(), OP_SELL,lots,Bid-50*Point, slippage, Bid+stoploss*Point,Bid-takeprofit*Point,"Sell Trade",magic1,Red);
   lots+=lotfactor;
   }
void opensellstop()
   {
   int ticket, expiration;
   double point;
   //----
   point=MarketInfo(Symbol(),MODE_POINT);
   expiration=NULL;
   double price = Bid-50*Point;
   //----
   while(true)
     {
      ticket= OrderSend(Symbol(), OP_SELLSTOP,lots,price,0, 0,price-takeprofit*Point,"SellStop Trade",magic1,expiration,Pink);
      if(ticket<=0)Print("Error = ", GetLastError());
      else{Print("ticket = ", ticket); break; }
      //---- 10 seconds wait
      Sleep(10000);  
     }
  lots+=lotfactor;
   }
   
int countpending()
   {
      int s=0;
      for(int i=0;i<OrdersTotal();i++)
        {
         OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
         if(OrderType() > OP_SELL)
           {
            s++;
           }
         
        }
      return(s);
   }
   void closeallorders()
   {
      for(int i=0;i<OrdersTotal();i++)
        {
             OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUY || OrderType() == OP_SELL)
            {
               int j=0;
               while(j!=5)//try 5 times to ensure execution
               {
               OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Pink);
               j++;
               }
            }
        }
   }
Files:
complain1.txt  3 kb
 

use extern instead

extern double lots =0.1;
 
Nafisat Lateef:

Is not a good practise changing the input parameters because once changed you cannot reset the value until the EA is restarted.

input double inplots =0.1;
input int stoploss= 30;
input int takeprofit= 40;
input int magic1=302;
input int slippage= 3;
input double lotfactor= 0.50;
input int totalorders=8;
input int EnterHour =4;

double lots = inplots;

//+------------------------------------------------------------------+
void openbuy()
   {
   OrderSend(Symbol(), OP_BUY,lots,Ask, slippage, Ask-stoploss*Point,Ask+takeprofit*Point,"Buy Trade",magic1,0,Blue);
   lots+=lotfactor;
   }
void openbuystop()
   {
   int ticket, expiration;
   double point;
   //----
   point=MarketInfo(Symbol(),MODE_POINT);
   expiration=NULL;
   double price = Ask+50*Point;
   //----
   while(true)
     {
      ticket= OrderSend(Symbol(), OP_BUYSTOP,lots,price,0, 0,price+takeprofit*Point,"BuyStop Trade",magic1,expiration,Green);
      if(ticket<=0)Print("Error = ", GetLastError());
      else{Print("ticket = ", ticket); break; }
      //---- 10 seconds wait
      Sleep(10000);  
     }
   lots+=lotfactor;
   }
  
void opensell()
   {
    OrderSend(Symbol(), OP_SELL,lots,Bid-50*Point, slippage, Bid+stoploss*Point,Bid-takeprofit*Point,"Sell Trade",magic1,Red);
   lots+=lotfactor;
   }
void opensellstop()
   {
   int ticket, expiration;
   double point;
   //----
   point=MarketInfo(Symbol(),MODE_POINT);
   expiration=NULL;
   double price = Bid-50*Point;
   //----
   while(true)
     {
      ticket= OrderSend(Symbol(), OP_SELLSTOP,lots,price,0, 0,price-takeprofit*Point,"SellStop Trade",magic1,expiration,Pink);
      if(ticket<=0)Print("Error = ", GetLastError());
      else{Print("ticket = ", ticket); break; }
      //---- 10 seconds wait
      Sleep(10000);  
     }
  lots+=lotfactor;
   }
 
Fernando Morales #:

Is not a good practise changing the input parameters because once changed you cannot reset the value until the EA is restarted.

So easy!Thank you so much, amigo!)
 
OrderSend(Symbol(), OP_BUY,lots,Ask, slippage, Ask-stoploss*Point,Ask+takeprofit*Point,"Buy Trade",magic1,0,Blue);

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).