
//+------------------------------------------------------------------+
//| MissMarple.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
//--- Inputs
extern string StartTime = "00:00"; // время начала торговли
extern string EndTime = "23:00"; // время окончания торговли
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int Delta = 100; // расстояние от МА
extern int Slip = 30; // реквот
extern int MAPeriod = 12; // период МА
extern int WPRPeriod = 21; // период WPR
extern int WPRLevel = 5; // уровень WPR
extern int Shift = 1; // на каком баре сигнал индикатора
extern int OnePos = 1; // 1-одна поза 0-несколько
extern int CloseSig = 0; // 1-закрытие по сигналу
extern int Magic = 123; // магик
extern bool Martin = false; // мартин
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(Martin)
{
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
if(lot>MaxLot)lot=Lots;
}
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OpenPos()
{
double ma=iMA(NULL,0,MAPeriod,0,0,0,Shift);
double wpr1=iWPR(NULL,0,WPRPeriod,Shift);
double wpr2=iWPR(NULL,0,WPRPeriod,Shift+1);
if(Ask>ma+Delta*Point && wpr1>-100+WPRLevel && wpr2<-100+WPRLevel)
{
PutOrder(0,Ask);
}
if(Bid<ma-Delta*Point && wpr2>-WPRLevel && wpr1<-WPRLevel)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double ma=iMA(NULL,0,MAPeriod,0,0,0,Shift);
double wpr1=iWPR(NULL,0,WPRPeriod,Shift);
double wpr2=iWPR(NULL,0,WPRPeriod,Shift+1);
//---
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)
{
if(wpr2>-WPRLevel && wpr1<-WPRLevel)
{
CloseAll(0);
}
}
if(OrderType()==OP_SELL)
{
if(wpr1>-100+WPRLevel && wpr2<-100+WPRLevel)
{
CloseAll(1);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
datetime End=StringToTime(EndTime);
datetime Start=StringToTime(StartTime);
if(TimeCurrent()>Start && TimeCurrent()<End)
{
if(t!=Time[0] && OnePos<1)
{
OpenPos();
t=Time[0];
}
if(CountTrades()<1 && OnePos>0) OpenPos();
if(CloseSig>0) ClosePos();
}
}
//+------------------------------------------------------------------+
а что даст это — либо?
//+------------------------------------------------------------------+
//| Libo.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
extern bool AfterTrade = true; // After profit tading
//+------------------------------------------------------------------+
//| ProfitLines.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lot = 0.1; // Trade volume
extern double KLot = 2; // Lot increase
extern double MaxLot = 5; // Maximum Lot
extern double Stop = 3000; // Stop in querency
extern double Profit = 30; // Profit in querency
extern int Slip = 3; // Slippage
extern int Magic = 123; // Magic number
extern bool AfterTrade = true; // After profit tading
bool trade=true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
PutHLine("UP",Bid+200*Point,Red);
PutHLine("DN",Bid-200*Point,Blue);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,Lots(),NormalizeDouble(price,Digits),Slip,0,0,"",Magic,0,clr);
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()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lots()
{
double lot=Lot;
if(CountTrades()>0) lot=NormalizeDouble(Lot*MathPow(KLot,CountTrades()),2);
if(lot>MaxLot)lot=Lot;
return(lot);
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=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 && (ot==0 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Горизонтальная линия |
//+------------------------------------------------------------------+
void PutHLine(string name,double p,color clr)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_HLINE,0,0,p);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
}
//+------------------------------------------------------------------+
//| Тип последней сделки |
//+------------------------------------------------------------------+
int LastDealType()
{
int type=0;
if(OrderSelect(OrdersTotal()-1,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>0)
{
type=1;//sell
}
}
}
return(type);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double up=ObjectGetDouble(0,"UP",OBJPROP_PRICE);
double dn=ObjectGetDouble(0,"DN",OBJPROP_PRICE);
if(AllProfit()>Profit || AllProfit()<-Stop || (CountTrades()>5 && AllProfit()>0))
{
CloseAll();
if(!AfterTrade) trade=false;
}
if(trade)
{
if(Ask>up && LastDealType()>0) PutOrder(0,Ask);
if(Bid<dn && LastDealType()<1) PutOrder(1,Bid);
}
Comment("\n UP: ",up,
"\n DN: ",dn,
"\n Lot: ",Lots(),
"\n Type: ",LastDealType(),
"\n Trades: ",CountTrades(),
"\n All Profit: ",NormalizeDouble(AllProfit(),2),
"\n Buy Profit: ",NormalizeDouble(AllProfit(0),2),
"\n Sell Profit: ",NormalizeDouble(AllProfit(1),2));
}
//+------------------------------------------------------------------+
AM2