need help for a code

 
Hello everyone, I am calling you because, as you can see, my current code will close a position when it takes 130 pips, I am trying to change it to close the position when it makes a profit of 1 euro (1 euro for example), the take profit will be set automatically so that a profit of 1 euro is realized taking into account the spread. I try to make sure that the take profit is automatically put according to the profit I ask for (1 euros) and not according to the pips (130 pips). Unfortunately despite several days of testing I can not create this code, I know that among you there are people who can help me.
Thank you.


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

bool symbolIsAlreadyTrade(string symbole, uint period){
   
   if(HistorySelect(TimeCurrent() - period, TimeCurrent())){
     
      for(int i = 0; i < HistoryDealsTotal(); i += 1){
         
         ulong ticket = HistoryDealGetTicket(i);
         
         if(HistoryDealGetString(ticket, DEAL_SYMBOL) == symbole && HistoryDealGetInteger(ticket, DEAL_ENTRY) == (int)DEAL_ENTRY_IN){
            return true;
         }
      }
   }
   
   return false;
}


void OnTick()
  {
   if(!symbolIsAlreadyTrade(_Symbol, 100 * 60))
     {
      MqlRates mrate[];
      ArraySetAsSeries(mrate,true);
      if(CopyRates(_Symbol,_Period,0,11,mrate) > 0)
        {
         if(mrate[1].close > mrate[10].close)
           {
            double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
            double stoploss = ask - 30000 * _Point ;
            double takeprofit = ask + 130 * _Point ;
            if(trade.Buy(0.01, _Symbol, ask, stoploss, takeprofit))
              {
               int code = (int) trade . ResultRetcode();
               ulong ticket = trade . ResultOrder();
               Print(" Code: " + (string) code);
               Print(" Ticket: " + (string) ticket);
              }
           }
        else if(mrate[1].close<mrate[10].close){
       
         double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
         double sellStoploss = bid + 30000 * _Point ;
         double sellTakeprofit = bid - 130 * _Point ;
   
         if(trade.Sell(0.01, _Symbol, bid, sellStoploss, sellTakeprofit)){
            int code = (int) trade . ResultRetcode();
            ulong ticket = trade . ResultOrder();
            Print(" Code: " + (string) code);
            Print(" Ticket: " + (string) ticket);
           }
        }
    }
  }  
}
Extract profit down to the last pip
Extract profit down to the last pip
  • www.mql5.com
The article describes an attempt to combine theory with practice in the algorithmic trading field. Most of discussions concerning the creation of Trading Systems is connected with the use of historic bars and various indicators applied thereon. This is the most well covered field and thus we will not consider it. Bars represent a very artificial entity; therefore we will work with something closer to proto-data, namely the price ticks.
 
You can use SYMBOL_TRADE_TICKVALUE_*
to get the Infos you need.

As much as I know, this gives you the tick value in your account currency. From there on it's simple math, adjusting the volume to what you need.

If I understand the value given correctly, it referes to the symbols minimum volume.
 
39863092:
Hello everyone, I am calling you because, as you can see, my current code will close a position when it takes 130 pips, I am trying to change it to close the position when it makes a profit of 1 euro (1 euro for example), the take profit will be set automatically so that a profit of 1 euro is realized taking into account the spread. I try to make sure that the take profit is automatically put according to the profit I ask for (1 euros) and not according to the pips (130 pips). Unfortunately despite several days of testing I can not create this code, I know that among you there are people who can help me.
Thank you.


Where is your attempt to code it ?

Your code shows 130 points TP not 130 pips.

 
Alain Verleyen :

Où est votre tentative de codeur ?

Votre code affiche 130 points TP et non 130 pips.

I have error messages I can’t.

 
39863092:
Hello everyone, I am calling you because, as you can see, my current code will close a position when it takes 130 pips, I am trying to change it to close the position when it makes a profit of 1 euro (1 euro for example), the take profit will be set automatically so that a profit of 1 euro is realized taking into account the spread. I try to make sure that the take profit is automatically put according to the profit I ask for (1 euros) and not according to the pips (130 pips). Unfortunately despite several days of testing I can not create this code, I know that among you there are people who can help me.
Thank you.


You have the check the PositionProfit value, which is a value on Currency (and not points/pips) and based on the PositionProfit value, you can close it when it reaches the desired profit (1 euro for example)


PositionGetDouble(POSITION_PROFIT)