How to insert a time interval for opening orders in EA? - page 2

 
Ok, thanks. Then maybe could you help me with codesnippet of min. 20 seconds and accordingly then the first tick?
 
Dutchpips:
Mm ok, what would be the max period without ticks in your opinion? My pairs are eurusd usdchf eurcad on m15

we can't say....    Als de internetverbinding weggevallen is door werkzaamheden heb je ook geen ticks van je forexbroker

so it doesn't matter what pairs you are trading

I think if you code like

iError = GetLastError();
                   if (iError != 0) // retry if error is "busy", otherwise give up
                    {
                     if(iError==ERR_SERVER_BUSY || iError==ERR_TRADE_CONTEXT_BUSY || iError==ERR_BROKER_BUSY || iError==ERR_NO_CONNECTION 
                       || iError == ERR_COMMON_ERROR || iError==ERR_TRADE_TIMEOUT || iError==ERR_INVALID_PRICE || iError==ERR_OFF_QUOTES 
                       || iError==ERR_PRICE_CHANGED || iError==ERR_REQUOTE || iError == ERR_TOO_MANY_REQUESTS) Sleep(RetryTime);

 you can run more ea's. make only 20 seconds delay for chart ea

otherwise make  something like

value int Trades;

if (OrdersTotal() != Trades)
   {
   if(Trades < OrdersTotal())lastOpen = now;
   Trades = OrdersTotal();
   }

 in this part

if(Trades < OrdersTotal())lastOpen = now;

you can make extra condition checking the trades for magicnumber and symbol

 
Dutchpips: what would be the max period without ticks in your opinion? My pairs are eurusd usdchf eurcad on m15
Fri 4 pm to Sun 6 pm = 38 Hours (+24 more if Friday or Monday is a Forex Holiday)
 

Thanks again all. 

@WHRoeder; yes you are right. But personally I don't take positions over the weekend (will turn it off firday afternoon).

@De vries; Thanks for your suggestion!

I put '20' after sleep and then paste the code in my ea? What is the position to paste?

(sorry maar snap niet exact waar ik de code moet inserten en wat ik er nog aan toe moet voegen..) 

 
Dutchpips:

Thanks again all. 

@WHRoeder; yes you are right. But personally I don't take positions over the weekend (will turn it off firday afternoon).

@De vries; Thanks for your suggestion!

I put '20' after sleep and then paste the code in my ea? What is the position to paste?

(sorry maar snap niet exact waar ik de code moet inserten en wat ik er nog aan toe moet voegen..) 

and if you fail then show your attempt so we can see where you get wrong my crystal ball doesn't show the problem you have

there might be more wrong with your code we don't know

 
Dutchpips: I put '20' after sleep and then paste the code in my ea?
Did you read the manual on Sleep? What does '20' mean?
 

Dear WHRoeder,

 

Thanks, you helped me a bit further again. So that makes:

 

iError = GetLastError();
                   if (iError != 0) // retry if error is "busy", otherwise give up
                    {
                     if(iError==ERR_SERVER_BUSY || iError==ERR_TRADE_CONTEXT_BUSY || iError==ERR_BROKER_BUSY || iError==ERR_NO_CONNECTION 
                       || iError == ERR_COMMON_ERROR || iError==ERR_TRADE_TIMEOUT || iError==ERR_INVALID_PRICE || iError==ERR_OFF_QUOTES  

                       || iError==ERR_PRICE_CHANGED || iError==ERR_REQUOTE || iError == ERR_TOO_MANY_REQUESTS) Sleep(20000); 

 

It worked out finally. Thanks to all!!

 

What I did:

 

chart 1: no sleep

chart 2: sleep 20000ms (20sec)

chart 3: sleep 40000ms (again 20 sec after 2)

 

and it works fine.

 

If anybody has a nice link with some basic functions I would be gratfull.

Want to optimize a bit with e.g. maxtrades total, mastrades per chart, start hour.

Thing is the rows to make it a setting are easy but I am always doubting where to insert the commands in the code exactly.

 

Basically I am helped.. 

 
Dutchpips: 

If anybody has a nice link with some basic functions I would be gratfull.


 


Hello. I need your help in making my indicator act as a trail version for one day in case if anyone asked me to give him to test it .. so how can I do that

//+------------------------------------------------------------------+
//|                                             Indicator: HHHH4.mq4 |
//|                                       Created with EABuilder.com |
//|                                             http://eabuilder.com |
//+------------------------------------------------------------------+
#property copyright "Created with EABuilder.com"
#property link      "http://eabuilder.com"
#property version   "1.00"
#property description ""

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

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 1

#property indicator_type1 DRAW_ARROW
#property indicator_width1 2
#property indicator_color1 0xFFFFFF
#property indicator_label1 "Buy"

//--- indicator buffers
double Buffer1[];

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | HHHH4 @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(1);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 233);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(Close[1+i] > Open[1+i] //Candlestick Close > Candlestick Open
      && Close[i] > Open[i] //Candlestick Close > Candlestick Open
      )
        {
         Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low
        }
      else
        {
         Buffer1[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+