ea code help wont execute trades

 

hi im new to coding and i cannot get my ea to execute trades on the strategy tester i keep getting this error or variation of this error :

2024.04.13 15:21:45.619 2023.01.09 13:27:02   failed market buy 0.01 EURUSD sl: 1.06725 tp: 1.07025 [Invalid request]

2024.04.13 15:21:45.619 2023.01.09 13:27:02   CTrade::OrderSend: market buy 0.01 position #266403325 EURUSD sl: 1.06725 tp: 1.07025 [invalid request]

my ea is 

//+------------------------------------------------------------------+

//|                     Simple ADX System - Uptrend - Buy Signal.mq5 |

//|                                  Copyright 2022, MetaQuotes Ltd. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2022, MetaQuotes Ltd."

#property link      "https://www.mql5.com"

#property version   "1.00"

//+------------------------------------------------------------------+



// Include MQL5 header file

#include <Trade\Trade.mqh>



// Global variable for the ticket of the order

ulong orderTicket = ulong(-1); // Changed from 'long' to 'ulong'



// Create instance of CTrade

CTrade trade;



void OnTick()

{

   // creating a variable for signal

   string signal="";

   

   //creating an array for prices

   double ADXArray0[];

   double ADXArray1[];

   double PDIArray[];

   double NDIArray[];

   

   //identify ADX, positive DI, negative DI

   int ADXDef = iADX(_Symbol,_Period,14);

   

   

   //sort price array from current data

   ArraySetAsSeries(ADXArray0,true);

   ArraySetAsSeries(ADXArray1,true);

   ArraySetAsSeries(PDIArray,true);

   ArraySetAsSeries(NDIArray,true);

   

   //Filling data according to created ADX

   CopyBuffer(ADXDef,0,0,3,ADXArray0);

   CopyBuffer(ADXDef,0,0,2,ADXArray1);

   CopyBuffer(ADXDef,1,0,3,PDIArray);

   CopyBuffer(ADXDef,2,0,3,NDIArray);

   

   //Getting value of current data

   double ADXValue=NormalizeDouble(ADXArray0[0],2);

   double ADXValueLast=NormalizeDouble(ADXArray1[1],2);

   double PDIValue=NormalizeDouble(PDIArray[0],2);

   double NDIValue=NormalizeDouble(NDIArray[0],2);

   

   //Comment with Buy signal according to Buy Strategy

   if (ADXValue>25&&ADXValue>ADXValueLast)

   {

      if(PDIValue>NDIValue)

      {

         signal = "BUY";

         if(orderTicket == ulong(-1)) // If there is no open order

         {

            MqlTradeRequest request;

            MqlTradeResult result;

            

            request.action = TRADE_ACTION_DEAL;

            request.symbol = _Symbol;

            request.volume = 0.01;

            request.type = ORDER_TYPE_BUY;

            request.price = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

            request.deviation = 100;

            request.magic = 2402;

            request.comment = "Buy order";



            // Set stop loss and take profit a fixed distance away from the order price

            request.sl = request.price - 0.0010; // Adjusted stop loss

            request.tp = request.price + 0.0020; // Adjusted take profit



            if(!trade.OrderSend(request,result))

            {

               Print("OrderSend failed with error ",trade.ResultRetcode());

               Print("Last error description: ", trade.ResultRetcodeDescription());

            }

            else

            {

               orderTicket = result.order;

            }

         }

      }

   }

   

   if(orderTicket != ulong(-1)) // If there is an open order

   {

      if(!PositionSelectByTicket(orderTicket)) // Changed from 'PositionSelect(_Symbol)' to 'PositionSelectByTicket(ticket)'

      {

         Print("Error selecting position by ticket ",orderTicket);

      }

      else

      {

         if(!trade.PositionClose(orderTicket)) // Changed from 'OrderClose(ticket, volume, price, 3)' to 'trade.PositionClose(ticket)'

            Print("PositionClose failed with error ",trade.ResultRetcode());

         else

            orderTicket = ulong(-1); // Reset the ticket variable

      }

   }

      

   Comment("Simple ADX System - Signal is ",signal,"\n""ADX Value is ", ADXValue,

   "\n""ADX Value Last is ", ADXValueLast, "\n""+DI Value is ", PDIValue,

   "\n""-DI Value is ", NDIValue);

}

//+------------------------------------------------------------------+


any help greatly appreciated



Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2024.04.13
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Do you built it for MT4. I can help with MT4 version.
 
Arif Ahmed #:
Do you built it for MT4. I can help with MT4 version.

no its for mt5

 
slammizzle:

hi im new to coding and i cannot get my ea to execute trades on the strategy tester i keep getting this error or variation of this error :

2024.04.13 15:21:45.619 2023.01.09 13:27:02   failed market buy 0.01 EURUSD sl: 1.06725 tp: 1.07025 [Invalid request]

2024.04.13 15:21:45.619 2023.01.09 13:27:02   CTrade::OrderSend: market buy 0.01 position #266403325 EURUSD sl: 1.06725 tp: 1.07025 [invalid request]

my ea is 


any help greatly appreciated



Print the request together with Ask & Bid to see whether all parameters of your order are on the right side and have the correct distance - don't forget you bay at Ask and sell at Bid.

 
slammizzle:

hi im new to coding and i cannot get my ea to execute trades on the strategy tester i keep getting this error or variation of this error :
2024.04.13 15:21:45.619 2023.01.09 13:27:02   failed market buy 0.01 EURUSD sl: 1.06725 tp: 1.07025 [Invalid request]
2024.04.13 15:21:45.619 2023.01.09 13:27:02   CTrade::OrderSend: market buy 0.01 position #266403325 EURUSD sl: 1.06725 tp: 1.07025 [invalid request]
my ea is 
any help greatly appreciated


Hi, you can search it in Codebase,

Example :
https://www.mql5.com/en/code/258

MQL5 Wizard - Trade Signals Based on Price Crossover with Moving Average, confirmed by ADX
MQL5 Wizard - Trade Signals Based on Price Crossover with Moving Average, confirmed by ADX
  • www.mql5.com
Trade signals based on price crossover with moving average indicator confirmed by ADX is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.
 
slammizzle:

hi im new to coding and i cannot get my ea to execute trades on the strategy tester i keep getting this error or variation of this error :

2024.04.13 15:21:45.619 2023.01.09 13:27:02   failed market buy 0.01 EURUSD sl: 1.06725 tp: 1.07025 [Invalid request]

2024.04.13 15:21:45.619 2023.01.09 13:27:02   CTrade::OrderSend: market buy 0.01 position #266403325 EURUSD sl: 1.06725 tp: 1.07025 [invalid request]

my ea is 


any help greatly appreciated



To be honest, this code does not look hand written, looks like Ai had its fair share here. 

 
Nardus Van Staden #:

To be honest, this code does not look hand written, looks like Ai had its fair share here. 

it is mainly ai as i said im new to coding :(
 
Carl Schreiber #:

Print the request together with Ask & Bid to see whether all parameters of your order are on the right side and have the correct distance - don't forget you bay at Ask and sell at Bid.

thank you i will try this
 
Yohana Parmi #:


Hi, you can search it in Codebase,

Example :
https://www.mql5.com/en/code/258

i just tried to use this ea but it wont let me compile i think i need the signal file 
Reason: