Hallo everyone ,
I just wonder if somebody can make these two EAs as one.
I just wonder if somebody can make these two EAs as one.
Attached File(s)
Combining strategies 13 replies
combining two pairs 5 replies
Combining pairs to save pips 5 replies
Combining EA Results 2 replies
TradeManagerBE(Symbol(),MagicNumber);
// extern string behi = "---------------------------------------------------------------------"; extern string BE = "----BreakEven settings----"; extern bool BreakEven = FALSE; extern double BreakEvenPips = 34; extern double BreakEvenProfit = 5; extern bool HideBreakEvenStop = FALSE; extern double PipsAwayFromVisualBE = 50; extern string sep1 = "---------------------------------------------------------------------"; extern string JSL = "----JumpingStopLoss settings----"; extern bool JumpingStop = FALSE; extern double JumpingStopPips = 38; extern bool AddBEP = TRUE; //This adds BreakEvenProfits extern bool JumpAfterBreakevenOnly = TRUE; extern bool HideJumpingStop = FALSE; extern double PipsAwayFromVisualJS = 50; bool ShowAlerts=false; bool PrintToJournal=TRUE; int xMultiplier; double xpips2dbl;
void TradeManagerBE(string symbol,int magicnumber=0) {
bool FilterBySymbol=TRUE;
bool FilterByMagicNumber=TRUE;
for (int cnt=OrdersTotal()-1; cnt>=0; cnt--) {
if (!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) continue;
if (FilterBySymbol && OrderSymbol()!=symbol) continue;
if (FilterByMagicNumber && OrderMagicNumber()!=magicnumber) continue;
if (OrderType()>OP_SELL) continue;//only buy and sell trades
{
BrokerDigitAdjust(OrderSymbol());
if (BreakEven) BreakEvenStopLoss();
if (JumpingStop) JumpingStopLoss();
}
}//for (int cnt=OrdersTotal()-1; cnt>=0; cnt--) {
}
void BreakEvenStopLoss() {// Move stop loss to breakeven, based upon/taken from mptm global ea
double ask = MarketInfo(OrderSymbol(),MODE_ASK);
double bid = MarketInfo(OrderSymbol(),MODE_BID);
//Check hidden BE for trade closure
if (HideBreakEvenStop)
{
bool TradeClosed = CheckForHiddenStopLossHit(OrderType(), PipsAwayFromVisualBE, OrderStopLoss() );
if (TradeClosed) return;//Trade has closed, so nothing else to do
}//if (HideBreakEvenStop)
bool result;
if (OrderType()==OP_BUY)
{
if (bid >= OrderOpenPrice () + (BreakEvenPips * xpips2dbl) &&
OrderStopLoss()<OrderOpenPrice())
{
while (IsTradeContextBusy()) Sleep(100);
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+(BreakEvenProfit * xpips2dbl),OrderTakeProfit(),0,CLR_NONE);
if (result && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
if (PrintToJournal) Print("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
if (!result)
{
int err=GetLastError();
if (ShowAlerts==true) Alert("Setting of breakeven SL ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
if (PrintToJournal) Print("Setting of breakeven SL ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
}//if !result && ShowAlerts)
}
}
if (OrderType()==OP_SELL)
{
if (ask <= OrderOpenPrice() - (BreakEvenPips * xpips2dbl) &&
(OrderStopLoss()>OrderOpenPrice()|| OrderStopLoss()==0))
{
while (IsTradeContextBusy()) Sleep(100);
result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-(BreakEvenProfit * xpips2dbl),OrderTakeProfit(),0,CLR_NONE);
if (result && ShowAlerts==true) Alert("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
if (PrintToJournal) Print("Breakeven set on ", OrderSymbol(), " ticket no ", OrderTicket());
if (!result && ShowAlerts)
{
err=GetLastError();
if (ShowAlerts==true) Alert("Setting of breakeven SL ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
if (PrintToJournal) Print("Setting of breakeven SL ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
}//if !result && ShowAlerts)
}
}
} // End BreakevenStopLoss sub
bool CheckForHiddenStopLossHit(int type, double iPipsAboveVisual, double stop ) { //based upon/taken from mptm global ea
//Reusable code that can be called by any of the stop loss manipulation routines except HiddenStopLoss().
//Checks to see if the market has hit the hidden sl and attempts to close the trade if so.
//Returns true if trade closure is successful, else returns false
double ask = MarketInfo(OrderSymbol(),MODE_ASK);
double bid = MarketInfo(OrderSymbol(),MODE_BID);
//Check buy trade
if (type == OP_BUY)
{
double sl = NormalizePrice(OrderSymbol(),(stop + (iPipsAboveVisual * xpips2dbl)));
if (bid <= sl)
{
while (IsTradeContextBusy()) Sleep(100);
bool result = OrderClose(OrderTicket(), OrderLots(), bid, 99999, CLR_NONE);//OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 5, CLR_NONE);
if (result)
{
if (ShowAlerts==true) Alert("Stop loss hit. Close of ", OrderSymbol(), " ticket no ", OrderTicket());
}//if (result)
else
{
int err=GetLastError();
if (ShowAlerts==true) Alert("Stop loss hit. Close of ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
if (PrintToJournal) Print("Stop loss hit. Close of ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
}//else
}//if (bid <= sl)
}//if (type = OP_BUY)
//Check buy trade
if (type == OP_SELL)
{
sl = NormalizePrice(OrderSymbol(),(stop - (iPipsAboveVisual * xpips2dbl)));
if (ask >= sl)
{
while (IsTradeContextBusy()) Sleep(100);
result = OrderClose(OrderTicket(), OrderLots(), ask, 99999, CLR_NONE);//OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 5, CLR_NONE);
if (result)
{
if (ShowAlerts==true) Alert("Stop loss hit. Close of ", OrderSymbol(), " ticket no ", OrderTicket());
}//if (result)
else
{
err=GetLastError();
if (ShowAlerts==true) Alert("Stop loss hit. Close of ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
if (PrintToJournal) Print("Stop loss hit. Close of ", OrderSymbol(), " ticket no ", OrderTicket()," failed with error (",err,")");
}//else
}//if (ask >= sl)
}//if (type = OP_SELL)
return(result);
}//End bool CheckForHiddenStopLossHit(int type, double iPipsAboveVisual, double stop )
void JumpingStopLoss() {//based upon/taken from mptm global ea
double ask = MarketInfo(OrderSymbol(),MODE_ASK);
double bid = MarketInfo(OrderSymbol(),MODE_BID);
// Jump sl by pips and at intervals chosen by user .
// Also carry out partial closure if the user requires this
// Abort the routine if JumpAfterBreakevenOnly is set to true and be sl is not yet set
if (JumpAfterBreakevenOnly && OrderType()==OP_BUY)
{
if(OrderStopLoss()<OrderOpenPrice()) return(0);
}
if (JumpAfterBreakevenOnly && OrderType()==OP_SELL)
{
if(OrderStopLoss()>OrderOpenPrice()) return(0);
}
double sl=OrderStopLoss(); //Stop loss
if (OrderType()==OP_BUY)
{
//Check hidden js for trade closure
if (HideJumpingStop)
{
bool TradeClosed = CheckForHiddenStopLossHit(OP_BUY, PipsAwayFromVisualJS, OrderStopLoss() );
if (TradeClosed) return;//Trade has closed, so nothing else to do
}//if (HideJumpingStop)
// First check if sl needs setting to breakeven
if (sl==0 || sl<OrderOpenPrice())
{
if (ask >= OrderOpenPrice() + (JumpingStopPips * xpips2dbl))
{
sl=OrderOpenPrice();
if (AddBEP==true) sl=sl+(BreakEvenProfit * xpips2dbl); // If user wants to add a profit to the break even
while (IsTradeContextBusy()) Sleep(100);
bool result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,CLR_NONE);
if (result)
{
if (ShowAlerts==true) Alert("Jumping stop set at breakeven ",sl, " ", OrderSymbol(), " ticket no ", OrderTicket());
if (PrintToJournal) Print("Jumping stop set at breakeven : ", OrderSymbol(), " : SL ", sl, " : Ask ", ask);
}//if (result)
if (!result)
{
int err=GetLastError();
if (ShowAlerts) Alert(OrderSymbol(), " buy trade. Jumping stop function failed to set SL at breakeven, with error(",err,")");
if (PrintToJournal) Print(OrderSymbol(), " buy trade. Jumping stop function failed to set SL at breakeven, with error(",err,")");
}//if (!result)
return(0);
}//if (ask >= OrderOpenPrice() + (JumpingStopPips * xpips2dbl))
} //close if (sl==0 || sl<OrderOpenPrice()
// Increment sl by sl + JumpingStopPips.
// This will happen when market price >= (sl + JumpingStopPips)
if (bid>= sl + ((JumpingStopPips*2) * xpips2dbl) && sl>= OrderOpenPrice())
{
sl=sl+(JumpingStopPips * xpips2dbl);
while (IsTradeContextBusy()) Sleep(100);
result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,CLR_NONE);
if (result)
{
if (ShowAlerts==true) Alert("Jumping stop set at ",sl, " ", OrderSymbol(), " ticket no ", OrderTicket());
if (PrintToJournal) Print("Jumping stop set : ", OrderSymbol(), " : SL ", sl, " : Ask ", ask);
}//if (result)
if (!result)
{
err=GetLastError();
if (ShowAlerts) Alert(OrderSymbol(), " buy trade. Jumping stop function failed with error(",err,")");
if (PrintToJournal) Print(OrderSymbol(), " buy trade. Jumping stop function failed with error(",err,")");
}//if (!result)
}// if (bid>= sl + (JumpingStopPips * xpips2dbl) && sl>= OrderOpenPrice())
}//if (OrderType()==OP_BUY)
if (OrderType()==OP_SELL)
{
//Check hidden js for trade closure
if (HideJumpingStop)
{
TradeClosed = CheckForHiddenStopLossHit(OP_SELL, PipsAwayFromVisualJS, OrderStopLoss() );
if (TradeClosed) return;//Trade has closed, so nothing else to do
}//if (HideJumpingStop)
// First check if sl needs setting to breakeven
if (sl==0 || sl>OrderOpenPrice())
{
if (ask <= OrderOpenPrice() - (JumpingStopPips * xpips2dbl))
{
sl = OrderOpenPrice();
if (AddBEP==true) sl=sl-(BreakEvenProfit * xpips2dbl); // If user wants to add a profit to the break even
while (IsTradeContextBusy()) Sleep(100);
result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,CLR_NONE);
if (result)
{
}//if (result)
if (!result)
{
err=GetLastError();
if (ShowAlerts) Alert(OrderSymbol(), " sell trade. Jumping stop function failed to set SL at breakeven, with error(",err,")");
if (PrintToJournal) Print(OrderSymbol(), " sell trade. Jumping stop function failed to set SL at breakeven, with error(",err,")");
}//if (!result)
return(0);
}//if (ask <= OrderOpenPrice() - (JumpingStopPips * xpips2dbl))
} // if (sl==0 || sl>OrderOpenPrice()
// Decrement sl by sl - JumpingStopPips.
// This will happen when market price <= (sl - JumpingStopPips)
if (bid<= sl - ((JumpingStopPips*2) * xpips2dbl) && sl<= OrderOpenPrice())
{
sl=sl-(JumpingStopPips * xpips2dbl);
while (IsTradeContextBusy()) Sleep(100);
result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,CLR_NONE);
if (result)
{
if (ShowAlerts==true) Alert("Jumping stop set at ",sl, " ", OrderSymbol(), " ticket no ", OrderTicket());
if (PrintToJournal) Print("Jumping stop set : ", OrderSymbol(), " : SL ", sl, " : Ask ", ask);
}//if (result)
if (!result)
{
err=GetLastError();
if (ShowAlerts) Alert(OrderSymbol(), " sell trade. Jumping stop function failed with error(",err,")");
if (PrintToJournal) Print(OrderSymbol(), " sell trade. Jumping stop function failed with error(",err,")");
}//if (!result)
}// close if (bid>= sl + (JumpingStopPips * xpips2dbl) && sl>= OrderOpenPrice())
}//if (OrderType()==OP_SELL)
}//End of JumpingStopLoss sub
//Open price for pending order must be adjusted to be a multiple of ticksize, not point, and on metals they are not the same.
//see also http://forum.mql4.com/45425#564188
double NormalizePrice(string symbol, double price) {
if (price==0.00000000) return(0.0);
double ts = MarketInfo(symbol,MODE_TICKSIZE);
return(MathRound(price/ts)*ts );
}
void BrokerDigitAdjust(string symbol) {
xMultiplier = 1;
int digits = MarketInfo(symbol,MODE_DIGITS);
if (digits == 3 || digits == 5) xMultiplier = 10;
if (digits == 6) xMultiplier = 100;
if (digits == 7) xMultiplier = 1000;
xpips2dbl = xMultiplier*MarketInfo(symbol,MODE_POINT);
//Slippage*=xMultiplier;
} DislikedBuy----------------> if buy volume is greater than sell volume at the end af the candle .
Sell ---------------> if sell volume is smaller than the buy volume at the end of the candleIgnored
DislikedThe postions open about 10pips away from entrance point. Could you fix it?Ignored