Error OrderSend130

 

I occasionally

//+------------------------------------------------------------------+
//|                                    Manage open trades by ATR.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <WinUser32.mqh>
#include <stderror.mqh>
#include <stdlib.mqh>

void logError(string functionName, string msg, int errorCode = -1)
  {
    Print("ERROR: in " + functionName + "()");
    Print("ERROR: " + msg );
    
    int err = GetLastError();
    if(errorCode != -1) 
        err = errorCode;
        
    if(err != ERR_NO_ERROR) 
      {
        Print("ERROR: code=" + err + " - " + ErrorDescription( err ));
      }    
  }

int start()
{
//+------------------------------------------------------------------+
//  You open a buy on Actual Ask, you close it on Actual Bid.
//  You open a sell on Actual Bid, you close it on Actual Ask.
//+------------------------------------------------------------------+

   int    nDigits;
   int    nMultiply;
   if(Symbol()=="GBPJPY" || Symbol()=="EURJPY" || Symbol()=="USDJPY" || Symbol()=="GOLD")  {nDigits = 3;nMultiply=100;}
   else {nDigits = 5;nMultiply=10000;}
   
   double currATR = iATR(NULL,PERIOD_D1,14,0) * nMultiply;
   double TradeTargetPrice = 16;
   double TradeStopLoss = 16;
   double BufferShort = 0.0006;
   double BufferLong = 0.0006; //takes into account the spread should be more than 6
   double StartHour = 22;
   double EndHour = 7;
   double diff = (EndHour-0)+(24-StartHour);

//////////////////////////////////////////////////////////
//IT IS NOW 2100GMT, delete any existing pending orders
//////////////////////////////////////////////////////////
bool is_timetodelete=false;
if(Hour()==22 && Minute()==0 && Seconds()==0) {is_timetodelete = true; }

if (is_timetodelete == true)
{      
      int total = OrdersTotal();
      for(int i=total-1;i>=0;i--) //if no orders then it won't run through this again
      {
         OrderSelect(i, SELECT_BY_POS);
         int type   = OrderType();

          bool result = false;
    
         switch(type)
         {
            //Close pending orders
            case OP_BUYLIMIT  :
            case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );
            case OP_SELLLIMIT :
            case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
         }
    
         if(result == false)
         {
            Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
            Sleep(3000);
         }  
      }
}

//////////////////////////////////////////////////////////
//IT IS NOW 0700GMT, set up the pending orders
//////////////////////////////////////////////////////////
bool is_timetocreatependingorders = false;
int ticket; 

if(Hour()==7 && Minute()==0 && Seconds()==0) 
{
   is_timetocreatependingorders = true;
   double OvernightHigh = High[iHighest(NULL,PERIOD_H1,MODE_HIGH,diff,0)];
   double OvernightLow = Low[iLowest(NULL,PERIOD_H1,MODE_HIGH,diff,0)];  
   Print("High="+OvernightHigh);
   Print("Low="+OvernightLow);

   if (OrdersTotal() == 0 && is_timetocreatependingorders == true)
      {
         //LONG
         RefreshRates();
         ticket=OrderSend(Symbol(),OP_BUYSTOP,1,OvernightHigh+BufferLong,NULL,(OvernightHigh+BufferLong)-(TradeStopLoss*Point),(OvernightHigh+BufferLong)+(TradeTargetPrice*Point),"LONG",0,0,Green);
      
         if(!ticket)
            {
               int errorCode = GetLastError();
               if(errorCode != ERR_NO_RESULT ) 
                  logError("OrderSend", "Error", errorCode);
            }
   
         //SHORT
         RefreshRates();
         ticket=OrderSend(Symbol(),OP_SELLSTOP,1,OvernightLow-BufferShort,NULL,(OvernightLow-BufferShort)+(TradeStopLoss*Point),(OvernightLow-BufferShort)-(TradeTargetPrice*Point),"SHORT",0,0,Red);
   
         if(!ticket)
            {
               errorCode = GetLastError();
               if(errorCode != ERR_NO_RESULT ) 
                  logError("OrderSend", "Error", errorCode);
            }
      }
   }

}      

get an error 130 in this code in the Strategy tester journel.

Any ideas why?

 

Error 130 is related to invalid stops, which means your stop loss levels are not set correctly. If your broker uses 5 digits quotes, this could be the problem. Who is your broker?

Reason: