Orders Execution
0
Views
0
Downloads
0
Favorites
Profitability Reports
GBP/USD
Oct 2024 - Jan 2025
36.00 %
Total Trades
48
Won Trades
18
Lost trades
30
Win Rate
0.38 %
Expected payoff
-3.59
Gross Profit
97.60
Gross Loss
-270.00
Total Net Profit
-172.40
-100%
-50%
0%
50%
100%
NZD/USD
Oct 2024 - Jan 2025
21.00 %
Total Trades
44
Won Trades
12
Lost trades
32
Win Rate
0.27 %
Expected payoff
-5.16
Gross Profit
60.80
Gross Loss
-288.00
Total Net Profit
-227.20
-100%
-50%
0%
50%
100%
heikinashi-EA 7.01
//+------------------------------------------------------------------+
//| heikinashi-exp.mq4 |
//| Nick Bilak, beluck[AT]gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Nick Bilak"
#property link "http://www.mql4.info/"
#include <stdlib.mqh>
extern int expertId = 1;
extern int TakeProfit=70;
extern int StopLoss=90;
extern int TrailingStop = 50;
extern double Lots = 0.1;
extern int MaMetod = 2;
extern int MaPeriod = 1;
extern int MaMetod2 = 3;
extern int MaPeriod2 = 100;
extern bool TradeOnColor=true; //true - trade on color change, false - trade on line cross
extern int slippage=3; //slippage for market order processing
extern int shift=1; //shift to current bar,
extern int OrderTriesNumber=50; //to repeate sending orders when got some error
extern string EAName="heikenashi07.01";
bool buysig,sellsig,closebuy,closesell; int lastsig,tries,co;
void start() {
//---- check for history and trading
if(Bars<100) return; // just deleted trade alowed
CheckForSignals();
co=CalculateCurrentOrders();
if (co>0) CheckForClose();
co=CalculateCurrentOrders();
CheckForOpen();
TrailStop();
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders()
{
int ord;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==expertId) ord++;
}
//---- return orders volume
return(ord);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForSignals() {
buysig=false;
sellsig=false;
closebuy=false;
closesell=false;
//indicators variables
double ha0 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,0,shift);
double ha1 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,1,shift);
double ha0_2 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,0,shift+1);
double ha1_2 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,1,shift+1);
double ha11 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,shift);
double ha12 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,shift+1);
double ha21 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,shift);
double ha22 = iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,shift+1);
double hamax,hamin,hamax1,hamin1;
hamax=MathMax(MathMax(MathMax(ha11,ha0),ha21),ha1);
hamin=MathMin(MathMin(MathMin(ha11,ha0),ha21),ha1);
hamax1=MathMax(MathMax(MathMax(ha12,ha0_2),ha22),ha1_2);
hamin1=MathMin(MathMin(MathMin(ha12,ha0_2),ha22),ha1_2);
Comment(hamax," ",hamin);
if (TradeOnColor) {
if (ha11<ha21 && ha12>ha22) buysig=true;
if (ha11>ha21 && ha12<ha22) sellsig=true;
} else {
if (Close[shift]>hamax && Close[shift+1]<=hamax1) buysig=true;
if (Close[shift]<hamin && Close[shift+1]>=hamin1) sellsig=true;
}
closebuy=sellsig;
closesell=buysig;
}
void CheckForOpen() {
int res,tr;
//---- sell conditions
if(sellsig) {
if (co==0 && lastsig!=Time[0]) {
res = OpenAtMarket(OP_SELL,Lots);
lastsig=Time[0];
}
return;
}
//---- buy conditions
if(buysig) {
if (co==0 && lastsig!=Time[0]) {
res = OpenAtMarket(OP_BUY,Lots);
lastsig=Time[0];
}
return;
}
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose() {
bool bres; int tr;
for(int i=0;i<OrdersTotal();i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=expertId || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
if (closebuy) {
bres=CloseAtMarket(OrderTicket(),OrderLots());
break;
}
if(OrderType()==OP_SELL)
if (closesell) {
bres=CloseAtMarket(OrderTicket(),OrderLots());
break;
}
}
}
int OpenAtMarket(int mode,double lot) {
int res,tr,col;
double openprice,sl,tp;
tries=0;
while (res<=0 && tries<OrderTriesNumber) {
tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }
RefreshRates();
if (mode==OP_SELL) {
openprice=Bid;
sl=openprice+StopLoss*Point;
tp=openprice-TakeProfit*Point;
col=Red;
} else {
openprice=Ask;
sl=openprice-StopLoss*Point;
tp=openprice+TakeProfit*Point;
col=Blue;
}
res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+"_"+expertId,expertId,0,col);
tries++;
}
return(res);
}
bool CloseAtMarket(int ticket,double lot) {
bool bres=false; int tr;
tries=0;
while (!bres && tries<OrderTriesNumber) {
tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); }
RefreshRates();
bres=OrderClose(ticket,lot,OrderClosePrice(),slippage,White);
if (!bres) Print("Error closing order : ",ErrorDescription(GetLastError()));
tries++;
}
}
void TrailStop() {
bool bres;
double StopLoss;
if ( TrailingStop > 2 ) {
for (int i = 0; i < OrdersTotal(); i++) {
if ( OrderSelect (i, SELECT_BY_POS) == false ) continue;
if ( OrderSymbol() != Symbol() || OrderMagicNumber() != expertId ) continue;
if ( OrderType() == OP_BUY ) {
if ( Bid < OrderOpenPrice()+TrailingStop*Point ) continue;
StopLoss = Bid-TrailingStop*Point;
if ( StopLoss > OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);
if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));
}
}
if ( OrderType() == OP_SELL ) {
if ( Ask > OrderOpenPrice()-TrailingStop*Point ) continue;
StopLoss = Ask+TrailingStop*Point;
if ( StopLoss < OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold);
if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));
}
}
}
}
return;
}
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
---