Help on closing negative trade after 15mn

 

Hello Experts !

I’m new in MQL4 and try to build up my one little EA.

Please, any one can help me on closing an open position 15mn after opening if the value turns negative (like 50% of the case)

I already start a simple pilot but I need to close the negative trade after a short period.

Thanks for the help.



rayve.

 
rayve:

Hello Experts !

I’m new in MQL4 and try to build up my one little EA.

Please, any one can help me on closing an open position 15mn after opening if the value turns negative (like 50% of the case)

I already start a simple pilot but I need to close the negative trade after a short period.

Thanks for the help.



rayve.


Why bother about time???

U r interested in not losing money so you should monitor the variation of the price... no matter in whice timeframe it occurs.

How to close your order if it loses more than what U r willing to risk? ...U know the answer already: stoploss :)


Zyp

 

Try this:

...

timeout=15; // minutes
for (cnt=0; cnt<OrdersTotal(); cnt++) {
   OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
   if ((TimeCurrent()-OrderOpenTime())>=(60*timeout)) {
      if (OrderType()==OP_BUY) {
         OrderClose(OrderTicket(),OrderLots(),Bid,0,Red);
      }
      if (OrderType()==OP_SELL) {
         OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
      }
   }
}
good lucky!

...

Figurelli

 
figurelli:

Try this:

...

good lucky!

...

Figurelli

Thanks, it work's after few adaptation

rayve.

 
figurelli:

Try this:

...

good lucky!

...

Figurelli

Hi Figurelli,

u r realy very cooperative. please solve my following problem. i simply just want to get basic calculations of each 50 point move either up or down..details are as follows .plz i need programming of it. i shall pray for u and please help it out.



uppose GBP/USD is trading at 1.9700 then we have to watch next 50 points move either towards upside or down side. after each 50 points move we will enter buy position with stoploss of 50 points and limit of 50 points and further with the same proceedure we will carry on..

for example

1.9700 starting rate and we buy every time one lot then market toches 50 points down then we will cut the position bcoz 50 point stop loss is touched and at this stage we will enter an other one buy lot at 1.9650 then market moves 50 more down and we will do the same and one buy lot at 1.9600.then market moves up 50 points we will buy next at 9650 .....mean after each 50 points move up or down we have to enter buy position with 50 points stop and limit...


1.9700 buy -50 loss
1.9650 buy -50 loss
1.9600 buy 50 profit
1.9650 buy -50 loss
1.9600 buy -50 loss

1.9550 buy -50 loss

1.9500buy 50 profit

1.9550buy -50 loss

1.9500buy -50 loss

1.9450buy
its seems to be very simple command but you know better bcoz u r professional in programming..i have to check this method on GBP/USD and other most active currencies pair. the pairs which have great average move .thanks .
 
figurelli:

Try this:

...

good lucky!

...

Figurelli

Dear Figurelli

please EA send at my email truetraders at gmail dot com thanks

 
zubairlink wrote >>

Hi Figurelli,

u r realy very cooperative. please solve my following problem. i simply just want to get basic calculations of each 50 point move either up or down..details are as follows .plz i need programming of it. i shall pray for u and please help it out.

uppose GBP/USD is trading at 1.9700 then we have to watch next 50 points move either towards upside or down side. after each 50 points move we will enter buy position with stoploss of 50 points and limit of 50 points and further with the same proceedure we will carry on..

for example

1.9700 starting rate and we buy every time one lot then market toches 50 points down then we will cut the position bcoz 50 point stop loss is touched and at this stage we will enter an other one buy lot at 1.9650 then market moves 50 more down and we will do the same and one buy lot at 1.9600.then market moves up 50 points we will buy next at 9650 .....mean after each 50 points move up or down we have to enter buy position with 50 points stop and limit...

1.9700 buy -50 loss
1.9650 buy -50 loss
1.9600 buy 50 profit
1.9650 buy -50 loss
1.9600 buy -50 loss

1.9550 buy -50 loss

1.9500buy 50 profit

1.9550buy -50 loss

1.9500buy -50 loss

1.9450buy
its seems to be very simple command but you know better bcoz u r professional in programming..i have to check this method on GBP/USD and other most active currencies pair. the pairs which have great average move .thanks .

Thanks zubairlink, what you have to do is store the last value to compare in the future, one way to do this is create a global variable, for example:

// put here your stage parameter

extern int stage=50;

// put here your global variable

static double lastValue=0; 

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
//----
   return(0);
  }

...

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

   ...

   // put here your compare code

   if (lastValue==0) lastValue=Ask; // this is your start value

   if (Ask>=(lastValue+stage*Point)) {      
      lastValue=Ask; // store the new last value
      // put here your high target action
      ...
   }

   if (Bid<=(lastValue-stage*Point)) {
      lastValue=Bid; // store the new last value
      // put here your low target action
      ...
   }

   ...

}

Hope this help you.

good lucky!

Figurelli

Reason: