
чтобы ордер ставился только при наборе нужного обьема на новом баре.
//+------------------------------------------------------------------+
//| Delta.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, AM2"
#property link "http://www.forexsystems.biz"
#property description "Forex expert advisor"
//--- Inputs
extern int StopLoss = 333; // лось
extern int TakeProfit = 333; // язь
extern int Delta = 33; // расстояние от цены до ордера
extern int BuySell = 0; // 0-оба 1-бай 2-селл
extern int Slip = 3; // проскальзывание ордера
extern int Expiration = 60; // истечение ордера в секундах
extern int TickVolume = 3333; // тиковый объем
extern double Lots = 0.3; // объем позиции
extern int Magic = 333; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrders()
{
bool del=true;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
if(OrderType()>3) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
long v = iVolume(NULL,0,0);
if(CountTrades()<1 && v>TickVolume)
{
if((BuySell==0 || BuySell==1) && CountOrders(4)<1) PutOrder(4,Ask+Delta*Point);
if((BuySell==0 || BuySell==2) && CountOrders(5)<1) PutOrder(5,Ask-Delta*Point);
}
if(CountTrades()>0) DelOrders();
Comment("\n Volume: ",v);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Grids.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
extern int StopLoss = 0; //Стоплосс ордера
extern int TakeProfit = 250; //Тейкпрофит ордера
extern int Slip = 20; //Проскальзывание ордера
extern int Step = 250; //Шаг установки ордеров
extern int Count = 3; //Количество устанавливаемых ордеров
extern int Expiration = 300; //Bремя истечения ордера в минутах
extern int Magic = 111; //Магик для ордеров
extern double Lots = 0.1; //Лот
bool b=true,s=true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=clrNONE;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*60,clr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 || OrderType()==1) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealType()
{
int type=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
type=1;//buy
}
if(OrderType()==OP_SELL)
{
type=2;//sell
}
}
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastProfitDealOpenPrice()
{
double price=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0) price=OrderOpenPrice();
}
}
return(price);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<1)
{
PutOrder(0,Ask);
PutOrder(1,Bid);
/**/
if(CountOrders(4)<1 && CountOrders(3)<1)
{
for(int i=1;i<=Count;i++)
{
PutOrder(4,Ask+Step*Point*i);
PutOrder(3,Ask+Step*Point*i);
}
}
if(CountOrders(5)<1 && CountOrders(2)<1)
{
for(int i=1;i<=Count;i++)
{
PutOrder(5,Ask-Step*Point*i);
PutOrder(2,Ask-Step*Point*i);
}
}
}
if(LastDealResult()==1 && LastDealType()==1 && b)
{
PutOrder(2,LastProfitDealOpenPrice());
b=false;
}
if(LastDealResult()==1 && LastDealType()==2 && s)
{
PutOrder(3,LastProfitDealOpenPrice());
s=false;
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Delta.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, AM2"
#property link "http://www.forexsystems.biz"
#property description "Forex expert advisor"
//--- Inputs
extern int StopLoss = 333; // лось
extern int TakeProfit = 333; // язь
extern int Delta = 33; // расстояние от цены до ордера
extern int BuySell = 0; // 0-оба 1-бай 2-селл
extern int Slip = 3; // проскальзывание ордера
extern int Expiration = 60; // истечение ордера
extern int TickVolume = 3333; // тиковый объем
extern double Lots = 0.3; // объем позиции
extern int Magic = 333; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*60,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrders()
{
bool del=true;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic || OrderSymbol()==Symbol())
{
if(OrderType()>3) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
long v = iVolume(NULL,0,1);
if(CountTrades()<1 && v>TickVolume && t!=Time[0])
{
if((BuySell==0 || BuySell==1) && CountOrders(4)<1) PutOrder(4,Ask+Delta*Point);
if((BuySell==0 || BuySell==2) && CountOrders(5)<1) PutOrder(5,Ask-Delta*Point);
t=Time[0];
}
if(CountTrades()>0) DelOrders();
Comment("\n Volume: ",v);
}
//+------------------------------------------------------------------+
int RegisterWindowMessageA(string lpstring);
int MT4InternalMsg = RegisterWindowMessageA("MetaTrader4_Internal_Message"); //incoming tick for EAs
PostMessageA(hwnd,MT4InternalMsg,2,1); //incoming tick for EAs
Андрей!
А я сам смогу его поправить? Открытый код у меня есть.
ошибка 4111 — Короткие позиции не разрешены
AM2