Need help to create an EA for Pending Orders

MQL5 Experten

Auftrag beendet

Ausführungszeit 1 Tag

Spezifikation

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

Bewerbungen

1
Entwickler 1
Bewertung
(1928)
Projekte
3548
88%
Schlichtung
73
40% / 15%
Frist nicht eingehalten
268
8%
Frei
2
Entwickler 2
Bewertung
(11)
Projekte
17
41%
Schlichtung
4
0% / 100%
Frist nicht eingehalten
5
29%
Frei
Ähnliche Aufträge
Black dragon MT5 indicator. EA to take the buy and sell signal with selectable timeframe and lot size. Strategies could be either with or without martingale and with or without hedge. If you already have something similar EA ready to take this signal. Please take the work order for further discussion. Budget negotiable. Thanks. https://www.mql5.com/en/market/product/62749#!tab=overview&nbsp;
Hello, I am looking for a Filipino MQL5 (MT5) programmer who can develop a simple automated trading EA for my personal live trading account (not for prop firm use). Strategy Details: Pair: XAUUSD (Gold) only Timeframe: 1 Hour (H1) Daily range-based pending order system Fixed Stop Loss: 20.00 price movement Step trailing system (moves every +20.00 profit) Maximum 1 trade per day No martingale No grid Features
Vell 35+ USD
Advanced trading robot built on ICT concepts and structured Price Action methodology. Designed to identify liquidity zones, market structure shifts, and high-probability entries while maintaining disciplined risk management and optimized trade execution for consistent, rule-based performance
I NEED A PROFITABLE EA 50 - 150 USD
This may be a weird request but if anyone has an EA that is actually consistently profitable I want to buy a copy of the source code from you. Ideally trades a lot, I'm sure theres a coder out there who has made a profitable EA, I want to backtest if you have, I have been trying to code a few on my own with no success as I'm not yet good at coding. In the mean time I need something profitable. bonus points if it
Yash Agrawal 30+ USD
// Simple EMA Bot input int FastEMA = 9; input int SlowEMA = 21; void OnTick() { double fast = iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,0); double slow = iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,0); if(fast > slow) { if(PositionsTotal()==0) OrderSend(Symbol(),OP_BUY,0.01,Ask,10,0,0); } if(fast < slow) { if(PositionsTotal()==0) OrderSend(Symbol(),OP_SELL,0.01,Bid,10,0,0); } }
Gold robot Ga1 30 - 200 USD
mport pandas as pd import numpy as np def detecter_tendance(data): # Code pour détecter la tendance pass def identifier_niveaux(data): # Code pour identifier les niveaux de support et de résistance pass def calculer_stop_loss(tendance, support, resistance): # Code pour calculer les stop loss pass def calculer_profils(tendance, support, resistance): # Code pour calculer les profils mport pandas as pd
I need modifications and restructuring of an existing MetaTrader 5 Expert Advisor (MQL5) . The current EA works with only one filter for trade entry. I need it redesigned to support 10 optional filters , with flexible configuration and improved Renko logic. I will provide the full .mq5 source code . The EA currently opens trades only when the selected filters agree in direction. 1) 10 Optional Filters System The EA
Seeking an experienced quantitative developer to build a custom, AI-powered Telegram signal parsing and trade execution system. The goal is to automatically copy trading signals from multiple Telegram providers to MetaTrader 5 with ultra-low latency and intelligent signal interpretation. Body: Looking for an experienced developer to build a custom signal copier system. Skills Required: - MQL5 / MetaTrader 5
I need a hft bot that works well on live market. I have tested some bot and they only perform on demo market. If you have any one that is profitable in the live market, pls send a message. I will need to test it before paying. Pls make sure the bot is profitable in LIVE MARKET
Mt4 ea 50 - 150 USD
looking for create ea for mt4 or mt5 which for gold which open buy and sell stop order on previous day high and previous day low , after enter the trade it will trail aggressively. need optimization and back test report. have selectable profiles for gold, forex and index. selection for trade based on fixed lot or equity base

Projektdetails

Budget
20 - 40 USD
Ausführungsfristen
von 2 bis 4 Tag(e)