Adding direction to reversal opening

MQL5 Esperti

Lavoro terminato

Tempo di esecuzione 4 minuti
Feedback del cliente
Experienced coder of our generation, flexible and understanding each and every details. He is fast, faster than Japanese bullet train.
Feedback del dipendente
Excellent client I will help him again thank you

Specifiche

Anyone who can add opening direction base on moving average if its above MA must take buy trades only if below then take sell trades only.

#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.20"



input bool inputOpenOppositeTradeAfterClose = true; // Open Opposite Trade After Close

input ENUM_ORDER_TYPE_FILLING typeFilling = ORDER_FILLING_FOK; //Order Filling Type

input int inputMaxOppositeTradePerSymbol = 3; //Max Opposite Trade Per Symbol
input int slippage = 100; //Slippage In Points

long MagicNumber = 163818213;


bool timerCreated = false;
int TIMER_FREQUENCY = 1; 

struct FLOATING_TRADES 
{
  ulong ticket;
  int tradeType;
  string symbol;
  double tradeLots;
  double stoploss;
  double takeprofit;
  bool oppositeAllowed;
 
};

FLOATING_TRADES FloatingTradesArray[];


bool inititalized = false;

int OnInit()
{   
  if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
  {
    Alert("Please Allow Auto Trading");
    return(INIT_FAILED);
  }

  if(!inititalized)
  { 
    ArrayResize(FloatingTradesArray, 0);
    timerCreated = EventSetTimer(TIMER_FREQUENCY);
    inititalized = true;
  }

  return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
  switch (reason) 
  {
    case REASON_CHARTCHANGE: break;
    case REASON_PARAMETERS: break;

    default:

    inititalized = false; 
    EventKillTimer();
    timerCreated = false;

    break;
  }
}

void OnTick()
{
  if (!timerCreated) timerCreated = EventSetTimer(TIMER_FREQUENCY);
}

void OnTimer()
{
  FindClosedPositions();
  FindNewPositions();
} 

void FindNewPositions()
{
  for(int i=PositionsTotal()-1; i>=0; i--)
  {
    ulong position_ticket=PositionGetTicket(i);
    ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
    string symbol = PositionGetString(POSITION_SYMBOL);

    if(position_ticket != 0 && (type==POSITION_TYPE_BUY || type==POSITION_TYPE_SELL) && PositionGetInteger(POSITION_MAGIC) != MagicNumber)
    { 
      if(CheckNewPosition(position_ticket))
      {
        Print("position "+(string)position_ticket+" opened");

        bool oppositeAllowed = CountOfTradeWithSameSymbolInArray(symbol) < inputMaxOppositeTradePerSymbol;

        FLOATING_TRADES newTrade;

        newTrade.ticket = position_ticket;
        newTrade.tradeType = (int)PositionGetInteger(POSITION_TYPE);
        newTrade.symbol = symbol;
        newTrade.tradeLots = PositionGetDouble(POSITION_VOLUME); 
        newTrade.stoploss = PositionGetDouble(POSITION_SL);
        newTrade.takeprofit = PositionGetDouble(POSITION_TP);   
        newTrade.oppositeAllowed = oppositeAllowed;

        int size = ArraySize(FloatingTradesArray);
        ArrayResize(FloatingTradesArray, size + 1);
        FloatingTradesArray[size] = newTrade;
      }
    }
  }
}

bool CheckNewPosition(ulong positionTicket)
{
  bool result = true;

  for(int i=0; i<ArraySize(FloatingTradesArray); i++)
  {
    if(FloatingTradesArray[i].ticket == positionTicket)
    {
      result = false;
      break;
    }  
  }

  return result;
}

void FindClosedPositions()
{
  for(int i=0; i<ArraySize(FloatingTradesArray); i++)
  {
    ulong PositionTicket = FloatingTradesArray[i].ticket;
    ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)FloatingTradesArray[i].tradeType;
    string symbol = FloatingTradesArray[i].symbol;
    double lot = FloatingTradesArray[i].tradeLots;
    double stoploss = FloatingTradesArray[i].stoploss;
    double takeprofit = FloatingTradesArray[i].takeprofit;
    bool oppositeAllowed = FloatingTradesArray[i].oppositeAllowed;

    if(PositionTicket != 0 && (type==POSITION_TYPE_BUY || type==POSITION_TYPE_SELL))
    {
      if(!CheckIfPositionIsFloating(PositionTicket) && CheckPositionFromHistory(PositionTicket))
      {
        Print("position "+(string)PositionTicket+" closed");

        if(oppositeAllowed)
        {
          if(OpenOppsitePositionOpened(PositionTicket, symbol, type, lot, stoploss, takeprofit))
          {      
            Print("oppsite of position "+(string)PositionTicket+" opened");
            int size = ArraySize(FloatingTradesArray);
            for (int j = i + 1; j < size; j++) 
            {
              FloatingTradesArray[j - 1] = FloatingTradesArray[j];
            }
            size--;
            ArrayResize(FloatingTradesArray, size);
          }  
        }
        else
        {
          int size = ArraySize(FloatingTradesArray);
          for (int j = i + 1; j < size; j++) 
          {
            FloatingTradesArray[j - 1] = FloatingTradesArray[j];
          }
          size--;
          ArrayResize(FloatingTradesArray, size);
        }
      }
    }
  }
}

bool CheckIfPositionIsFloating(ulong PositionTicket) 
{ 
  bool result = false;

  for(int i=PositionsTotal()-1; i>=0; i--)
  {     
    ulong position_ticket = PositionGetTicket(i);  
    if(position_ticket == PositionTicket)
    {
      result = true;    
      break;   
    }                                      
  }
  return result;
}

bool CheckPositionFromHistory(ulong positionTicket) 
{
  bool result = false;

  if(HistorySelectByPosition(positionTicket))
  {  
    ulong dealTicket = 0;
    int DealEntry;
 
    for(uint j = 0; j<2; j++)
    {   
      if((dealTicket=HistoryDealGetTicket(j))>0)
      {  
        DealEntry = (int)HistoryDealGetInteger(dealTicket,DEAL_ENTRY);
        if(DealEntry==DEAL_ENTRY_OUT) result = true;
      }
    }
  } 

  return result;
}

bool OpenOppsitePositionOpened(long ticket, string symbol, ENUM_POSITION_TYPE positionType, double lot, double sl,double tp)
{
  if(!inputOpenOppositeTradeAfterClose) return true;

  string tradeComment = "opp:"+(string)ticket;  

  if(CheckIfPositionIsOpened(tradeComment)) return true;
  if(CheckIfOrderIsOpened(tradeComment)) return true;

  ENUM_POSITION_TYPE OppPositionType = ReversePosition(positionType); 

  double temp = sl;
  sl = tp;
  tp = temp;

  if(OppPositionType == POSITION_TYPE_BUY) return OpenBuyPosition(symbol, lot, sl, tp, tradeComment);
  else if(OppPositionType == POSITION_TYPE_SELL) return  OpenSellPosition(symbol, lot, sl, tp, tradeComment);
  
  return false;
}

ENUM_POSITION_TYPE ReversePosition(ENUM_POSITION_TYPE positionType)
{
  if(positionType == POSITION_TYPE_BUY) return POSITION_TYPE_SELL; //buy reverse to sell
  else if(positionType == POSITION_TYPE_SELL) return POSITION_TYPE_BUY; //sell reverse to buy
  
  return positionType;
}

bool OpenBuyPosition(string symbol,double lot,double sl,double tp, string comment)
{
  bool res = false;

  MqlTradeRequest request={};
  MqlTradeResult  result={};

  request.action = TRADE_ACTION_DEAL;                    
  request.symbol = symbol;                             
  request.volume = lot;                                
  request.type = ORDER_TYPE_BUY;                        
  request.price = SymbolInfoDouble(symbol,SYMBOL_ASK); 
  request.sl = sl;                    
  request.tp = tp; 
  request.deviation = slippage;                                     
  request.type_filling = typeFilling;   
  request.comment = comment;
  request.magic = MagicNumber;               
  
  if(!OrderSend(request,result))
  {
    PrintFormat("OrderSend error %d",GetLastError());
    res = false;
  }
  else res = true;

  return res;
}

bool OpenSellPosition(string symbol,double lot,double sl,double tp, string comment)
{
  bool res = false;

  MqlTradeRequest request={};
  MqlTradeResult  result={};

  request.action = TRADE_ACTION_DEAL;                  
  request.symbol = symbol;                              
  request.volume = lot;                                  
  request.type = ORDER_TYPE_SELL;                       
  request.price = SymbolInfoDouble(symbol,SYMBOL_BID); 
  request.sl = sl;                    
  request.tp = tp; 
  request.deviation = slippage;                                     
  request.type_filling = typeFilling;   
  request.comment = comment;   
  request.magic = MagicNumber;         

  if(!OrderSend(request,result))
  {
    PrintFormat("OrderSend error %d",GetLastError()); 
    res = false;
  }
  else res = true;

  return res;
}

bool CheckIfPositionIsOpened(string positionComment) 
{
  bool result = false;
  for(int i=PositionsTotal()-1; i >= 0; i--)
  {   
    ulong position_ticket=PositionGetTicket(i);   
    string position_comment = PositionGetString(POSITION_COMMENT);          
    if(position_comment==positionComment)
    {
      result = true;
      break;
    }                                              
  }
  return result;
}

bool CheckIfOrderIsOpened(string orderComment) 
{
  bool result = false;
  for(int i=OrdersTotal()-1; i >= 0; i--)
  {   
    ulong orderticket=OrderGetTicket(i);   
    string order_comment = OrderGetString(ORDER_COMMENT);          
    if(order_comment==orderComment)
    {
      result = true;
      break;
    }                                              
  }
  return result;
}
 
int CountOfTradeWithSameSymbolInArray(string symbol)
{
  int count = 0;

  for(int i=0; i<ArraySize(FloatingTradesArray); i++)
  {
    if(FloatingTradesArray[i].symbol == symbol) count++;
  }

  return count;
}

Con risposta

1
Sviluppatore 1
Valutazioni
(8)
Progetti
11
18%
Arbitraggio
7
43% / 29%
In ritardo
1
9%
Gratuito
2
Sviluppatore 2
Valutazioni
(75)
Progetti
92
42%
Arbitraggio
4
50% / 50%
In ritardo
2
2%
Gratuito
3
Sviluppatore 3
Valutazioni
(10)
Progetti
15
27%
Arbitraggio
3
67% / 33%
In ritardo
0
Gratuito
4
Sviluppatore 4
Valutazioni
(37)
Progetti
59
27%
Arbitraggio
25
20% / 52%
In ritardo
10
17%
In elaborazione
5
Sviluppatore 5
Valutazioni
(128)
Progetti
162
36%
Arbitraggio
4
25% / 50%
In ritardo
13
8%
Gratuito
6
Sviluppatore 6
Valutazioni
(96)
Progetti
143
76%
Arbitraggio
0
In ritardo
2
1%
Gratuito
Ordini simili
GOODAY TO YOU I AM NEED OF A FAST, TALENTED AND HIGH QUALITY CODER TO THIS JOB FOR ME. THE EA TRADE MANAGER WILL HAVE THE FOLLOWING: STOPLOSS & TAKEPROFIT IN PIPS LOT SIZE IN PIPS NUMBER OF TRADES (1-30 TRADES MAXIMUM) PLEASE LOOK AT THE PICTURE ABOVE FOR A GUIDE
evalq({ #نوع دالة التنشيط. الحقيقة <- c( "sig" , #: sigmoid "sin" , #: sine "radbas" , #: radial basis "hardlim" , #: hard-limit "hardlims" , #: symmetric hard-limit "satlins" , #: satlins "tansig" , #: tan -sigmoid "tribas" , #: triangular basis "poslin" , #: positive linear "purelin" ) #: linear السندات
Hello, I want to create an EA with the belowspecification. EA will check conditions based on following input parameters: ● High Price ● Low Price ● Move Value (in Price) ● Gap (in price) After start, EA will mark High and Low prices based on input parameters. EA will start trading when the current price will hit any of the price POSITION at High , Low, Control Buy or Control Sell . EA will open
a gap between 1 pip opposite order open continue once tp hit ea change position and start from 1 everything is manually adjustable tp gap pip and pip all show start from 0.01
If you are knowledgeable in hedging strategy we can chat. I created my simple EA using Fxdreema , so you only need to modify it for me. There are two parts of the EA , 1. Is the execution strategy 2. Is the money management strategy (hedging). I already created number 1 which is the execution of trades , I only need someone who can implement hedging in every orders the EA create. Additional Parameters needed. Trade
Necesito una placa EA que me permita ejecutar órdenes buy limit sell limit buy stop sell stop pero estas órdenes su tp su stop loss si triling stopp su punto de equilibrio debe ser virtual y algunas especificaciones mas solo aplican si tienes experiencia adjunta un ejemplo quiero algo como esto pero mas simple https://www.mql5.com/es/market/product/73489?source=Site +Market+MT5+Search+Rating006%3aEasyGRID+MT5
Hello Im looking for professional trading developer who htf ready made trading with best and working strategy with low risk level with average of 30 to 60 percent profit margin, broker is not problem, any broker is welcomed and any trading pairs are welcomed as well
Black Tokens EA 30+ USD
I want yo create a trading robot which can analyse into the markets and be able to spot what the market targets (Arrays) the robot should make out my strategies and respect them well
I am looking for a developer to create an automated ATM strategy for NinjaTrader. The strategy should operate as follows: Trade Entry : Manual entry based on a bullish or bearish engulfing pattern. Stop Loss : Set at the low of the previous candle for long trades and at the high of the previous candle for short trades, covering the entire candle body and wicks. Take Profit : Set at twice the size of the stop loss
i need to convert this indicator (check the points=are the trades - m5 chart), i need the exact trades as expert on mt4, apply only if you are sure to complete this project 100%, i dont want leave bad feedbacks please, i hope you can understand, if you want have a major consideration, tell me how it works so i can know that you have the knowlodge to do this work

Informazioni sul progetto

Budget
30+ USD
Per lo sviluppatore
27 USD