Hedge EA - page 2

 
Marco vd Heijden:

Go here: https://www.mql5.com/en/job

Dear sir 

please modify 

its taking stop loss 

i need only take profit 

like martingle averaging .

Regards 

Sanjay




#property copyright ""

#property link ""

#property version "1.02"

#property strict

//--- input parameters

input int TakeProfit=500;

input int StopLoss=500;

input double LotSize=0.1;

input int Slippage=30;

input int MagicNumber=5555;

int OT;

double Martingale=LotSize;

//+------------------------------------ ------------------------------+

//| Expert initialization function |

//+------------------------------------ ------------------------------+

int OnInit()

{

//---


//---

return(INIT_SUCCEEDED);

}

//+------------------------------------ ------------------------------+

//| Expert deinitialization function |

//+------------------------------------ ------------------------------+

void OnDeinit(const int reason)

{

//---


}

//+------------------------------------ ------------------------------+

//| Expert tick function |

//+------------------------------------ ------------------------------+

void OnTick()

{

//---


if (OT!=NULL)

   {OrderSelect(OT,SELECT_BY_TICKET);

    if (OrderCloseTime()!=NULL && OrderProfit()<0)

       {Martingale=Martingale*1.5;};

    if (OrderCloseTime()!=NULL && OrderProfit()>0)

       {Martingale=LotSize;};};


//if(TotalOpenOrders() == 0 && IsNewBar() == true)

if(IsNewBar() == true)

{

if(Close[1] > Open[1] )

{

//Open Buy Order

Print("I am at Buy with Ask: " + Ask + " And TakeProfit :" + TakeProfit + " And Pint: " + _Point);

OrderSend(_Symbol,OP_BUY,Martingale,Ask,Slippage,Ask-StopLoss*_Point,Ask+TakeProfit*_Point,"BUY",MagicNumber);

}

// Sell Logic

if(Close[1] < Open[1] )

{

Print("I am at Buy with Ask: " + Ask + " And TakeProfit :" + TakeProfit + " And Pint: " + _Point);

OrderSend(_Symbol,OP_SELL,Martingale,Bid,Slippage,Bid+StopLoss*_Point,Bid-TakeProfit*_Point,"SELL",MagicNumber);


}

}

OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

OT=OrderTicket();


}

//+------------------------------------ ------------------------------+


// Check if there is a new bar

bool IsNewBar()

{

static datetime RegBarTime=0;

datetime ThisBarTime = Time[0];


if (ThisBarTime == RegBarTime)

{

return(false);

}

else

{

RegBarTime = ThisBarTime;

return(true);

}

}


// Returns the number of total open orders for this Symbol and MagicNumber

int TotalOpenOrders()

{

int total_orders = 0;


for(int order = 0; order < OrdersTotal(); order++)

{

if(OrderSelect(order,SELECT_BY_POS, MODE_TRADES)==false) break;


if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol)

{

total_orders++;

}

}


return(total_orders);

}

 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 
Sergey Golubev:

Thanks sir

 
54566766:

Thanks sir

#property copyright ""
#property link ""
#property version "1.02"
#property strict
//--- input parameters
input int TakeProfit=500;
input int StopLoss=500;
input double LotSize=0.1;
input int Slippage=30;
input int MagicNumber=5555;
int OT;
double Martingale=LotSize;
//+------------------------------------ ------------------------------+
//| Expert initialization function |
//+------------------------------------ ------------------------------+
int OnInit()
{
//---

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------ ------------------------------+
//| Expert deinitialization function |
//+------------------------------------ ------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------ ------------------------------+
//| Expert tick function |
//+------------------------------------ ------------------------------+
void OnTick()
{
//---

if (OT!=NULL)
   {OrderSelect(OT,SELECT_BY_TICKET);
    if (OrderCloseTime()!=NULL && OrderProfit()<0)
       {Martingale=Martingale*1.5;};
    if (OrderCloseTime()!=NULL && OrderProfit()>0)
       {Martingale=LotSize;};};

//if(TotalOpenOrders() == 0 && IsNewBar() == true)
if(IsNewBar() == true)
{
if(Close[1] > Open[1] )
{
//Open Buy Order
Print("I am at Buy with Ask: " + Ask + " And TakeProfit :" + TakeProfit + " And Pint: " + _Point);
OrderSend(_Symbol,OP_BUY,Martingale,Ask,Slippage,Ask-StopLoss*_Point,Ask+TakeProfit*_Point,"BUY",MagicNumber);
}
// Sell Logic
if(Close[1] < Open[1] )
{
Print("I am at Buy with Ask: " + Ask + " And TakeProfit :" + TakeProfit + " And Pint: " + _Point);
OrderSend(_Symbol,OP_SELL,Martingale,Bid,Slippage,Bid+StopLoss*_Point,Bid-TakeProfit*_Point,"SELL",MagicNumber);

}
}
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
OT=OrderTicket();

}
//+------------------------------------ ------------------------------+

// Check if there is a new bar
bool IsNewBar()
{
static datetime RegBarTime=0;
datetime ThisBarTime = Time[0];

if (ThisBarTime == RegBarTime)
{
return(false);
}
else
{
RegBarTime = ThisBarTime;
return(true);
}
}

// Returns the number of total open orders for this Symbol and MagicNumber
int TotalOpenOrders()
{
int total_orders = 0;

for(int order = 0; order < OrdersTotal(); order++)
{
if(OrderSelect(order,SELECT_BY_POS, MODE_TRADES)==false) break;

if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol)
{
total_orders++;
}
}

return(total_orders);
}
Reason: