Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
demBot
//+------------------------------------------------------------------+
//| demBot.mq4 |
//| @2009 Desynced Tech |
//| http://desynced.no-ip.org/fx |
//+------------------------------------------------------------------+
#property copyright "@2009 Desynced Tech"
#property link "http://desynced.no-ip.org/fx"
#include <mysql.mqh>
datetime lastOrder =0;
int times =0;
int ticket = 0;
extern int takeprofit = 100;
extern int MAGIC = 35;
extern double lots = 0.1;
int demarkerPeriods = 20;
double tp;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
int getNumberTrades()
{
int total = OrdersTotal();
int numords = 0;
for(int cnt=0; cnt<total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)
return (OrderTicket());
}
return(-1);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int ratio = MathFloor( AccountBalance() /1000 );
if ( ratio > 0 ) lots = 0.1*(ratio+1);
// Print(lots);
double markers[20];
ArrayInitialize(markers,0);
double vol = (iMA(NULL,0,14,0,MODE_SMA,PRICE_HIGH,0)-iMA(NULL,0,14,0,MODE_SMA,PRICE_LOW,0))*1000;
//if ( OrdersTotal() > 0 ) Print (" counter " , iDeMarker(NULL,0,14,0));
for(int i=0;i<demarkerPeriods;i++) {
markers[i] = iDeMarker(NULL,0,demarkerPeriods,i);
}
int x =0, y=0;
bool acima ;
bool abaixo;
for( i=demarkerPeriods-1;i>0;i-- ) {
if ( markers[i] < 0.7 && markers[i-1] > 0.7 ) {
x = i ;
abaixo = true;
continue;
}
if ( markers[i] > 0.7 && markers[i-1] < 0.7 ) {
acima = true;
y = i;
continue;
}
}
//if (iDeMarker(NULL,0,14,0) > 0.7 && iDeMarker(NULL,0,14,1) < 0.7) {
int entrySafety = x -y;
if ( abaixo && acima && entrySafety > MathFloor(demarkerPeriods/2) && (TimeCurrent() - lastOrder) > (60*60*1.5) ) {
if ( getNumberTrades() < 0 ){
times++;
// if ( (TimeCurrent() - lastOrder) > (60*60*1.5) && times > 3 ) {
if ( takeprofit > 0 ) {
tp = Bid-takeprofit*Point;
}
else tp = 0;
Print( " vol entry" , vol , " entry " , x , " , " , y , " = " , (x -y ) );
ticket = OrderSend(Symbol(),OP_SELL, lots, Bid, 3, 0, tp,"", MAGIC, 0, Red);
if ( ticket > 0 ) {
/*
mysql_connect("192.168.0.3","forex","forex","forex",3306);
insertOrderDb(ticket,Symbol(),Bid,0, tp,MAGIC,"demBot",OP_SELL, TimeCurrent());
mysql_close(mysql);
*/
lastOrder = TimeCurrent();
times =0;
return(0);
}
// }
}
else {
if ( (TimeCurrent() - lastOrder) > (60*60*0.7) ) {
//OrderClose(ticket,lots,Ask,3);
}
}
}
int ticket = getNumberTrades() ;
acima =false;
abaixo = false;
for( i=demarkerPeriods-1;i>0;i-- ) {
if ( markers[i] > 0.3 && markers[i-1] <0.3 ) {
x = i ;
abaixo = true;
continue;
}
if ( markers[i] < 0.3 && markers[i-1] > 0.3 ) {
acima = true;
y = i;
continue;
}
}
entrySafety = x -y;
if ( false &&abaixo && acima && entrySafety >= 15 /*MathFloor(demarkerPeriods/2)*/ && (TimeCurrent() - lastOrder) > (60*60*0.5) ) {
if ( getNumberTrades() > 0 ) return(0);
if ( takeprofit > 0 ) {
tp = Ask+takeprofit*Point;
}
else tp = 0;
ticket = OrderSend(Symbol(),OP_BUY, lots, Ask, 3, 0, tp,"", MAGIC, 0, Red);
if ( ticket > 0 ) {
Print( " vol entry" , vol , " entry " , x , " , " , y , " = " , (x -y ) );
/*
mysql_connect("192.168.0.3","forex","forex","forex",3306);
insertOrderDb(ticket,Symbol(),Bid,0, tp,MAGIC,"demBot",OP_SELL, TimeCurrent());
mysql_close(mysql);
*/
lastOrder = TimeCurrent();
return(0);
}
}
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
---