1 of 2 trades isn't entered

 

Sometimes this script enters 2 trades, at other times it only enters 1 of the trades and reports an error of Error = no error

Any ideas what this could be or a way to reorder if something goes wrong in the error checking code?


//+------------------------------------------------------------------+
//|                                                        trade.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#include <stdlib.mqh>
#include <WinUser32.mqh>
//+------------------------------------------------------------------+
//| script "trading for all money"                                   |
//+------------------------------------------------------------------+
int start()
  {
  
  double Balance = AccountBalance();
  double Risk = 0.025;
  double MaxLoss = Risk*Balance;
  double SenkouSpanA = iIchimoku(NULL, 0, 9, 26, 52, MODE_SENKOUSPANA, 0);
  double SenkouSpanB = iIchimoku(NULL, 0, 9, 26, 52, MODE_SENKOUSPANB, 0);
  //this is a BUY so we want to find the furthest away figure
  double Diff;
  double SenkouStop;
  double Lots;
  if (SenkouSpanA > SenkouSpanB) {Diff = SenkouSpanA-Bid; SenkouStop = SenkouSpanA;}
  else {Diff = SenkouSpanB-Bid;SenkouStop = SenkouSpanB;} 
  if (Point == 0.00001) {
      SenkouStop = SenkouStop+0.0010;//buffer
      SenkouStop = NormalizeDouble(SenkouStop,5);
      Lots = NormalizeDouble((MaxLoss/(Diff*10000)*0.1),2);
  }
  if (Point == 0.001) {
      SenkouStop = SenkouStop+0.10;
      SenkouStop = NormalizeDouble(SenkouStop,3);
      Lots = NormalizeDouble((MaxLoss/(Diff*100)*0.1),2);
  }
  if (Lots < 0.1) {Lots=0.1;}
  
   if(MessageBox("SELL "+Lots+ " on "+Symbol()+" with stop at "+SenkouStop,
                 "Script",MB_YESNO|MB_ICONQUESTION)!=IDYES) return(1);
   
   RefreshRates();
   int ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(Lots/2,2),Bid,30,SenkouStop,Bid-(SenkouStop-Bid),DoubleToStr(Period(),0),255,0,CLR_NONE);
   RefreshRates();
   int ticket_two=OrderSend(Symbol(),OP_SELL,NormalizeDouble(Lots/2,2),Bid,30,SenkouStop,0,DoubleToStr(Period(),0),255,0,CLR_NONE);
   
   if(ticket<1 || ticket_two<1)
     {
      int error=GetLastError();
      Print("Error = ",ErrorDescription(error));
      return;
     }
//----
   OrderPrint();
   return(0);
  }
//+------------------------------------------------------------------+
 
SanMiguel:

Sometimes this script enters 2 trades, at other times it only enters 1 of the trades and reports an error of Error = no error

Any ideas what this could be or a way to reorder if something goes wrong in the error checking code?

Presumably, the second order always succeeds, and it's the first order which is periodically failing. The success of the second order will reset the last-error to zero. To find out what's going wrong, simply put some logging directly after the attempt to place the first order.