Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
BloodyWanker090a_001
//+------------------------------------------------------------------+
//| Bloody Wanker EA by Dan Bowkley <danbowkley@gmail.com> |
//| Copyleft 2010, no rights reserved. Hereby released to the |
//| public domain with the intention that it make everyone rich. |
//| (Except spread-gouging brokers, whom I hope to see living in |
//| a cardboard box someday, begging for money from passing cars, |
//| pushing around a shopping cart full of junk and talking to |
//| themselves while scratching inappropriately...) |
//+------------------------------------------------------------------+
//Set all external variables
extern string RTFM = "Please read the manual before attempting to use this EA!";
extern int MagicNumber = 788752;
extern string MyOrderComment = "Bloody Wanker EA v0.90a";
extern double LAF = 2;
extern int MaxOpenOrders = 1;
extern bool UseTrailingStop = True;
extern double TakeProfit = 12;
extern double StopLoss = 30;
extern double TrailingStop = 10;
extern double TrailingStep = 2;
extern double MACDThreshold = 3;
extern double MACDSlowPeriod = 26;
extern double MACDFastPeriod = 12;
extern double MACDSignalPeriod = 9;
extern double MASlowPeriod = 143;
extern double MAFastPeriod = 10;
extern double StochKPeriod = 5;
extern double StochDPeriod = 3;
extern double StochSlowing = 3;
extern double StochZone = 30;
//Set up display labels
ObjectCreate("BWDisp_Head1",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_Head1",OBJPROP_COLOR,White);
ObjectSet("BWDisp_Head1",OBJPROP_CORNER,2);
ObjectSet("BWDisp_Head1",OBJPROP_XDISTANCE,4);
ObjectSet("BWDisp_Head1",OBJPROP_YDISTANCE,4);
ObjectSetText("BWDisp_Head1","Bloody Wanker EA, (C) 2010 by Dan Bowkley",14,"Arial",White);
ObjectCreate("BWDisp_Margin",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_Margin",OBJPROP_COLOR,White);
ObjectSet("BWDisp_Margin",OBJPROP_CORNER,0);
ObjectSet("BWDisp_Margin",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_Margin",OBJPROP_YDISTANCE,20);
ObjectCreate("BWDisp_Lots",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_Lots",OBJPROP_COLOR,White);
ObjectSet("BWDisp_Lots",OBJPROP_CORNER,0);
ObjectSet("BWDisp_Lots",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_Lots",OBJPROP_YDISTANCE,40);
ObjectCreate("BWDisp_OpenOrders",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_OpenOrders",OBJPROP_COLOR,White);
ObjectSet("BWDisp_OpenOrders",OBJPROP_CORNER,0);
ObjectSet("BWDisp_OpenOrders",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_OpenOrders",OBJPROP_YDISTANCE,60);
ObjectCreate("BWDisp_Line1",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_Line1",OBJPROP_COLOR,White);
ObjectSet("BWDisp_Line1",OBJPROP_CORNER,0);
ObjectSet("BWDisp_Line1",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_Line1",OBJPROP_YDISTANCE,80);
ObjectSetText("BWDisp_Line1","=======================",12,"Arial",White);
ObjectCreate("BWDisp_MASignal",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_MASignal",OBJPROP_CORNER,0);
ObjectSet("BWDisp_MASignal",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_MASignal",OBJPROP_YDISTANCE,100);
ObjectCreate("BWDisp_MACDSignal",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_MACDSignal",OBJPROP_CORNER,0);
ObjectSet("BWDisp_MACDSignal",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_MACDSignal",OBJPROP_YDISTANCE,120);
ObjectCreate("BWDisp_StochSignal",OBJ_LABEL,0,0,0);
ObjectSet("BWDisp_StochSignal",OBJPROP_CORNER,0);
ObjectSet("BWDisp_StochSignal",OBJPROP_XDISTANCE,0);
ObjectSet("BWDisp_StochSignal",OBJPROP_YDISTANCE,140);
//Trailing Stop logic from etrailing.mq4, thanks to kimiv.ru for this!
void TrailingPositions() {
double pBid, pAsk, pp;
pp = MarketInfo(OrderSymbol(), MODE_POINT);
if (OrderType()==OP_BUY) {
pBid = MarketInfo(OrderSymbol(), MODE_BID);
if ((pBid-OrderOpenPrice())>TrailingStop*pp) {
if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
ModifyStopLoss(pBid-TrailingStop*pp);
return;
}
}
}
if (OrderType()==OP_SELL) {
pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
if ((OrderOpenPrice()-pAsk)>TrailingStop*pp) {
if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {
ModifyStopLoss(pAsk+TrailingStop*pp);
return;
}
}
}
}
void ModifyStopLoss(double ldStopLoss) {
bool fm;
fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,Blue);
}
//Let us begin...first, assign/calculate internally used variables
int start() {
int cnt;
int ticket;
int OpenOrderCount = 0;
double MacdCurrent=iMACD(NULL,0,MACDFastPeriod,MACDSlowPeriod,MACDSignalPeriod,PRICE_CLOSE,MODE_MAIN,0);
double MacdPrevious=iMACD(NULL,0,MACDFastPeriod,MACDSlowPeriod,MACDSignalPeriod,PRICE_CLOSE,MODE_MAIN,1);
double SignalCurrent=iMACD(NULL,0,MACDFastPeriod,MACDSlowPeriod,MACDSignalPeriod,PRICE_CLOSE,MODE_SIGNAL,0);
double SignalPrevious=iMACD(NULL,0,MACDFastPeriod,MACDSlowPeriod,MACDSignalPeriod,PRICE_CLOSE,MODE_SIGNAL,1);
double FastMaCurrent=iMA(NULL,0,MAFastPeriod,0,MODE_EMA,PRICE_CLOSE,0);
double FastMaPrevious=iMA(NULL,0,MAFastPeriod,0,MODE_EMA,PRICE_CLOSE,1);
double SlowMaCurrent=iMA(NULL,0,MASlowPeriod,0,MODE_EMA,PRICE_CLOSE,0);
double SlowMaPrevious=iMA(NULL,0,MASlowPeriod,0,MODE_EMA,PRICE_CLOSE,1);
double StochMain=iStochastic(NULL,0,StochKPeriod,StochDPeriod,StochSlowing,MODE_LWMA,1,0,1);
double StochSignal=iStochastic(NULL,0,StochKPeriod,StochDPeriod,StochSlowing,MODE_LWMA,1,1,1);
int StochZoneBuy = StochZone;
int StochZoneSell = 100 - StochZone;
bool StochBuy=False;
if (StochSignal>StochZoneBuy && StochMain>StochZoneBuy){StochBuy=True;}
bool StochSell=False;
if (StochSignal<StochZoneSell && StochMain<StochZoneSell){StochSell=True;}
bool MacdBuy=False;
if (MacdCurrent>SignalCurrent&&MacdPrevious<SignalPrevious&&MathAbs(MacdCurrent)>(MACDThreshold*Point)){MacdBuy=True;}
bool MacdSell=False;
if (MacdCurrent<SignalCurrent&&MacdPrevious>SignalPrevious&&MathAbs(MacdCurrent)>(MACDThreshold*Point)){MacdSell=True;}
bool MABuy=False;
if (FastMaCurrent>FastMaPrevious&&FastMaCurrent<SlowMaCurrent){MABuy=True;}
bool MASell=False;
if (FastMaCurrent<FastMaPrevious&&FastMaCurrent>SlowMaCurrent){MASell=True;}
double Lots=MathMin((AccountFreeMargin()*LAF/10000),MarketInfo(Symbol(),MODE_MAXLOT));
double OrderBuyTakeProfit = 0;
double OrderSellTakeProfit = 0;
double OrderBuyStopLoss = Bid-StopLoss*Point;
double OrderSellStopLoss = Ask+StopLoss*Point;
//Set TP for buy and sell, if needed
if (!UseTrailingStop) {
OrderBuyTakeProfit = Bid+TakeProfit*Point;
OrderSellTakeProfit = Ask-TakeProfit*Point;
}
//Determine if we have open orders with our magic number, count them for later, and run trailing stops on our orders
for(cnt=OrdersTotal();cnt>=0;cnt--){
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber()==MagicNumber) {
if (UseTrailingStop){
TrailingPositions();
}
OpenOrderCount++;
}
}
//Display stuff
ObjectSetText("BWDisp_Margin",StringConcatenate("Available Margin: ",AccountFreeMargin()),12,"Arial",White);
ObjectSetText("BWDisp_Lots",StringConcatenate("Lot Size: ",Lots),12,"Arial",White);
ObjectSetText("BWDisp_OpenOrders",StringConcatenate("Open Orders: ",OpenOrderCount),12,"Arial",White);
if (MABuy) {
ObjectSetText("BWDisp_MASignal","Moving Average: BUY",12,"Arial",Green);
}
if (MASell) {
ObjectSetText("BWDisp_MASignal","Moving Average: SELL",12,"Arial",Red);
}
if (!MABuy && !MASell) {
ObjectSetText("BWDisp_MASignal","Moving Average: HOLD",12,"Arial",White);
}
if (MacdBuy) {
ObjectSetText("BWDisp_MACDSignal","MACD: BUY",12,"Arial",Green);
}
if (MacdSell) {
ObjectSetText("BWDisp_MACDSignal","MACD: SELL",12,"Arial",Red);
}
if (!MacdBuy && !MacdSell) {
ObjectSetText("BWDisp_MACDSignal","MACD: HOLD",12,"Arial",White);
}
if (StochBuy) {
ObjectSetText("BWDisp_StochSignal","Stochastic: BUY",12,"Arial",Green);
}
if (StochSell) {
ObjectSetText("BWDisp_StochSignal","Stochastic: SELL",12,"Arial",Red);
}
if (!StochBuy && !StochSell) {
ObjectSetText("BWDisp_StochSignal","Stochastic: HOLD",12,"Arial",White);
}
//Should we buy?
if (MacdBuy&&StochBuy&&MABuy&&OpenOrderCount<MaxOpenOrders){
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,OrderBuyStopLoss,OrderBuyTakeProfit,MyOrderComment,MagicNumber,0,Green);
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){
Print("BUY order opened : ",OrderOpenPrice()," LOTS=",Lots);
}
else {
Print("Error opening BUY order : ",GetLastError()," Lot Size=",Lots);
return(0);
}
}
}
//Should we sell?
if (MacdSell&&StochSell&&MASell&&OpenOrderCount<MaxOpenOrders){
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,OrderSellStopLoss,OrderSellTakeProfit,MyOrderComment,MagicNumber,0,Red);
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)){
Print("SELL order opened : ",OrderOpenPrice()," LOTS=",Lots);
}
else {
Print("Error opening SELL order : ",GetLastError()," Lot Size=",Lots);
return(0);
}
}
}
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---