Need help to create an EA for Pending Orders

MQL5 Experts

Trabalho concluído

Tempo de execução 1 dia

Termos de Referência

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

Respondido

1
Desenvolvedor 1
Classificação
(1858)
Projetos
3462
88%
Arbitragem
73
40% / 15%
Expirado
265
8%
Trabalhando
2
Desenvolvedor 2
Classificação
(11)
Projetos
17
41%
Arbitragem
4
0% / 100%
Expirado
5
29%
Livre
Pedidos semelhantes
NADGIO 30+ USD
I need a developer that can convert two Buy and Sell indicators into a trading robot. the indicators has an input parameter, this should be made available for adjustment. Features 1. Break Even 2. Trailing Stop 3. Global TP and SL 5. Time Filter 6. News Filter (If possible)
I need a developer who can convert trading view indicator in to mt5 expert advisor with some modifications. The other details will shared once chosen the developer. Looking for someone who has good knowledge of forex, mql5,and pine script
Hello, i hope you all well. I am looking or a good developer who can understand SCM/ICT concepts so that can modify an existing EA to trade against that. The EA is already there with code and it was trading based on Breakouts zones. Now i want the EA to be modified so that it trades based on inducements and liquidity. The EA should use Pending orders on those zones instead. I do not want new developers to apply
EA for index trading using ATR % of 5day 1 Give Average true range for the past 5 day so 5day ATR also for ref use the indicator "atr value indicator " my entries will be based on a % of this NO. NO. TO BE SHOWN IN TOP CORNER The Expert im looking for is 1.AT X TIME (ie 8:am ) 2.IF price moves X % of the 5 day atr( either up or down ) within Y TIME (IE 5MINUTES ) (if PRICE moves say 30% of the 5 day atr down i buy or
I want to create an Expert Advisor (EA) that can be set to open either buy or sell trades, depending on user preference (buy-only or sell-only mode). The EA will initiate trades when the market reaches (or is equal to or less than) a specified DeMarker value (e.g., DeMarker value = 0.3). The user will set both the DeMarker value for starting trades and another DeMarker value to stop opening new trades. - **DeMarker
Create a mql5 expert advisor for forex/commodities trading based on modified candlestick formation. If modified bullish engulfing appears, EA will open buy position at closing of last candle area with martingale until opening of last candle area and set stop loss at open last candle area. Trailing stop appears when half of all buy positions running profit then when all buy positions running profit, and so on. If
I want to grid based robot such like CM Manual Grid for mt 5 Snap of that attached. like The expert Advisor helps set a network of pending orders and collect profit from any price movement. I can use it to trade many grid strategies. I can also use it to track open positions. "Buy Stop — - open a network of pending stop orders for sale "Sell Stop" - open a network of pending stop orders for purchase "Buy Limit" -
I have developed a very strong TradingView strategy in Pine Script but unfortunately, a third-party connector is requiired and in my opinion, I want a more direct connection. I am not brilliant at coding, but I have coded the majority of the MT5 code and I would like you to make sure that the MT5 code matches my TradingView script and executes the same way as the TradingView script
Hi, I would like to have an EA to open trade when 2 time frame met the condition. Need to have ability to select the TF combination, Example: H4 with H1, H1 with M15 etc. PS: Able to lock EA with "Name" or "Account Number" PSS: Able to set trading session for specific pair. Example: US session = EURUSD For Buy #1 Big TF Candle Closed Outside Top BB #2 Big TF Candle touch low MA #3 Got to Smaller TF Candle touch &
I have thee best concept period, hence i got less to say. Actions speaks louder then words. Sign up and lets get started as there is a big world that awaits all your your adventures

Informações sobre o projeto

Orçamento
20 - 40 USD
Desenvolvedor
18 - 36 USD
Prazo
de 2 para 4 dias