different error

 
//+------------------------------------------------------------------+
//|                                                      Querty2.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Variabili Esterne                                |
//+------------------------------------------------------------------+

extern int MagicNumber=10001;
extern double Lots=0.25;
extern double StopLoss=0;
extern double TP=20;
extern double Rsivaluebuy=60;
extern double Rsivaluesell=40;
extern int Slippage=0;

extern bool lotin=false;

// Variabili Esterne //

extern bool trail=false;
extern bool Azzerastop=true;
extern double TrailingStop=50;

extern double Lotti=0.01;
extern double LottiAzz=0.01;

extern double PuntiAZ=10;
extern double Pips_Stop=10;
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////



double p;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(Point==0.00001) p=0.0001;
   else if(Point==0.01) p=0.01;
   else                  p=Point;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if(Azzerastop) Azzerastop();
   if(lotin) lotin();
   if(trail) trail();
   if(Ordini()==false)
     {
      Trade();



     }

  }
//+------------------------------------------------------------------+
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

int Ordini()
  {
   for(int i=OrdersTotal()-1; i>=0;i--)
     {
      bool result=false;
      result=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         return(true);

     }
   return (false);

  }
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////  

void Trade()
  {

   if(Ordini()==0)
     {
      int result=0;
      if((iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>0) && (iRSI(NULL,0,14,PRICE_CLOSE,0)>Rsivaluebuy) && (iRSI(NULL,0,14,PRICE_CLOSE,0)<68) && (iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0)>iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,0))) // Here is your open buy rule
        {
         result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,NULL,Bid+TP*p,"buy",MagicNumber,0,Blue);
         // metti NULL al posto del take o dello stop se non li vuoi
        }
      if((iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)<0) && (iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0)<iMA(NULL,0,18,0,MODE_EMA,PRICE_CLOSE,0)) && (iRSI(NULL,0,14,PRICE_CLOSE,0)>32) && (iRSI(NULL,0,14,PRICE_CLOSE,0)<Rsivaluesell)) // Here is your open Sell rule
        {
         result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,NULL,Ask-TP*p,"sell",MagicNumber,0,Red);


        }
     }
  }
///////////////////////////////////////////////////////////////////////////////

void trail()

  {          for(int i=0;i<OrdersTotal(); i++)
  {

   bool result1=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

   if(OrderSymbol()==Symbol())
     {
      if(OrderType()==OP_BUY)
        {
         if(Bid-OrderOpenPrice()>TrailingStop*p)
           {
            if(OrderStopLoss()<Bid-TrailingStop*p)
              {
               bool result=false;
               result=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*p,OrderTakeProfit(),Red);
              }
           }
        }
      else if(OrderType()==OP_SELL)
        {
         if(OrderOpenPrice()-Ask>TrailingStop*p)
           {
            if(OrderStopLoss()>Ask+TrailingStop*p)
              {
               bool result=false;
               result=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*p,OrderTakeProfit(),Red);
              }
           }
        }
     }
  }
}
//////////////////////////////////////////

double lotin()
  {
   for(int i=0; i<OrdersTotal(); i++)
   {
    bool result1=false;
    result1=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol())
    {
    if(OrderProfit()<0) Lots=OrderLots()*2;
    else if(OrderProfit()>0) Lots=LottiAzz;
    }
    }
    return(Lots);

  }
///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////


void Azzerastop()

{          for(int i=0;i<OrdersTotal(); i++)
{

           bool result1=false;
           result1=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

           if(OrderSymbol()==Symbol())
           {
           if(OrderType()==OP_BUY)
           {
           if(Bid-OrderOpenPrice()>PuntiAZ*p)
           {

           bool result=false;
           result=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Pips_Stop*p,OrderTakeProfit(),Red);
           }
           }
           }
            if(OrderType()==OP_SELL)
{
           if(OrderOpenPrice()-Ask>PuntiAZ*p)
           {

           bool result=false;
           result=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Pips_Stop*p,OrderTakeProfit(),Red);
            }
          }
         }
       }
//+------------------------------------------------------------------+


Hi guys, i have different problem with this EA, he return erro ordermodify 130 i try to modify Ask Bid i try to inverted but when i launch the ea don't start the function Azzerrastop(); if something  can help me please

thanks for all and sorry for my english

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. 2008 ATC Hi, I participated in ATC 2008...
 

Please use the </> button to insert your code.


 
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  3.  result1=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    Check your return codes for errors, report them Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

  4.  if(OrderType()==OP_BUY){
        if(Bid-OrderOpenPrice()>PuntiAZ*p){
           bool result=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Pips_Stop*p,OrderTakeProfit(),Red);
    Where do you check that the new SL is still below the market in your OrderModify? You can't move stops (or pending prices) closer to the market than the minimum (MODE_STOPLEVEL * _Point.)
              Requirements and Limitations in Making Trades - Appendixes - MQL4&Tutorial
  5. Use the debugger or print out your variables, including Bid and find out why.