Доделка в следующем месяце?
давайте сделаем.свечка 25 и выше… бай или сел в зависимости от направления движения… ниже или выше опен уходит это стопом считается.
код, опробовал — работает, но как то не так, как бы хотелось, пока пробую сам разобраться. Стесняется открывать больше одной позиции, много ложных входов и закрытий
1. вместо значений типа ордеров используйте их именованные константы
2. в настройки добавить рабочий ТФ, иначе при переключении ТФ советник будет работать уже по другому тф.
//+------------------------------------------------------------------+
//| FL.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 BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 300; // трал
extern int Slip = 30; // реквот
extern int Shift = 1; // сдвиг
extern int Magic = 123; // магик
extern string IndName = "FL01";
//+------------------------------------------------------------------+
//| 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;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 up = iCustom(NULL,0,IndName,1,Shift);
double dn = iCustom(NULL,0,IndName,2,Shift);
if(Open[1]<dn && Close[1]>dn)
{
PutOrder(0,Ask);
}
if(Open[1]>up && Close[1]<up)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double up = iCustom(NULL,0,IndName,1,Shift);
double dn = iCustom(NULL,0,IndName,2,Shift);
//---
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(Open[1]>up && Close[1]<up)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,Slip,White))
Print("OrderClose error ",GetLastError());
}
}
if(OrderType()==OP_SELL)
{
if(Open[1]<dn && Close[1]>dn)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,Slip,White))
Print("OrderClose error ",GetLastError());
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=0; i<OrdersTotal(); 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 BU()
{
bool m;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && OrderOpenPrice()<OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double up = iCustom(NULL,0,IndName,1,Shift);
double dn = iCustom(NULL,0,IndName,2,Shift);
if(CountTrades()<1)
{
OpenPos();
}
else ClosePos();
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
Comment("\n UP: ",up,
"\n DN: ",dn);
}
//+------------------------------------------------------------------+
кстате да… советник ваще будет тема на таком. именно пипсовщик.))
extern double Profit1 = 10; // профит в валюте 1-го ордера
AM2