EA4-BuyBuyBuy_SellSellSell

input double StartingBalance=1884.01;
input double TakeProfit= 55;
input double StopLoss = 12;
input double TrailingStop= 6;
input double Lots;
int MagicNumber=1151;
//+---------+
//| init |
//+---------+
int init()
{
}
//+---------+
//| De-init |
//+---------+
int deinit()
{
}
//+---------+
//| Start |
//+---------+
int start()
{
int cnt, ticket, total;
double SL,TP;
// Lot increasement based on StartingBalance
// this will trade 1.0, then 1.1, then 1.2 etc as balance grows
// or 0.9 then 0.8 then 0.7 as balance shrinks
Lots=NormalizeDouble(AccountBalance()/StartingBalance,1);
total = 0;
for(cnt=OrdersTotal()-1; cnt>=0; cnt--)
{
OrderSelect (cnt, SELECT_BY_POS, MODE_TRADES);
if ( OrderSymbol() != Symbol()) continue;
if ( OrderMagicNumber() != MagicNumber) continue;
if(OrderType() == OP_BUY ) total++;
if(OrderType() == OP_SELL ) total++;
}
if(total < 1) { SL=Ask-StopLossPoint; TP=Ask+TakeProfitPoint; ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,SL,TP,NULL,MagicNumber,0,White); if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("BUY order opened : ",OrderOpenPrice());
} } else { Print("Error opening BUY order : ",GetLastError()); } }
for(cnt=total-1; cnt>=0; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) // long position is opened { // check for trailing stop if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { SL=Bid-Point*TrailingStop; TP=OrderTakeProfit(); OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Green); } } } } if(OrderType()==OP_SELL) // long position is opened { // check for trailing stop if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { SL=Ask+Point*TrailingStop; TP=OrderTakeProfit(); OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Red); } } } } } }
}