my code and ordersend dont work! please help me.

 
this is my code. i jast want EA after run, buy 0.1 lot of symbol in Ask price. but this code dont work and show me 10013 return code. please help me. what is problem and how i can solve it. tnx.
int OnInit()
  {
   MqlTradeRequest request;
   MqlTradeResult result;
   
   request.action = TRADE_ACTION_DEAL;
   request.type = ORDER_TYPE_BUY;
   request.symbol = _Symbol;
   request.volume = 0.01;
   request.type_filling = ORDER_FILLING_FOK;
   request.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   request.sl = request.price - (request.price * 0.2);
   request.tp = request.price + (request.price * 0.2);
   
   
   OrderSend(request,result);
   
   if(result.retcode == 10008 || result.retcode == 10009)
   {
      Comment("Trade placed");
   }
   else
   {
      Comment("Trade not placed. Error code ",result.retcode);
   }
   
   Comment("Return Code:",result.retcode,", Volume: ",result.volume,
         ", Price: ",result.price,", Bid: ",result.bid,", Ask: ",result.ask);
   
   return(INIT_SUCCEEDED);
  }
 

Use a simple option. This script is a one-off program. Attention: this is not an expert!

//+------------------------------------------------------------------+
//|                                                     Open Buy.mq5 |
//|                         Copyright © 2018-2021, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018-2021, Vladimir Karputov"
#property version   "1.001"
//---
#include <Trade\Trade.mqh>
CTrade         m_trade;                      // trading object
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(Symbol());
   m_trade.Buy(0.01); // open Buy position, volume 0.01 lot
  }
//+------------------------------------------------------------------+
 
Vladimir Karputov:

Use a simple option. This script is a one-off program. Attention: this is not an expert!

i know but how i can buy or sell when price break moving average line? can you show me this expert code?
 
reza bhamanian :
i know but how i can buy or sell when price break moving average line? can you show me this expert code?

First, you need to learn how to create an indicator and receive data from the indicator: Creating an iMA indicator handle, getting indicator values

How to start with MQL5
How to start with MQL5
  • 2020.03.05
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
Reason: