Hi All
I want help to modify this expert to open only one postion in each currency at the same plateform
//+------------------------------------------------------------------+
//| maak.mq4 |
//| Copyright © 2006, Abdurrazag Khaled |
//|
benkhaled684@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, ABDURRAZAG KHALED"
#property indicator_buffers 4
#property indicator_color1 DarkViolet
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Gray
//---- variables
extern double TakeProfit = 100;
extern double Lots = 0.1;
extern double TrailingStop = 19;
int ib = 0;
string mat = "";
double cv;
int ct = 0;
bool cd = true,Okay=false;
int init()
{
ib = Bars - 20;
if (ib < 0)
ib = 0;
return(0);
}
// Custor indicator deinitialization function
int deinit()
{
return(0);
}
// Custom indicator iteration function
int start()
{
int i,total;
bool Okay=false;
int counted_bars = IndicatorCounted();
string cds = "";
total=OrdersTotal();
if (counted_bars < 0) counted_bars = 0;
if (counted_bars > 0) counted_bars--;
if (counted_bars > ib) counted_bars = ib;
if (Period() == 30)
{
double ma48c, ma48b1, ma48b2,
dif0, dif1, dif2;
for (i = ib-counted_bars; i >= 0; i--)
{
ma48c = iMA(NULL, PERIOD_M30, 48, 0, MODE_LWMA,
PRICE_CLOSE, i);
ma48b1= iMA(NULL, PERIOD_M30, 48, 0, MODE_LWMA,
PRICE_CLOSE, i+1);
ma48b2 = iMA(NULL, PERIOD_M30, 48, 0, MODE_LWMA,
PRICE_CLOSE, i+2);
dif0 = iMA(NULL, PERIOD_M30, 8, 0, MODE_LWMA,
PRICE_CLOSE, i) - ma48c;
dif1 = iMA(NULL, PERIOD_M30, 8, 0, MODE_LWMA,
PRICE_CLOSE, i+1) - ma48b1;
dif2 = iMA(NULL, PERIOD_M30, 8, 0, MODE_LWMA,
PRICE_CLOSE, i+2) - ma48b2;
// for bull cross
if (dif0 > 0)
{
if (dif1 < 0)
{
cd = true;
if (MathAbs(dif0) < MathAbs(dif1))
{
ct = Time[i];
cv = ma48c;
}
else
{
ct = Time[i+1];
cv = ma48b1;
}
}
else
{
if (dif1 == 0 && dif2 < 0)
{
cd = true;
ct = Time[i+1];
cv = ma48b1;
}
}
}
// for beer cross
if (dif0 < 0)
{
if (dif1 > 0)
{
cd = false;
if (MathAbs(dif0) < MathAbs(dif1))
{
ct = Time[i];
cv = ma48c;
}
}
else
{
ct = Time[i+1];
cv = ma48b1;
}
}
else
{
if (dif1 == 0 && dif2 > 0)
{
cd = false;
ct = Time[i+1];
cv = ma48b1;
}
}
}
}
if (cd)
{
cds = "bull";
checkorder(Okay);
if(checkorder(true)==false)
{
OrderSend(Symbol(),OP_BUY,Lots,cv+35*Point,0,cv-
5*Point,cv+TakeProfit*Point,"",0,0,Green);
}
}
else
{
cds = "bear";
checkorder(Okay);
if(checkorder(true)==false)
{
OrderSend(Symbol(),OP_SELL,Lots,cv-30*Point,0,cv+5*Point,cv-
TakeProfit*Point,"",0,0,Green);
}
}
if (ct != 0)
Comment("Last ", mat, " cross: ", TimeToStr(ct), ", ", cd, " at ", cv);
else
Comment("Last ", mat, " cross: ", cd, " at ", cv);
TrailingPositionsBuy(TrailingStop);
TrailingPositionsSell(TrailingStop);
return(0);
}
bool checkorder(bool Okay)
{
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS)) {
if (OrderSymbol()==Symbol()) {
return(true);
}
}
}
return(false);
}
void TrailingPositionsBuy(int TS) {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol()) {
if (OrderType()==OP_BUY) {
if (Bid-OrderOpenPrice()>TS*Point) {
if (OrderStopLoss()<Bid-TS*Point)
ModifyStopLoss(Bid-TS*Point);
}
}
}
}
}
}
void TrailingPositionsSell(int TS) {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol()) {
if (OrderType()==OP_SELL) {
if (OrderOpenPrice()-Ask>TS*Point) {
if (OrderStopLoss()>Ask+TS*Point || OrderStopLoss()==0)
ModifyStopLoss(Ask+TS*Point);
}
}
}
}
}
}
void ModifyStopLoss(double ldStopLoss) {
bool fm;
fm = OrderModify(OrderTicket(),OrderOpenPrice
(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
}
//+------------------------------------------------------------------+