MT4 || Getting data of a order and closing it after x-amount of time

 

Hi,

I am learning how to code, so I am struggling with some basic stuff. Normally I try to make a program that has only one trade open at the same time, with a already determined stoploss and takeprofit. I do not have to track these trades because all the variables are already set. This is probably not the right way of doing this, but this makes it much easier for me to learn of to setup some code. 

Now I want to advance my programming skills and make my advisors a lot better and safer. Because I know my coding isn't good. 

I have an trading idea that doesn't have a set stoploss. The only way to get a stop out is after 30 trading days. Now I also have multiple trades running at the same time, thats why I need the trades to be marked with some specific data to close them after 30 trading days. I currently send my trades like this, without any check or anything like that:

OrderSend(Symbol(),OP_BUY,tradingLotSize,Ask,maxSlippage,NULL,takeProfit,NULL,NULL,NULL,clrGreen);


Now I need to stop the trades after 30 trading days if they have not reached the takeprofit. I know there is a OrderClose function that requires the ticket of a trade to close it. Now if I put Ticket = OrderSend(etc etc) before a trade I will get the desired trade which I can insert into loads of other functions. This is the point where I get lost. When I have (for example) 10 different trades running, and I keep using the same "Ticket", it will be overwritten. And how do I keep "live" track of all the trades on the same time, and closing them after that amount of time?

I've watched lots of video's, but I won't get my head around it. Can you please help me to solve my struggles, maybe with a good video about the topic, some written code I can have a look at etc. 


I want to thank you a lot for the help!

Daan

 
DaanKouwen_SF: I have an trading idea that doesn't have a set stoploss. The only way to get a stop out is after 30 trading days.
  1. Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk. Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.

  2. Select the order, get the OrderOpenTime, get the corresponding D1 bar index, check for 30. What's the problem?

Reason: