Useful features from KimIV - page 120

 

Good afternoon.

I modified GetProfitOpenPosInCurrency() function to return the worst losing position. Can you please tell which functions would be suitable to return the opening time of this position (OrderOpenTime())?

double GetMaxLoseOpenPosInCurrency(string sy="", int op=-1, int mn=-1) {
  double p=0;
  int    i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) 
            if(p > OrderProfit() + OrderSwap() + OrderCommission()){
            p=OrderProfit()+OrderCommission()+OrderSwap();
          }
        }
      }
    }
  }
  return(p);
}
 
abeiks:

Good afternoon.

I modified GetProfitOpenPosInCurrency() function to return the worst losing position. Can you please tell which functions would be suitable to return the opening time of this position (OrderOpenTime())?


Return the ticket number and you can do with the standard functions
 
Vinin:

Return the ticket number and you can dispense with the standard functions

Thank you.
 

KimIV , hello.Looking for--can't find the script--delete all the pending orders on the symbol--and trawlon the symbol,maybe there is--post........ dont consider it impertinent.Thanks in advance .

 

Good afternoon.

I am using isTradeTimeInt() function from KimIV. I will use many time intervals and for each interval I will assign different variables. I have made this code for it (2 intervals so far). The question is, is this the most correct solution or should I approach the task differently?

extern int OH1=9;extern int OM1=0;extern int CH1=12;extern int CM1=0;
extern int OH2=13;extern int OM2=0;extern int CH2=15;extern int CM2=0;

int HourOpenTime()
{
int trade = 0;
if(isTradeTimeInt(OH1,OM1,CH1,CM1))trade = 1;
if(isTradeTimeInt(OH2,OM2,CH2,CM2))trade = 2;
return (trade);
}
 
bestseich:

Dear Igor Kim, help me write a function like OrderCloseBy(), but it should work on different pairs and OrderProfit(), and it does not matter if orders are differently directed or not, like one OrderProfit() > another, another pair, by how many points and both, exactly, only these two, close simultaneously. My variant is like this:

for (int i=OrdersTotal()-1;i>=0;i--)

{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()!=Symbol()||OrderSymbol()==Symbol())
{
if(OrderProfit()>=pr*Point)//pr is in parameters, points profit
int ot=OrderTicket();double op=OrderProfit();
if(OrderProfit()<=pru*(-1)*Point)//pru-it is in the parameters, points of loss
int otu=OrderTicket();double opu=OrderProfit();
if(op>opu*v*(-1)&&(OrderType()==OP_BUY||OrderType()==OP_SELL))
//v is a profit/loss ratio, i.e. 1.5
OrderClose(otu,OrderLots(),Bid,sleep,Blue);
OrderClose(ot,OrderLots(),Bid,sleep,Blue);
OrderClose(otu,OrderLots(),Ask,sleep,Blue);
OrderClose(ot,OrderLots(),Ask,sleep,Blue);

}}}

Will it work? Correct or suggest your own solution, if you don't mind.

 

Dear Igor!

Could you please advise whether you have a function to calculate the lot volume depending on the account balance after closing the last order and before opening the next one?

I thank you in advance.

 
vasabu2012:

Dear Igor!

Could you please advise whether you have a function to calculate the lot volume depending on the account balance after closing the last order and before opening the next one?

I thank you in advance.

Here is Igor's function.

Files:
b-lots.mqh  3 kb
 

In the update the PriceOpenLastPos function stopped working in the conditions, almost broke my brain, it gives out values in the comments but does not work in the conditions, a small edit solved the problem.

double PriceOpenLastPos(string sy="", int op=-1, int mn=-1) {
datetime t;
double r=0, r2=0;
int i, k=OrdersTotal();

if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==sy || sy=="") {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderOpenTime()) {
t=OrderOpenTime();
r=OrderOpenPrice();
}
}
}
}
}
}
}

r2 = DoubleToStr(r, 4);

return(r2);
}


 
Please help recompile the EA e-CloseByEquity.rar with programming changes in MetaEditor
Reason: