One Trade only//Hello Guys, how can I adjust this EA to enter one trade only /// and ifpossible how can i add 10 pips to the sl

 
#include <Trade\Trade.mqh>

CTrade trade;

int OnInit()

  {

   return(INIT_SUCCEEDED);

  }

void OnDeinit(const int reason)

  { 

  }

void OnTick()

  {

 

  double high = iHigh(_Symbol,PERIOD_H4,1);

  double low = iLow(_Symbol,PERIOD_H4,1);

  double close = iClose(_Symbol,PERIOD_H4,1);

  double open = iOpen(_Symbol,PERIOD_H4,1);

//candle 2

 double high1 = iHigh(_Symbol,PERIOD_H4,2);

 double low1 = iLow(_Symbol,PERIOD_H4,2);

 double close1 = iClose(_Symbol,PERIOD_H4,2);

 double open1 = iOpen(_Symbol,PERIOD_H4,2);



if(low < low1 && close > high1 && close > open){

double tp1= (close-low) + close;

  trade.Buy(0.1,_Symbol,close,low,tp1);

 }



if(high > high1 && close < low1 && close < open){

double tp= (close-high) + close;

  trade.Sell(0.1,_Symbol,close,high,tp);

 }
}
Trade Operations in MQL5 - It's Easy
Trade Operations in MQL5 - It's Easy
  • www.mql5.com
Almost all traders come to market to make money but some traders also enjoy the process itself. However, it is not only manual trading that can provide you with an exciting experience. Automated trading systems development can also be quite absorbing. Creating a trading robot can be as interesting as reading a good mystery novel.
 
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>

CTrade trade;

#define MAGIC 11

input int InpAddStopLoss = 100;    // Add to Stop Loss (points)

datetime prev_bar;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   prev_bar = 0;

//--- Set Magic Number
   trade.SetExpertMagicNumber(MAGIC);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   int      cnt, pos_nr = 0;
   datetime curr_bar;
   ulong    ticket;

//--- Gets the opening time of the current bar
   curr_bar = iTime(_Symbol, PERIOD_H4, 0);
   if(curr_bar == 0)
     {
      Print("Error getting current bar open time...");
      return;
     }

//============== CHECKS IF IS A NEW BAR... ===============//
   if(prev_bar != curr_bar && TimeCurrent() < curr_bar + 30)
     {
      //--- Checks positions
      for(cnt = PositionsTotal() - 1; cnt >= 0; cnt --)
        {
         //--- Gets the ticket and selects the position
         ticket = PositionGetTicket(cnt);
         if(ticket == 0)
           {
            Print("Failed to get position ticket...");
            return;
           }
         if(PositionGetString(POSITION_SYMBOL) == _Symbol && PositionGetInteger(POSITION_MAGIC) == MAGIC)
           {
            pos_nr ++;
            break;
           }
        }

      if(pos_nr == 0)
        {
         //candle 1
         double high1 = iHigh(_Symbol,PERIOD_H4,1);
         double low1 = iLow(_Symbol,PERIOD_H4,1);
         double close1 = iClose(_Symbol,PERIOD_H4,1);
         double open1 = iOpen(_Symbol,PERIOD_H4,1);

         //candle 2
         double high2 = iHigh(_Symbol,PERIOD_H4,2);
         double low2 = iLow(_Symbol,PERIOD_H4,2);
         double close2 = iClose(_Symbol,PERIOD_H4,2);
         double open2 = iOpen(_Symbol,PERIOD_H4,2);

         if(low1 < low2 && close1 > high2 && close1 > open1)
           {
            double tp1= (close1-low1) + close1;
            trade.Buy(0.1,_Symbol,close1,low1-InpAddStopLoss*_Point,tp1);
           }

         if(high1 > high2 && close1 < low2 && close1 < open1)
           {
            double tp= (close1-high1) + close1;
            trade.Sell(0.1,_Symbol,close1,high1+InpAddStopLoss*_Point,tp);
           }
        }

      //--- Updates bar time
      prev_bar = curr_bar;
     }
  }
//+------------------------------------------------------------------+
 
Vinicius de Oliveira #:

thank you very much, it worked! <3

 
Rami Khattab #thank you very much, it worked! <3


You're welcome. 👍