How to stop trading for rest of the day if xxx profit reach

 

Hi,


can someone help how to to teach an ea when xxx amount  of open orders reached than do not open trades for the rest of the day and start on next day.


I am counting my openorders right now like this


double Open_Orders_Profit()
{
   double openordersprofit = 0;
   RefreshRates();
   int Total=OrdersTotal();
   if(Total>0)
   {
      for(int i=Total-1; i>=0; i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==TRUE)
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber() == magicNumber)
            {
               openordersprofit +=OrderProfit()+OrderSwap()+OrderCommission();
            }
         }
      }
   }
   return(openordersprofit);
}
    if(Open_Orders_Profit()>=TakeProfitInput)
   {     
      CloseAllPositions();  
      bool tradeallowed = false;	
   }

Now if CloseAllPositions() is called EA have to skip opening new trades..so i have set the bool tradeallowed to true.

But know how can i code ea that the bool will automatically set to true on next trading session by server time?

 
  1. Your tradeallowed, is lost as soon as you exit the closing brace.
  2. Instead just make a global (so you remember it between calls,) datetime, put the date there on close, and test at the start of the next tick.
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 programming forum
 
William Roeder:
  1. Your tradeallowed, is lost as soon as you exit the closing brace.
  2. Instead just make a global (so you remember it between calls,) datetime, put the date there on close, and test at the start of the next tick.
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 programming forum

hmm damn i dont understand how to solv it i read your link.

 

if you want to reset the value of the bool on the new D! candle.

datetime time;
if(time!=iTime(Symbol(),PERIOD_D1,0))
{
 tradeallowed =1; 
 time=iTime(Symbol(),PERIOD_D1,0);
}

But you have to declare the bool tradeallowed outside of the function.

bool tradeallowed = false;
    if(Open_Orders_Profit()>=TakeProfitInput)
   {     
      CloseAllPositions();  
      tradeallowed = false;     
   }

Just as with the time variable.
 

 

i have just checked but seems not working. I have make a function reset. and put it in OnTick.

void reset()
   {
      if(time!=iTime(Symbol(),PERIOD_D1,0))
         {
            tradeallowed = true; 
            time=iTime(Symbol(),PERIOD_D1,0);
         }
   }

i have put global variable

datetime time;
bool     tradeallowed = true;

i have changed it

    if(Open_Orders_Profit()>=TakeProfitInput)
   {     
      CloseAllPositions();  
      tradeallowed = false;     
   }

before my ordersend i check if tradeallowed is true

   if (!tradeallowed) return;
 
ähhh i cannot get that working
 
Raphael Schwietering: ähhh i cannot get that working
"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.

We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

 
Raphael Schwietering:
ähhh i cannot get that working

Place an order in freelance

 
Mafuta Landou:

Place an order in freelance

🤣

Raphael Schwietering:
ähhh i cannot get that working

More seriously, when you post your code, try to post complete functions or even complete files (best, because that'll allow the curious people here to test run and tell you straight away what is wrong). Otherwise your question will only be met with guesses... 

Reason: