Download MetaTrader 5

Expert or indicator for changing TP

To add comments, please log in or register
Mahmood Nouri
240
Mahmood Nouri  

Expert or indicator for changing TP

 

Hello,

Do you know any expert or indicator which can get average from the orders then according to that take the TP? For example an order is opened at 2 and another one at 6, and average for them is 4, so is there any expert witch can take this on one pair exchange? And when we have a new order can it account the average again, and get the TP to the new number?

Thanks for your help

phi nuts
2181
phi nuts  
mahmoodfx:

Expert or indicator for changing TP

 

Hello,

Do you know any expert or indicator which can get average from the orders then according to that take the TP? For example an order is opened at 2 and another one at 6, and average for them is 4, so is there any expert witch can take this on one pair exchange? And when we have a new order can it account the average again, and get the TP to the new number?

Thanks for your help

In MT open price of position is averaged. Try this open position and then 10 pips later open another one ans see where the open price now.

ans please don't double posting. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
noonehastherighttojudgeanother
235
noonehastherighttojudgeanother  
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#include <Trade\TerminalInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>

//+------------------------------------------------------------------+
//| Parameters 
//+------------------------------------------------------------------+
input int      _TakeProfitPoints=600;
input int      _StopLossPoints=400;

//+------------------------------------------------------------------+
//| Global Objects 
//+------------------------------------------------------------------+
CPositionInfo  GBL_position;
CTrade         GBL_trade;
CSymbolInfo    GBL_Symbol;
CTerminalInfo  GBL_Terminal;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   GBL_trade.SetAsyncMode(true);
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(GBL_Terminal.IsTradeAllowed())
     {
      ManagePositions();
     }
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ManagePositions()
  {
   GBL_Symbol.RefreshRates();
   GBL_Symbol.Refresh();
   if(GBL_position.Select(_Symbol))
     {
      if(SetTakeProfit())
        {
        }

      if(SetStopLoss())
        {
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool SetStopLoss()
  {
   if(_StopLossPoints>0)
     {
      if(GBL_position.Select(_Symbol))
        {
         if(GBL_position.StopLoss()==0)
           {
            if(GBL_position.PositionType()==POSITION_TYPE_BUY)
              {
                 {
                  GBL_trade.PositionModify(_Symbol,
                                           GBL_position.PriceOpen()-_StopLossPoints*_Point,
                                           GBL_position.TakeProfit()
                                           );
                  return(true);
                 }
              }

            if(GBL_position.PositionType()==POSITION_TYPE_SELL)
              {
                 {
                  GBL_trade.PositionModify(_Symbol,
                                           GBL_position.PriceOpen()+_StopLossPoints*_Point,
                                           GBL_position.TakeProfit()
                                           );
                  return(true);
                 }
              }
           }
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool SetTakeProfit()
  {
   if(_TakeProfitPoints>0)
     {
      if(GBL_position.Select(_Symbol))
        {
         if(GBL_position.TakeProfit()==0)
           {
            if(GBL_position.PositionType()==POSITION_TYPE_BUY)
              {
                 {
                  GBL_trade.PositionModify(_Symbol,
                                           GBL_position.StopLoss(),
                                           GBL_position.PriceOpen()+_TakeProfitPoints*_Point
                                           );
                  return(true);
                 }
              }

            if(GBL_position.PositionType()==POSITION_TYPE_SELL)
              {
                 {
                  GBL_trade.PositionModify(_Symbol,
                                           GBL_position.StopLoss(),
                                           GBL_position.PriceOpen()-_TakeProfitPoints*_Point
                                           );
                  return(true);
                 }
              }
           }
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
To add comments, please log in or register