How to only have one trade a day

 

Hi guys,


How can I have a system, so my EA only makes one trade a day? Even if my only trade that day is closed, I don't want it to open anything new before the next day.


Thanks in advance :)

 
You code it to do that. Remember the last open date, check against today's date.
          Find bar of the same time one day ago - MQL4 programming forum 2017.10.06

Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

 


if(OrdersTotal()<1)
{   
   if(Hour()<=19)
   {
      if(Hour()>=11)
      {
      Alert("Time to put in orders");
      OrderSend(NULL,OP_BUYSTOP,PositionS,EntryBuy,20,StopL,TakeProfitLong);
      OrderSend(NULL,OP_SELLSTOP,PositionS,EntrySell,20,StopL,TakeProfitShort);
      }
      
      else
      {
      Alert ("Too early to trade");
      }
   }
   else
   {
   Alert("Too late to trade");
   }
      
}   
else
{
   Alert("Enough orders already");
}

Sorry if my code is a bit messy. I am sending 2 limit orders in at my signals prices. Later I want to remove the other when one of these are triggered. This leaves me with one order. If this one takes profit og hit stop loss, my code is sending new orders, but I dont want more orders... Any feedback on my code is welcome, since I'm new and still  learning :)

 
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Do an OrderSelect loop if you find a open order, remove the pending one.
    Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles

  3. What do you mean you "don't want more orders?" Then your EA stops working. More likely you want to stop looking at a signal. Act on a change of signal.
              MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 2017.12.12

 
Martin Jensen:

Sorry if my code is a bit messy. I am sending 2 limit orders in at my signals prices. Later I want to remove the other when one of these are triggered. This leaves me with one order. If this one takes profit og hit stop loss, my code is sending new orders, but I dont want more orders... Any feedback on my code is welcome, since I'm new and still  learning :)

if(OrdersTotal()<1)

don't use such! This will select terminals total orders (all) ....Don't you want your expert adviser to keep track of it's own orders? Select and count your orders correct by symbol and magic!

 

Thanks for the feedback

Answer to your points:

1) My bad. I didn't know this was the wrong place.

2) I'm gonna look into that and see if I can use the loop function. I'm not sure if a magic number will be useful for this one, but I can add that too.

3) My strategi is actually only gonna run 1 position for most of the day or until the order has hit the TP or SL. When that happens It should no longer trade. I'm opening two limit orders, as I don't know yet If it's gonna be long or short. So when one of these are finally trigered, I wanna remove the limit order waiting and just stick to the market order already open.

What do you mean by "change of signal"?

I just got a new idea actually: I consider changing my code to something that will only add these limit orders once at a specific time, after that It will have to wait until tomorrow before seing the specific time. That means I only have to figure out how to remove the other order once one of my limit turns to market.

Thanks again for the feedback! I actually think I can get a bit further now :)

 
Kenneth Parling:

don't use such! This will select terminals total orders (all) ....Don't you want your expert adviser to keep track of it's own orders? Select and count your orders correct by symbol and magic!

Well, This is my first EA, so at the moment I'm just gonna make this one run correctly. If I start on my second one, I will surely go back and fix this as I see your point.

I will properbly add the symbol and magic after I am able to run it.

Thanks for the feedback

 
Martin Jensen:

Well, This is my first EA, so at the moment I'm just gonna make this one run correctly. If I start on my second one, I will surely go back and fix this as I see your point.

I will properbly add the symbol and magic after I am able to run it.

Thanks for the feedback

1st or 10th....always use magic number in OrderSend() , how else will your ea know it's own orders....Then you also need to make the ea to keep track of it's orders on the symbol(s) traded. This is the first things you should make work. What if your terminal crash or you by any reason needs to restart it or you perhaps just change ea settings? if you have an ea without these capabilities it will not pick up the order once restarted as it can't recognize it. What if you by any reason want to use another ea on same account? well you'll figure out why this is important!

 
In future please post in the correct section
I will move this topic to the MQL4 and Metatrader 4 section.
 
Martin Jensen: What do you mean by "change of signal"?
Do you see words with underlines? Those are links. They take you to more information. You would know what I meant, had you bothered to click on the provided link.