I am beginner, any one guide me fix this error

ckannan
15

I am beginner, any one guide me fix this error

//+------------------------------------------------------------------+
//|                                                  Buy Sell EA.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property script_show_inputs

#include<Trade/trade.mqh>
CTrade trade;

input double LotSize = 0.01; //lot size
input int TakeProfitInPips = 500; //TakeProfit pips
input int StoplossInPips = 500

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 // Call BuyOrder
    BuyOrder();

 // Call SellOrder
    SellOrder();
  }
//+------------------------------------------------------------------+

void BuyOrder(){
  double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
  double TakeProfit = Ask + TakeProfitInPips*_Point;
  double Stoploss = Ask - StoplossInPips*_Point;
   if(PositionsTotal()<2){
       trade.Buy(LotSize,_Symbol,Ask,Stoploss,TakeProfit,NULL);
   }
 }
 
 void SellOrder(){
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   double TakeProfit = Bid - TakeProfitInPips*_Point;
   double Stoploss = Bid + StoplossInPips*_Point;
    if(PositionsTotal()<2){
        trade.Sell(LotSize,_Symbol,Bid,Stoploss,TakeProfit,NULL);
     
    }  
 }
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Vladimir Karputov
Moderator
286472
ckannan:

I am beginner, any one guide me fix this error

1. Please insert the code correctly: when editing a message, press the button   Code and paste your code into the pop-up window. 

2. A simple advisor: there are always two opposite positions in the market

How to start with MQL5
How to start with MQL5
  • 2021.11.13
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
William Roeder
26462
William Roeder  
ckannan: I am beginner, any one guide me fix this error
  1. What error? You haven't stated any. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

  2. input int TakeProfitInPips = 500; //TakeProfit pips
    ⋮
      double TakeProfit = Ask + TakeProfitInPips*_Point;

    A PIP is not a point.

    PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum (2014)

    Unless you manually adjust your SL/TP for each separate symbol, using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points), and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 programming forum (2017)
              Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum (2018)

  3. 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. 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).