Need help to create an EA for Pending Orders

MQL5 Эксперты

Работа завершена

Время выполнения 1 день

Техническое задание

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

Откликнулись

1
Разработчик 1
Оценка
(1862)
Проекты
3465
88%
Арбитраж
73
40% / 15%
Просрочено
265
8%
Свободен
2
Разработчик 2
Оценка
(11)
Проекты
17
41%
Арбитраж
4
0% / 100%
Просрочено
5
29%
Свободен
Похожие заказы
Preciso de um EA que abra ordens a mercado a partir de um indicador, Ele precisa obter take e stop loss fixos, spread máximo, horários de início e final das operações, meta e stop diário, martingale, painel e a função no script para que eu possa ceder o EA apartir do id do mt4 de terceiros
Hello Investors, I'm selling a profitable and stable expert advisor trading on the Gold (XAUUSD) pair using a cutting-edge scalping strategy. The EA is able to generate a stable monthly income without using martingale strategy, and with an optional cut loss in place. Particularly the average monthly gain can go from 2-3% (at a relatively low risk, with an historical max DD of 6%) to 20-30% (with an aggressive style
Hello, I have a strategy and I need a very good programmer who will create me an exprt or make me an indicator that will open positions for buy/sell limit (see picture below). The indicator/Expert will have to open positions (buy/sell limit) regarding the strategy and indicators (I will explain it more in collaboration). Below I will give pictures of what I mean. I will send a link to the telegram group where it
Atomic Analyst Indicator to EA. I have an mt4 indicator called Atomic Analyst. The indicator gives buy/sell signals as shown in the screenshot. I want to know if you can take this indicator, and create an EA that automatically takes the signals. The indicator puts in the SL and TP1, TP2, TP3, TP4, TP5 automatically. I would like the option to put in my lot size parameter and I would also like an automatic trail stop
can you help me with Ctrader i need modification on the linkhttps://docs.google.com/document/d/1fggk49xWbnwahtfOlE-U7G6muZB1FT8eWmftGiY7R-s/edit?usp=sharing can you assist with cTrader modifications to enhance functionality and improve performance. do text me if you a professional on it i will be looking forward to your response best regards
MT4 Expert Advisor 30 - 120 USD
EA sittings The EA utilises the concept of grid and hedging by creating a zone for recovering losing trades It is a continues trading EA without any stop loss. The EA initially aims to trade continually without the need to hedge. The EA enter the first trade following the direction of the moving average (when price is above or below the moving average), and only hedge when, the trade goes against the trend and reach
Would I honestly need is someone who can make a profitable EA for me that can at least make me around $80 a day starting with $50 and the EA must be able to work with exness the EA should automat trades 24/7. Broker = Exness Pairs = USD/JPY XAU/USD and etc Chart time frames = M1 M15 History = last month till last 6 months. Lot size 0.10 take profit at $2 stop
Hello i am seeking a skilled MetaTrader 5 (MQL5) developer to modify an existing Telegram signal copier. The goal is to enhance the copier's functionality, reliability, and user experience. kindly bid this job to get started immediately
Hello, I’m looking for assistance with creating or customizing a TradingView indicator to suit my trading needs. If you have experience in this area, please reach out. Your help would be greatly appreciated. Thanks
# MT4 Expert Advisor Development Rules ## Time Period Definition 1. Allow user to define a specific time period (e.g., 10:00 to 15:00). 2. Identify and store the high and low prices within this period. ## Price Breakout Detection 3. Monitor current price for breakouts above the period high or below the period low. ## Signal Confirmation (signals will be taken on m5 timeframe) 4. After a breakout, wait for a signal

Информация о проекте

Бюджет
20 - 40 USD
Исполнителю
18 - 36 USD
Сроки выполнения
от 2 до 4 дн.