StopLoss=150
StopLoss,F=0
StopLoss,1=50
StopLoss,2=10
StopLoss,3=150
TakeProfit=25
TakeProfit,F=0
TakeProfit,1=5
TakeProfit,2=5
TakeProfit,3=30
BBPeriod=68.00000000
BBPeriod,F=1
BBPeriod,1=4.00000000
BBPeriod,2=4.00000000
BBPeriod,3=144.00000000
BBDev=2.60000000
BBDev,F=1
BBDev,1=1.00000000
BBDev,2=0.20000000
BBDev,3=3.00000000
TRazmah=1300.00000000
TRazmah,F=1
TRazmah,1=300.00000000
TRazmah,2=100.00000000
TRazmah,3=3000.00000000
FRazmah=100.00000000
FRazmah,F=1
FRazmah,1=100.00000000
FRazmah,2=100.00000000
FRazmah,3=600.00000000
StartHour=8
StartHour,F=0
StartHour,1=8
StartHour,2=0
StartHour,3=0
EndHour=23
EndHour,F=0
EndHour,1=23
EndHour,2=0
EndHour,3=0
HighLotHour=11
HighLotHour,F=1
HighLotHour,1=0
HighLotHour,2=1
HighLotHour,3=23
Lots=4.00000000
Lots,F=0
Lots,1=0.00000000
Lots,2=0.00000000
Lots,3=0.00000000
HighLot=40.00000000
HighLot,F=0
HighLot,1=20.00000000
HighLot,2=0.00000000
HighLot,3=0.00000000
Risk=30.00000000
Risk,F=0
Risk,1=30.00000000
Risk,2=0.00000000
Risk,3=0.00000000
//+------------------------------------------------------------------+
//| LBV.mq4 |
//| Copyright © 2015, AM2. |
//| http://www.forexsyatems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2."
#property link "http://www.forexsyatems.biz"
#define MagicNumber 20150509
extern int StopLoss = 500;
extern int TakeProfit = 25;
extern double BBPeriod = 60;
extern double BBDev = 2.6;
extern double TRazmah = 300;
extern double FRazmah = 100;
extern int StartHour = 8;
extern int EndHour = 23;
extern int HighLotHour = 20;
extern double Lots = 0;
extern double HighLot = 20;
extern double Risk = 30;
int Trend=0,Flat=0,LastTime=0;
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
//----
int res;
//---- get Indicatorrs
double bbh=iBands(NULL,0,BBPeriod,BBDev,0,PRICE_CLOSE,MODE_UPPER,1);
double bbl=iBands(NULL,0,BBPeriod,BBDev,0,PRICE_CLOSE,MODE_LOWER,1);
double r=bbh-bbl;
//---- buy
bool BuyInTrend= Ask>bbh && r>=TRazmah*Point;
bool BuyInFlat = Ask<bbl && r<=FRazmah*Point;
if((BuyInTrend || BuyInFlat) && Trend==0)
{
res=OrderSend(Symbol(),OP_BUY,Lot(Risk,StopLoss),Ask,30,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MagicNumber,0,Blue);
Flat=0;
Trend++;
return;
}
//---- sell
bool SellInTrend = Bid<bbl && r>=TRazmah*Point;
bool SellInFlat = Bid>bbh && r<=FRazmah*Point;
if((SellInTrend || SellInFlat) && Flat==0)
{
res=OrderSend(Symbol(),OP_SELL,Lot(Risk,StopLoss),Bid,30,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MagicNumber,0,Red);
Flat++;
Trend=0;
return;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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()==MagicNumber)
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot(double LotRisk,int SL)
{
if(Lots==0)
{
double lots=AccountBalance()*LotRisk/(100*SL);
lots=NormalizeDouble(lots,2);
}
else lots=Lots;
if(Hour()>=HighLotHour) lots=HighLot;
return(lots);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Time[0]!=LastTime)
{
if(Hour()>=StartHour && Hour()<=EndHour && CountTrades()<1) OpenPos();
}
LastTime=Time[0];
Comment("\n Trend: ",Trend,
"\n Flat: ",Flat);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TimeOpen.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property description "Time Open expert advisor"
#include <stdlib.mqh>
//--- Inputs
extern int StopLoss = 555; // лось
extern int TakeProfit = 555; // язь
extern int BuySell = 0; // 0-бай. 1-селл. 2-бай/селл
extern int Slip = 100; // проскальзывание
extern int Count = 1; // количество открываемых ордеров
extern int MAGIC = 123; // магик
extern double Lots = 0.1; // лот
extern double KLot = 2; // увеличение лота
extern double MaxLot = 5.0; // максимальный лот
extern string t = "Время";
extern int t1 = 1; // время 1
extern int t2 = 5; // время 1
extern int t3 = 15; // время 1
extern int t4 = 30; // время 1
extern int t5 = 60; // время 1
extern int t6 = 240; // время 1
extern int t7 = 1440; // время 1
extern int t8 = 10080; // время 1
extern int t9 = 43200; // время 1
int tf[9],k=0;
datetime StartTime;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
StartTime=TimeCurrent();
tf[0]=t1;
tf[1]=t2;
tf[2]=t3;
tf[3]=t4;
tf[4]=t5;
tf[5]=t6;
tf[6]=t7;
tf[7]=t8;
tf[8]=t9;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
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()==OP_BUY || OrderType()==OP_SELL) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
void OpenOrd()
{
int res,err;
double sl,tp;
double ask=MarketInfo(OrderSymbol(),MODE_ASK);
double bid=MarketInfo(OrderSymbol(),MODE_BID);
//--- sell conditions
if(BuySell==1)
{
if(StopLoss>0) sl=NormalizeDouble(bid+StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(bid-TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_SELL,Lot(),NormalizeDouble(bid,Digits),Slip,sl,tp,"",MAGIC,0,Red);
if(res<0)
{
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА SELL: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(1000);
//--- buy conditions
if(BuySell==0)
{
if(StopLoss>0) sl=NormalizeDouble(ask-StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(ask+TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_BUY,Lot(),NormalizeDouble(ask,Digits),Slip,sl,tp,"",MAGIC,0,Blue);
if(res<0)
{
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА BUY: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(1000);
//--- buy sell conditions
if(BuySell==2)
{
//--- sell conditions
if(LastDealType()==1 || LastDealType()==0)
{
if(StopLoss>0) sl=NormalizeDouble(bid+StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(bid-TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_SELL,Lot(),NormalizeDouble(bid,Digits),Slip,sl,tp,"",MAGIC,0,Red);
if(res<0)
{
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА SELL: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(1000);
//--- buy conditions
if(LastDealType()==2 || LastDealType()==0)
{
if(StopLoss>0) sl=NormalizeDouble(ask-StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(ask+TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_BUY,Lot(),NormalizeDouble(ask,Digits),Slip,sl,tp,"",MAGIC,0,Blue);
if(res<0)
{
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА BUY: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(1000);
}
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealType()
{
int type=0;
if(OrdersHistoryTotal()==0)
{
type=0;
}
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderType()==OP_BUY)
{
type=1;//buy
}
if(OrderType()==OP_SELL)
{
type=2;//sell
}
}
return(type);
}
//+------------------------------------------------------------------+
void CloseAll()
{
bool cl,sel;
for(int i=0; i<OrdersTotal(); i++)
{
sel=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
{
if(OrderType()==OP_BUY) cl=OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Blue);
if(OrderType()==OP_SELL) cl=OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);
}
Sleep(1000);
}
}
//+------------------------------------------------------------------+
//| Calculate optimal lot size |
//+------------------------------------------------------------------+
double Lot()
{
double lot;
if(OrdersHistoryTotal()==0)
{
lot=Lots;
}
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0)
{
lot=Lots;
k=0;
}
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
if(lot>MaxLot || lot==0) lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(k>9) k=0;
if(CountTrades()<Count) OpenOrd();
if((TimeCurrent()-StartTime)>tf[k]*60)
{
k++;
CloseAll();
StartTime=TimeCurrent();
}
Comment("\n Current Time: ",TimeToString(TimeCurrent(),TIME_SECONDS),
"\n Start Time: ",TimeToString(StartTime,TIME_SECONDS),
"\n Time Frame: ",tf[k],
"\n K: ",k,
"\n Lot: ",Lot(),
"\n Last Deal Type: ",LastDealType());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TimeOpen.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property description "Time Open expert advisor"
#include <stdlib.mqh>
//--- Inputs
extern int StopLoss = 555; // лось
extern int TakeProfit = 555; // язь
extern int BuySell = 0; // 0-бай. 1-селл. 2-бай/селл
extern double Lots = 0.1; // лот
extern int Slip = 100; // проскальзывание
extern int Count = 1; // количество открываемых ордеров
extern int MAGIC = 123; // магик
extern string t = "Время";
extern int t1 = 1; // время 1
extern int t2 = 5; // время 1
extern int t3 = 15; // время 1
extern int t4 = 30; // время 1
extern int t5 = 60; // время 1
extern int t6 = 240; // время 1
extern int t7 = 1440; // время 1
extern int t8 = 10080; // время 1
extern int t9 = 43200; // время 1
int tf[9],k=0;
datetime StartTime;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
StartTime=TimeCurrent();
tf[0]=t1;
tf[1]=t2;
tf[2]=t3;
tf[3]=t4;
tf[4]=t5;
tf[5]=t6;
tf[6]=t7;
tf[7]=t8;
tf[8]=t9;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
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()==OP_BUY || OrderType()==OP_SELL) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
void OpenOrd()
{
int res,err;
double sl,tp;
//--- sell conditions
if(BuySell==1 || BuySell==2)
{
double bid=MarketInfo(OrderSymbol(),MODE_BID);
if(StopLoss>0) sl=NormalizeDouble(bid+StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(bid-TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(bid,Digits),Slip,sl,tp,"",MAGIC,0,Red);
if(res<0)
{
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА SELL: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(1000);
//--- buy conditions
if(BuySell==0 || BuySell==2)
{
double ask=MarketInfo(OrderSymbol(),MODE_ASK);
if(StopLoss>0) sl=NormalizeDouble(ask-StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(ask+TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(ask,Digits),Slip,sl,tp,"",MAGIC,0,Blue);
if(res<0)
{
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА BUY: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(1000);
//---
}
//+------------------------------------------------------------------+
void CloseAll()
{
bool cl,sel;
for(int i=0; i<OrdersTotal(); i++)
{
sel=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC)
{
if(OrderType()==OP_BUY) cl=OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Blue);
if(OrderType()==OP_SELL) cl=OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);
}
Sleep(1000);
}
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(CountTrades()<Count) OpenOrd();
if((TimeCurrent()-StartTime)>tf[k]*60)
{
k++;
CloseAll();
StartTime=TimeCurrent();
}
Comment("\n Current Time: ",TimeToString(TimeCurrent(),TIME_SECONDS),
"\n Start Time: ",TimeToString(StartTime,TIME_SECONDS),
"\n Time Frame: ",tf[k],
"\n K: ",k);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| OpenTime.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property description "OpenTime expert advisor"
#include <stdlib.mqh>
//--- Inputs
extern int StopLoss = 555; // лось
extern int TakeProfit = 555; // язь
extern int Buy = 1; // 1-есть бай
extern int Sell = 0; // 1-есть селл
extern int Try = 5; // количество попыток выставить ордер
extern int SleepTime = 555; // пауза в миллисекундах
extern int StartHour = 9; // час начала торговли
extern int StartMin = 30; // минута начала торговли
extern int EndHour = 23; // час окончания торговли
extern int EndMin = 30; // минута окончания торговли
extern double Lots = 0.1; // лот
extern int Slip = 100; // проскальзывание
extern int Count = 5; // количество открываемых ордеров
extern int MAGIC = 123; // магик
int errors;
//+------------------------------------------------------------------+
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()==OP_BUY || OrderType()==OP_SELL) count++;
}
}
}
return(count);
}
//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 30.04.2009 |
//| Описание : Возвращает флаг разрешения торговли по времени. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| hb - часы времени начала торговли |
//| mb - минуты времени начала торговли |
//| he - часы времени окончания торговли |
//| me - минуты времени окончания торговли |
//+----------------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0,int mb=0,int he=0,int me=0)
{
datetime db, de; // Время начала и окончания работы
int hc; // Часы текущего времени торгового сервера
db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+hb+":"+mb);
de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+he+":"+me);
hc=TimeHour(TimeCurrent());
if(db>=de)
{
if(hc>=he) de+=24*60*60; else db-=24*60*60;
}
if(TimeCurrent()>=db && TimeCurrent()<=de) return(True);
else return(False);
}
//+------------------------------------------------------------------+
void OpenOrd()
{
int res,err;
double sl,tp;
//--- sell conditions
if(Sell==1)
{
if(StopLoss>0) sl=NormalizeDouble(Bid+StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(Bid-TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),Slip,sl,tp,"",MAGIC,0,Red);
if(res<0)
{
errors++;
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА SELL: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(SleepTime);
//--- buy conditions
if(Buy==1)
{
if(StopLoss>0) sl=NormalizeDouble(Ask-StopLoss*Point,Digits); else sl=0;
if(TakeProfit>0) tp=NormalizeDouble(Ask+TakeProfit*Point,Digits); else tp=0;
res=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),Slip,sl,tp,"",MAGIC,0,Blue);
if(res<0)
{
errors++;
err=GetLastError();
Print("ОШИБКА ВЫСТАВЛЕНИЯ ОРДЕРА BUY: ",err,"(",ErrorDescription(err),")");
} else {
RefreshRates();
}
return;
}
Sleep(SleepTime);
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(errors>Try) return;
if(isTradeTimeInt(StartHour,StartMin,EndHour,EndMin))
{
if(CountTrades()<Count) OpenOrd();
}
Comment("\n CountTrades: ",CountTrades(),
"\n Errors: ",errors);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| TickIndicator.mq4 |
//| Copyright 2015, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Lime
input int MAPeriod = 12;
double IndBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexBuffer(0,IndBuf);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=counted_bars;
for(int i=limit; i>=0; i--)
{
IndBuf[i+1]=IndBuf[i];
}
IndBuf[0]=(close[0]-iMA(NULL,0,MAPeriod,0,MODE_SMA,PRICE_CLOSE,0))/Point;
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
AM2