Thanks IX...Good Luck on Oil Ops... speculators here in the States are being blamed for the recent High energy prices and subsequent economic crisis...Government is watching....
On your Script/and Limit orders...I added them to my martingale EA and it creates orders fine (did get some error 4110)...But closing ALL open Buys or Sells at Profit did not happen....When one would close at a profit duplicate limit orders are created. I tried using the EA's existing close orders code, but it did not recognize the limit orders should be closed also. I also tried to modify the code from this thread, but no success.
http://www.tradingsystemforex.com/mq...equence-2.html
Could a simple Orderdelete line be added???
if (OrdersTotal is not X then OrderDelete)
I don't know the proper syntax to code this line...I've been trying to learn on MQL4.com but can not get it to work or work on only Buys or Sells... any ideas??
#define m 20050611
//----
extern int sl=550;
extern int tp = 47;
extern int sh = 63;
//----
datetime lastt;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int kol_buy()
{
int kol_ob = 0;
//----
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;
//----
if(OrderType() == OP_BUY)
kol_ob++;
}
return(kol_ob);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int kol_sell()
{
int kol_os = 0;
//----
for(int i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;
//----
if(OrderType() == OP_SELL)
kol_os++;
}
return(kol_os);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int slip, i, ii, tic, total, kk, gle;
double lotsi = 0.0;
bool sob = false, sos = false, scb = false, scs = false;
int kb, kb_max = 0;
kb = kol_buy() + 1;
double M_ob[11][8];
ArrayResize(M_ob,kb);
int ks = 0, ks_max = 0;
ks = kol_sell() + 1;
double M_os[11][8];
ArrayResize(M_os,ks);
ArrayInitialize(M_ob, 0.0);
int kbi = 0;
//----
for(i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;
//----
if(OrderSymbol() == Symbol() && OrderType() == OP_BUY)
{
kbi++;
M_ob[kbi][0] = OrderTicket();
M_ob[kbi][1] = OrderOpenPrice();
M_ob[kbi][2] = OrderLots();
M_ob[kbi][3] = OrderType();
M_ob[kbi][4] = OrderMagicNumber();
M_ob[kbi][5] = OrderStopLoss();
M_ob[kbi][6] = OrderTakeProfit();
M_ob[kbi][7] = OrderProfit();
}
}
M_ob[0][0] = kb;
double max_lot_b = 0.0;
//----
for(i = 1; i < kb; i++)
if(M_ob[i][2] > max_lot_b)
{
max_lot_b = M_ob[i][2];
kb_max = i;
}
double buy_lev_min = M_ob[kb_max][1];
ArrayInitialize(M_os,0.0);
int ksi = 0;
//----
for(i = 0; i < OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false )
break;
//----
if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
{
ksi++;
M_os[ksi][0] = OrderTicket();
M_os[ksi][1] = OrderOpenPrice();
M_os[ksi][2] = OrderLots();
M_os[ksi][3] = OrderType();
M_os[ksi][4] = OrderMagicNumber();
M_os[ksi][5] = OrderStopLoss();
M_os[ksi][6] = OrderTakeProfit();
M_os[ksi][7] = OrderProfit();
}
}
M_os[0][0] = ks;
double max_lot_s = 0.0;
//----
for(i = 1;i < ks; i++)
if(M_os[i][2] > max_lot_s)
{
max_lot_s = M_os[i][2];
ks_max = i;
}
double sell_lev_max = M_os[ks_max][1];
//----
if(Bars < 100 || IsTradeAllowed() == false)
return(0);
sob = (kol_buy() < 1 || buy_lev_min - sh*Point > Ask) &&
AccountFreeMargin() > AccountBalance()*0.5;
sos = (kol_sell() < 1 || sell_lev_max + sh*Point < Bid) &&
AccountFreeMargin() > AccountBalance()*0.5;
//----
if(M_ob[kb_max][2] > 0.0)
scb = M_ob[kb_max][7] / (M_ob[kb_max][2]*10) > tp;
//----
if(M_os[ks_max][2] > 0.0)
scs = M_os[ks_max][7] / (M_os[ks_max][2]*10) > tp;
kk = 0;
ii = 0;
//----
if(scb)
{
while(kol_buy() > 0 && kk < 3)
{
for(i = 1; i <= kb; i++)
{
ii = M_ob[i][0];
//----
if(!OrderClose(ii,M_ob[i][2],Bid,slip,White))
{
gle = GetLastError();
kk++;
Print("Îøèáêà ¹", gle, " ïðè close buy ", kk);
Sleep(6000);
RefreshRates();
}
}
kk++;
}
}
kk = 0;
ii = 0;
//----
if(scs)
{
while(kol_sell() > 0 && kk < 3)
{
for(i = 1; i <= ks; i++)
{
ii = M_os[i][0];
//----
if(!OrderClose(ii,M_os[i][2], Ask, slip, White))
{
gle = GetLastError();
kk++;
Print("Îøèáêà ¹", gle, " ïðè close sell ", kk);
Sleep(6000);
RefreshRates();
}
}
kk++;
}
}
kk = 0;
tic = -1;
//----
if(sob)
{
//----
while(tic == -1 && kk < 3)
{
tic = OrderSend(Symbol(),OP_BUY,0.1, Ask,5,Ask-150*Point,Ask+300*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_BUYLIMIT,0.1, Ask-150*Point,5,Ask-300*Point,Ask+300*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_BUYLIMIT,0.2, Ask-300*Point,5,Ask-450*Point,Ask+300*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_BUYLIMIT,0.4, Ask-450*Point,5,Ask-600*Point,Ask+450*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_BUYLIMIT,0.8, Ask-750*Point,5,0,0,"",255,0,CLR_NONE);
Print("tic_buy=", tic);
//----
if(tic==-1)
{
gle = GetLastError();
kk++;
Print("Îøèáêà ¹", gle, " ïðè buy ", kk);
Sleep(6000);
RefreshRates();
}
}
lastt = CurTime();
return;
}
tic = -1;
kk = 0;
//----
if(sos)
{
//----
while(tic == -1 && kk < 3)
{
tic = OrderSend(Symbol(),OP_SELL,0.1, Bid,5,Bid+150*Point,Bid-300*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_SELLLIMIT,0.1, Bid+150*Point,5,Bid+300*Point,Bid-300*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_SELLLIMIT,0.2, Bid+300*Point,5,Bid+450*Point,Bid-300*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_SELLLIMIT,0.4, Bid+450*Point,5,Bid-600*Point,Bid-450*Point,"",255,0,CLR_NONE);
Sleep(2);
OrderSend(Symbol(),OP_SELLLIMIT,0.8, Bid-750*Point,5,0,0,"",255,0,CLR_NONE);
Print("tic_sell=", tic);
//----
if(tic == -1)
{
gle = GetLastError();
kk++;
Print("Îøèáêà ¹", gle, " ïðè sell ", kk);
Sleep(6000);
RefreshRates();
}
}
lastt = CurTime();
return;
}
}