Need help to create an EA for Pending Orders

MQL5 Uzman Danışmanlar

İş tamamlandı

Tamamlanma süresi: 1 gün

İş Gereklilikleri

Hello MQL5 freelancers, good day.


I’m just starting to learn MQL5 and I’ve started reading the MQL5 Docs and a couple tutorials for beginners but haven’t found a good tutorial on how to place pending orders using Buy Stop and Sell Stop. I would like to know if anybody could teach me how to do what I need with one or two freelance jobs, this way I could get the grasp of it a little bit faster and start learning by the example of an experienced MQL5 programmer.


Here are the basic rules for my first EA:


1. Check ADX Indicator and determine if +DI > -DI or +DI < -DI; assign this to variables used for next steps.

    a) Buy_Condition = +DI > -DI;

    b) Sell_Condition = +DI < -DI;

 

2. If +DI > -DI the order should be Buy Stop and if +DI < -DI the order should be Sell Stop.

    a) If +DI > -DI look for black candles (bears) and if +DI < -DI look for white candles (bulls).

    b) Once this conditions are met respectively, open a position to buy or sell (depending on the criteria) with Open price from previous bar/candle.


3. If the order is Buy Stop, Stop Loss should be equal to: Low price from previous bar/candle -0.1 cents; if the order is Sell Stop, Stop Loss should be equal to: High price from previous bar/candle +0.1 cents.


4. The timeframe/period for this should be daily (D1).


For this EA I think I won’t be needing Moving Average nor Take Profit.

 

Here is the code I have started to create but could't place any orders yet:

 

// Input variables

input double Lots    = 0.1;

input int StopLoss   = 1000;

input int TakeProfit = 1000;

input int MAPeriod   = 10;

input int ADXPeriod  = 14;

// Global variables

bool glBuyPlaced, glSellPlaced;

// OnInit() event handler

int OnInit()

  {

//---

   

//---

   return(0);

  }

// OnTick() event handler

void OnTick()

{

// Trade structures

MqlTradeRequest request;

MqlTradeResult result;

ZeroMemory(request);

// Moving average

double ma[];

ArraySetAsSeries(ma,true);

int maHandle=iMA(_Symbol,0,MAPeriod,MODE_SMA,0,PRICE_CLOSE);

CopyBuffer(maHandle,0,0,1,ma);

// ADX Indicator values

double ADX_Val[], Plus_DI[], Minus_DI[];

ArraySetAsSeries(ADX_Val,true);

ArraySetAsSeries(Plus_DI,true);

ArraySetAsSeries(Minus_DI,true);

int ADX_Handle = iADX(NULL, 0, ADXPeriod);

CopyBuffer(ADX_Handle, 0, 0, 3, ADX_Val);

CopyBuffer(ADX_Handle, 1, 0, 3, Plus_DI);

CopyBuffer(ADX_Handle, 2, 0, 3, Minus_DI);

// Open price

double open[];

ArraySetAsSeries(open,true);

CopyOpen(_Symbol,0,0,1,open);

// High price

double high[];

ArraySetAsSeries(high,true);

CopyHigh(_Symbol,0,0,1,high);

// Low price

double low[];

ArraySetAsSeries(low,true);

CopyLow(_Symbol,0,0,1,low);

// Close price

double close[];

ArraySetAsSeries(close,true);

CopyClose(_Symbol,0,0,1,close);

// Current position information

bool openPosition = PositionSelect(_Symbol);

long positionType = PositionGetInteger(POSITION_TYPE);

double currentVolume = 0;

if ( openPosition == true ) currentVolume = PositionGetDouble(POSITION_VOLUME);

// Open buy market order

if ( Plus_DI[0] > Minus_DI[0] && glBuyPlaced == false && (positionType != POSITION_TYPE_BUY || openPosition == false) )

{

request.action = TRADE_ACTION_PENDING;

request.type = ORDER_TYPE_BUY_STOP;

request.symbol = _Symbol;

request.volume = Lots + currentVolume;

request.type_filling = ORDER_FILLING_FOK;

request.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

request.sl = 0;

request.tp = 0;

request.type_time = ORDER_TIME_SPECIFIED;

request.deviation = 50;

request.stoplimit = 0;

OrderSend(request,result);

// Modify SL/TP

if ( result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE )

{

request.action = TRADE_ACTION_SLTP;

do Sleep(100); while(PositionSelect(_Symbol) == false);

double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);

if ( StopLoss > 0 ) request.sl = positionOpenPrice - (StopLoss * _Point);

if ( TakeProfit > 0 ) request.tp = positionOpenPrice + (TakeProfit * _Point);

if ( request.sl > 0 && request.tp > 0 ) OrderSend(request,result);

glBuyPlaced = true;

glSellPlaced = false;

}

}

// Open sell market order

else if ( Minus_DI[0] < Plus_DI[0] && glSellPlaced == false && positionType != POSITION_TYPE_SELL )

{

request.action = TRADE_ACTION_PENDING;

request.type = ORDER_TYPE_SELL_STOP;

request.symbol = _Symbol;

request.volume = Lots + currentVolume;

request.type_filling = ORDER_FILLING_FOK;

request.price = SymbolInfoDouble(_Symbol,SYMBOL_BID);

request.sl = 0;

request.tp = 0;

request.type_time = ORDER_TIME_SPECIFIED;

request.deviation = 50;

request.stoplimit = 0;

OrderSend(request,result);

// Modify SL/TP

if ( (result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE) && (StopLoss > 0 || TakeProfit > 0) )

{

request.action = TRADE_ACTION_SLTP;

do Sleep(100); while(PositionSelect(_Symbol) == false);

double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);

if ( StopLoss > 0 ) request.sl = positionOpenPrice + (StopLoss * _Point);

if ( TakeProfit > 0 ) request.tp = positionOpenPrice - (TakeProfit * _Point);

if ( request.sl > 0 && request.tp > 0 ) OrderSend(request,result);

glBuyPlaced = false;

glSellPlaced = true;

}

}

} 

  

I hope someone could point me in the right direction and help me to solve this EA.


Regards and thank you in advance,

codeMolecules

Yanıtlandı

1
Geliştirici 1
Derecelendirme
(1925)
Projeler
3542
88%
Arabuluculuk
73
40% / 15%
Süresi dolmuş
268
8%
Serbest
2
Geliştirici 2
Derecelendirme
(11)
Projeler
17
41%
Arabuluculuk
4
0% / 100%
Süresi dolmuş
5
29%
Serbest
Benzer siparişler
Hello everyone, I’m looking for a reliable and well-tested EA that can either pass prop firm challenges (such as FTMO, MyForexFunds, etc.) or show consistent long-term performance on a funded account. Requirements: Maximum drawdown: 1–2% per trade Adjustable lot size based on account size Solid risk management with on-chart panel (daily drawdown, equity, profit target, etc.) Proper Stop Loss and Take Profit logic —
Quiero un bot que cuando una vela manipule un soporte o resistencia y deje una mecha el bot envie una señal al mt5 o ejecute una operación. Debe tener 2 formas 1enviar la señal visual en mt5. 2 ejecutar la operación poniendo el sl x pips por debajo de la mecha, debe tener incorporado un indicador de soporte y resitencias. El tp debe ajustarse según el sl, de esta manera, si el sl es 50 pips
I need a very simple EA which: Works on the latest levels of top/ bottoms. Support and resistance are the latest bottom and tops on the chart and they keep changing upon the formation of new top/ bottoms. Whenever a new top/ bottom forms, these resistance/ support levels change accordingly. Support and resistance horizontal lines should be drawn by the EA in the red colour. EA should draw the horizontal lines on the
Would it be possible to get a custom offer for creating a script that would draw trendlines for multiple timeframes both top and bottom of the candles, I would like the script to monitor the chart and provide me notification when the chart touches the trendline either top or bottom. If I have a position in the chart, the notification of provide me a notification of my position during each timeframe and well as when
I am looking for a developer with experience in MM and great coding skills in MT4. I have 2 indicators to be used to develop an EA with built in news feature and a few extras which i will disclose to the successful appointed developer. I would also want a panel showing on the top left hand corner of the chart (i can move the panel around anywhere on the chart) displaying certain info such as BROKER NAME, OPEN
MT5 Algo Development – Based on 2 Custom Pine Indicators + Heikin Ashi Candle Project Description: I want to develop an MT5 Expert Advisor (EA) that takes trades automatically based on two custom indicators and Heikin Ashi candle confirmation as per the trade setup explained in my attached PDF. The EA should execute trades exactly as per the logic described in the PDF and include the following user-configurable
I need a MT4 tool for different approaches of extremely detailed and complex calculations. The tool is to be done from the beginning with full programming code and unlimited license (no expiry!) to be provided. I should be able to use the tool on unlimited quantity of MT4 terminals at the same time, even on unlimited quantity of computers. Within the same project, I need from you yet another subproject: Another work
- EMA 20 + EMA 50 setup - Price EMA pe bounce kare - RSI (14) 40-60 range mein ho - Entry: Bounce confirmed - SL: EMA ke neeche - TP: 1.5% to 3%
Technical Project Description: AI-Enhanced Adaptive Trading Expert Advisor I want to commission the development of a high-performance AI-powered Expert Advisor (EA) designed for MetaTrader 5 , optimized for indices (e.g., Volatility 75 Index) , gold (XAU/USD) , and crypto pairs (BTC/USD) . The EA should intelligently adapt to market volatility using machine learning or AI-based decision-making to refine its entry and
Looking for a bot that has good win rate with at least 1 year history verified performance that can pass ftmo challenge and can keep it after challenge passed that Will profit monthly 7 percent minimum

Proje bilgisi

Bütçe
20 - 40 USD
Geliştirici için
18 - 36 USD
Son teslim tarihi
from 2 to 4 gün