Добрый день.
В журнале очень много
Casha EURUSD,M15: OrderModify error 130
Так и должно быть?
При активации работы по времени (если не по нулям стоит) советник должен дождаться нового сигнала для совершения первой сделки, а не по текущему открывать.
//+------------------------------------------------------------------+
//| 2Mashki.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 double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int TrailingStop = 0; // трал
extern int MA1Period = 12; // период МА1
extern int MA2Period = 40; // период МА2
extern int Slip = 30; // реквот
extern int Shift = 1; // на каком баре сигнал индикатора
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Установка ордера |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0,err=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;
double MinimumLot = MarketInfo(NULL,MODE_MINLOT);
double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);
if(CountTrades()>0) lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
if(lot>MaxLot)lot=Lots;
if(lot<MinimumLot) lot=MinimumLot;
if(lot>MaximumLot) lot=MaximumLot;
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);
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
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 OpenOrd()
{
double MA11=iMA(NULL,0,MA1Period,0,0,0,Shift);
double MA12=iMA(NULL,0,MA1Period,0,0,0,Shift+1);
double MA21=iMA(NULL,0,MA2Period,0,0,0,Shift);
double MA22=iMA(NULL,0,MA2Period,0,0,0,Shift+1);
if(MA11<MA21 && MA12>MA22)
{
PutOrder(1,Bid);
}
if(MA11>MA21 && MA12<MA22)
{
PutOrder(0,Ask);
}
}
//+------------------------------------------------------------------+
//| Простой трал |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
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(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-TrailingStop*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
if(TrailingStop>0) Trailing();
OpenOrd();
if(AllProfit(0)>0) CloseAll(0);
if(AllProfit(1)>0) CloseAll(1);
if(AllProfit()>0) CloseAll();
t=Time[0];
}
Comment("\n Открыто Buy ",CountOrders(0),
"\n Открыто Sell ",CountOrders(1),
"\n Общий профит: ",AllProfit(),
"\n Профит по Buy: ",AllProfit(0),
"\n Профит по Sell: ",AllProfit(1));
}
//+------------------------------------------------------------------+
Название в эксперте поправил но вот это мне не по силам поправит, открыл не понятно почему
double blue = iCustom(NULL,0,IndName1,VP_Bars,VP_Version,VP_Alerts,VP_Channel_Alerts,Email_Signal,VP_WMA,SlowerLWMA,FasterSidusEMA,SlowerSidusEMA,0,Shift);
double red = iCustom(NULL,0,IndName1,VP_Bars,VP_Version,VP_Alerts,VP_Channel_Alerts,Email_Signal,VP_WMA,SlowerLWMA,FasterSidusEMA,SlowerSidusEMA,1,Shift);
double green=iCustom(NULL,0,IndName2,1,Shift);
double orange=iCustom(NULL,0,IndName2,2,Shift);
if(blue<1000 && green<1000)
Все в порядке. Только объясните как работает параметр Delta.
Вот это понять не могу зачем???? Он историю не смотрит, он берет только максимум и минимум за определенное время.
И он поставил ордер только в 14:15 и только в buy, последняя
//+------------------------------------------------------------------+
//| Mnogitel.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 int StopLoss = 15;
extern int TakeProfit = 60;
extern int Step = 10;
extern int Slip = 30;
extern int Magic = 123;
extern double Lots = 0.1;
extern double KLot = 5;
extern double MaxLot = 5;
double Price=0,lot=Lots;
//+------------------------------------------------------------------+
//| 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);
}
if(AccountFreeMarginCheck(Symbol(),type,lot)<=0 || GetLastError()==134)
{
Print("Недостаточно средств!!!");
}
if(GetLastError()==131)
{
Print("Неправильный объем!!!");
}
if(lot>MaxLot) lot=Lots;
r=OrderSend(NULL,type,lot,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
return(result);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(LastDealResult()>0) lot=Lots;
//--- sell conditions
if(Bid>Price+Step*Point)
{
PutOrder(0,Ask);
Price=Bid;
lot*=KLot;
}
if(Bid<Price-Step*Point)
{
PutOrder(1,Bid);
Price=Bid;
lot*=KLot;
}
Comment("\n Price: ",Price,"\n Lot: ",lot);
}
//+------------------------------------------------------------------+
AM2