EA which will take only one trade at a time ?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
13006
WHRoeder 2016.03.29 16:38 #
 
reformat the csv string (if necessary) and convert it to a datetime with StringToTime - Conversion Functions - MQL4 Reference StrToTime - Conversion Functions - MQL4 Reference






avatar
160
cashcube 2016.03.30 07:45 #
 
WHRoeder:
reformat the csv string (if necessary) and convert it to a datetime with StringToTime - Conversion Functions - MQL4 Reference StrToTime - Conversion Functions - MQL4 Reference






Hi,

I did that already,

   Dat_DtTm =StrToTime(Str_DtTm);   // Transformation of data type

 It was an indicator previously, So date time is working perfectly as an indicator. But not the EA.

avatar
13006
WHRoeder 2016.03.30 14:26 #
 
cashcube: So date time is working perfectly as an indicator. But not the EA.

"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.

Post your code and the values of your variables.

avatar
160
cashcube 2016.03.31 08:03 #
 
But I already posted my full code at the 1st page.

cashcube 2016.03.24 05:36 #

Ok Re posting again,

extern double S = 1;
extern double StopLoss = 5;
extern double TakeProfit = 10;
extern double LotSize = 0.01;
extern int Slippage = 5;
extern int MagicNumber = 11;
  
  
  double CalcSlippage;
  int SlippagePips;
  double CalcPoint1;
  double CalcPoint;
  double UsePoint;
  int    UseSlippage;
  int BuyTicket;
  int SellTicket;

// Init function---------------------------------------------------------
int init()
{

int CalcDigits = (int)MarketInfo(Symbol(),MODE_DIGITS);

if(CalcDigits == 2 || CalcDigits == 4) CalcSlippage = SlippagePips;
else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;      


if(CalcDigits == 2 || CalcDigits == 3) CalcPoint1 = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint1 = 0.0001;
      
UsePoint = CalcPoint;
UseSlippage = (int) CalcSlippage; 
return (0);
}
//-------------------------------------------------------------------
int start()                            // Spec. function start()
  {
//--------------------------------------------------------------- 2 --
   int Handle;                          // File descriptor
   string File_Name="H.csv",          // Name of the file
          Obj_Name,                     // Name of the object               
          D1,                           // Data     
          Str_DtTm;                    // Date and time of the event (line)
   datetime Dat_DtTm;                  // Date and time of the event (date)
   double  DD1;  // Data (converted)
     
//--------------------------------------------------------------- 3 --
   Handle=FileOpen(File_Name,FILE_CSV|FILE_READ,",");// File opening
   if(Handle<0)                        // File opening fails
     {
      if(GetLastError()==4103)         // If the file does not exist,..
         Alert("No file named ",File_Name);//.. inform trader
      else                             // If any other error occurs..
         Alert("Error while opening file ",File_Name);//..this message
      PlaySound("Bzrrr.wav");          // Sound accompaniment
      return(0);                          // Exit start()      
     }
//--------------------------------------------------------------- 4 --
   while(FileIsEnding(Handle)==false)  // While the file pointer..
     {                                 // ..is not at the end of the file
      //--------------------------------------------------------- 5 --
      Str_DtTm =FileReadString(Handle);// Date and time of the event (date)
      D1     =FileReadString(Handle);  // Data
   
      if(FileIsEnding(Handle)==true)   // File pointer is at the end
         break;                        // Exit reading and drawing
      //--------------------------------------------------------- 6 --
      Dat_DtTm =StrToTime(Str_DtTm);   // Transformation of data type
           
      datetime ND = Dat_DtTm + 86400;
      DD1 = floor(StrToDouble(D1));  
      
      //------------------------------------------------------ Pricing    
     
      double CalcDigits = MarketInfo(Symbol(),MODE_DIGITS);
      {
      if(CalcDigits == 2 || CalcDigits == 3) CalcPoint = 100;
      else if (CalcDigits == 4 || CalcDigits == 5) CalcPoint = 10000;
      }
      
      double j =  iOpen(Symbol(), PERIOD_D1, iBarShift(Symbol(),PERIOD_D1, Dat_DtTm));
      double SK = floor((360*S));
      double k = floor(round((j*CalcPoint))/SK); 
      double L1 = ((k * SK)+ floor((DD1 * S)))/CalcPoint;

  // Orders-----------------------------

     if(TimeCurrent() == Dat_DtTm)
    {
       bool can_buy=true;
       bool can_sell=true;
       
       double T1 = L1;
       
       
       for(int x=OrdersTotal()-1;x>=0;x--)
      {
         if(OrderSelect(x,SELECT_BY_POS) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
          {
          if(OrderType()==OP_BUY)
             can_buy=false;
          if(OrderType()==OP_SELL)
             can_sell=false;
          }
      }
      
  //----------------------------------------
     if(can_buy)
     {
     
     if(Close[1]> T1 ) 
       
       {
       
       double BuyStopLoss = Ask - (StopLoss * CalcPoint1);
       double BuyTakeProfit = Ask + (TakeProfit *  CalcPoint1);
       BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,Ask,UseSlippage,BuyStopLoss,BuyTakeProfit,"Buy Order",MagicNumber,0,Green); 
       
       }
     
     
     }
 //--------------------      
    if(can_sell)
     {
    
       if(Close[1]< T1 ) 
       
       {
       double SellStopLoss = Bid + (StopLoss * CalcPoint1);
       double SellTakeProfit = Bid - (TakeProfit *  CalcPoint1);
       SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,UseSlippage,SellStopLoss,SellTakeProfit,"Sell Order",MagicNumber,0,Red);     
       
       }   
    
     }
  ///------------------------          
        
      }
//-----------------end of orders
           
     }
    
    //--------------------------------------------------------------- 8 --
   FileClose( Handle );                // Close file
   PlaySound("bulk.wav");              // Sound accompaniment
   WindowRedraw();                     // Redraw object
   return(0);                             // Exit start()
  }

//------------------------------------------------------------

 Data in the CSV file stored liked this.

 

 

avatar
160
cashcube 2016.04.04 11:42 #
 

No reply yet.

How to delete a thread? 

avatar
13006
WHRoeder 2016.04.04 14:34 #
 
I said
WHRoeder:
reformat the csv string (if necessary) and convert it to a datetime with StringToTime - Conversion Functions - MQL4 Reference StrToTime - Conversion Functions - MQL4 Reference

You said
cashcube: I did that already,
Dat_DtTm =StrToTime(Str_DtTm);   // Transformation of data type
Now you post your data format
 MM.DD.YYYY
RTFM StrToTime - Conversion Functions - MQL4 Reference



Converts string in the format "yyyy.mm.dd hh:mi" to datetime type (the amount of seconds that have passed since 1 Jan., 1970).

Are they the same format? NO!

see How to Extract from a String (barnacle7) - MQL4 forum

avatar
Moderator
3419
GumRai 2016.04.04 14:37 #
 

I have also already pointed out that

if(TimeCurrent() == Dat_DtTm)

May well lead to expected execution of code not happening.

Back to topics list   | 1 2  

To add comments, please log in or register