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
(1916)
Projeler
3530
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
I have a working Python script that: – captures messages from several Telegram groups (using Telethon), – parses the content (BUY/SELL signals, TP/SL/BE), – logs the data into specific tabs in a Google Sheets file (via gspread). Problem: The script is unstable — it sometimes ignores messages from certain groups, misses replies, or silently stops processing after a few hours. It needs urgent verification and repair
want an aggressive scalping Expert Advisor (EA) for XAUUSD (Gold) on M1 timeframe with the following features: ✅ Uses a combination of EMA, RSI, and ATR for entry signals. ✅ Recovery Mode to increase lot size on confirmed setups to recover losses safely. ✅ Trailing Stop functionality with adjustable start and step parameters. ✅ Stop trading after daily target or daily loss limit is reached. ✅ Money Management (fixed
Plataforma Meta Trader 5 Apertura sesión de Londres. 2 horas de operativa diaria. Índices, especialmente DAX40. Marco temporal de 5 minutos. Apertura automática de operaciones con cierre automático en TP o SL. Operaciones tanto en compra como en venta. Se pueden tomar todas las operaciones posibles, pero no 2 operaciones a la vez, es decir se tiene que cerrar una operación para abrir otra. Si hay una operación
I want a simple expert Advisor based on macd and ema with patial profit taking based on risk to reward, breakeven also based on risk to reward and trailing also based on risk to reward. stoploss will mostly be placed on candlestick low but instances where there has been a series of candlestick lows, it will be placed on the furthest candlestick low. new trade will be opened when current trade is at breakeven
Hi, I’m looking for an experienced MQL5 developer to replicate an Expert Advisor I currently use for Forex. I don’t have the source code, but I do have all the input settings, behavior structure, and detailed backtesting of how the system should operate. ✅ Basic features the EA should include: Entry logic based on simple technical indicators (e.g., moving average). Take Profit and Stop Loss system using ratios (e.g
i need a developer to code my smc concept only experienced traders contact us we need to finish the job in a short period of time its a simple smc concept all you need is to apply the entry model which i explain to you thank you
I want you to build an Expert Advisor (EA) that mirrors trades between two accounts in opposite directions , maintaining identical TP and SL distances in pips with adjustable lot sizes. The EA logic is as follows: ✅ Core Requirements • EA monitors trades opened on Account A . • When a trade is opened on Account A: • An opposite direction trade is opened on Account B . • The TP and SL distances (in pips) are
Hi, I need an EA for both MT4 and MT5 that pushes JSON data to an API. It needs to push all trade history data, plus the opened trades. It needs to push all account data (including leverage, account type etc), and for trades, it needs to push all the relevant information (open/close time and price, direction, tp/sl levels if set, swap, commission, magic, comment, ticket, etc.) It will send data on the follwing
Create a ZigZag indicator, which is constructed based on extreme values determined using oscillators. It can use any classical normalized oscillator, which has overbought and oversold zones. The algorithm should first be executed with the WPR indicator, then similarly add the possibility to draw a zigzag using the following indicators
I'm looking for a developer to create a trading bot based on order blocks. Entry: on OB via the indicator CODE Exit and Money Management copied from: https://www.mql5.com/en/market/product/55393?source=Site +Market+MT4+Search+Rating006%3adark+venus CODE Goal so I can do multiple iframes But otherwise EURUSD in M1

Proje bilgisi

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