trade limitation

 

hi all, i need a help in coding

i want to disallowed trading for a few bar, lets say 10 bar after a trade is closed, how do i do that?

 
shenlongming:

hi all, i need a help in coding

i want to disallowed trading for a few bar, lets say 10 bar after a trade is closed, how do i do that?

Check the closed time of the last trade,  if it's less than 10 * Period don't place a new trade.
 
RaptorUK:
Check the closed time of the last trade,  if it's less than 10 * Period don't place a new trade.


i tried to do that already but then i cant get the closetime, something wrong is with the orderselect, will you show me how?

i tried with orderselect history mode then, close time =0 at all time , how to select the most recent closed order?

 
The close time is a datetime type variable,  so the most recent close time will have the biggest value for OrderCloseTime()

Show your code.
 
RaptorUK:
Check the closed time of the last trade,  if it's less than 10 * Period don't place a new trade.


in weekend or marketholiday we have a timegap makes  this is not working correctly

Check if Time[10] > time last closed trade of the EA and you are allowed to place a new trade 

 
deVries:


in weekend or marketholiday we have a timegap makes  this is not working correctly

Check if Time[10] > time last closed trade of the EA and you are allowed to place a new trade 

Good point :-)
 
for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)
   {
   if(!(OrderSelect(PositionIndex,SELECT_BY_POS,MODE_HISTORY)))
      {
      Print ("orderclosetime1",orderclosetime());
      if(OrderCloseTime() < bar_intervals*Period())
         {
         Print("orderclosetime",OrderCloseTime());
         buysignal=0;
         sellsignal=0;
         }
      }
   }
both the orderclose are 0 in values, is there something wrong in the trade selection?
 
deVries:


in weekend or marketholiday we have a timegap makes  this is not working correctly

Check if Time[10] > time last closed trade of the EA and you are allowed to place a new trade 

Use iBarShift() https://docs.mql4.com/series/iBarShift
 
shenlongming:
both the orderclose are 0 in values, is there something wrong in the trade selection?
If the OrderClose() fails you then go and try to print OrderCloseTime() ? how does that make any sense ?  please explain your reasoning ?

I don't mind you using code I have posted on the Forum,  but the least you can do is understand what you are copy and pasting . . . .


Edit:  Sorry . .  I meant if the  OrderSelect() fails . . .
 
for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)
   {
   if(!(OrderSelect(PositionIndex,SELECT_BY_POS,MODE_HISTORY)))
      {
      Print ("orderclosetime1",orderclosetime());
      if(OrderCloseTime() < bar_intervals*Period())
         {
         Print("orderclosetime",OrderCloseTime());
         buysignal=0;
         sellsignal=0;
         }
      } 

   orderclosetime is what i want in value, the orderclosetime1 is just to show myself that the value is available or not with orderselect

so it make sense but just in the other way round, ok? the orderclosetime1 have to be delete after finish coding,now back to the topic

from the code, it seems like the orderselect didnt success in selecting any order, so orderclosetime is always 0. what's wrong with the orderselect? 

how do i choose the last close order by magic or by position index? 

 
shenlongming:

   orderclosetime is what i want in value, the orderclosetime1 is just to show myself that the value is available or not with orderselect

so it make sense but just in the other way round, ok? the orderclosetime1 have to be delete after finish coding,now back to the topic

from the code, it seems like the orderselect didnt success in selecting any order, so orderclosetime is always 0. what's wrong with the orderselect? 

how do i choose the last close order by magic or by position index? 

Sorry . .  I meant if the  OrderSelect() fails . . .


OK,  answer a simple question  please . . . .  what does the   !  do before the OrderSelect() ?

Reason: