//+------------------------------------------------------------------+
//| TrailingAll.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 TrailingStop = 200; // трал
extern int TrailingStart = 300; // старт трала
//+------------------------------------------------------------------+
//| 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=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
}
r=OrderSend(NULL,type,0.1,NormalizeDouble(price,Digits),0,0,0,"",0,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double All()
{
double p=0,n=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()<2)
{
p+=OrderOpenPrice();
n++;
}
}
}
}
if(n>0)p/=n;
return(p);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void TrailingAlls(int Start,int stop,double AvgPrice)
{
bool m;
double profit;
double stoptrade;
double stopcal;
if(stop==0) return;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
{
profit=NormalizeDouble((Bid-AvgPrice)/Point,0);
if(profit<Start)
continue;
stoptrade=OrderStopLoss();
stopcal=Bid-(stop*Point);
if(stoptrade==0 || (stoptrade!=0 && stopcal>stoptrade))
m=OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
}
if(OrderType()==OP_SELL)
{
profit=NormalizeDouble((AvgPrice-Ask)/Point,0);
if(profit<Start)
continue;
stoptrade=OrderStopLoss();
stopcal=Ask+(stop*Point);
if(stoptrade==0 || (stoptrade!=0 && stopcal<stoptrade))
m=OrderModify(OrderTicket(),AvgPrice,stopcal,OrderTakeProfit(),0,Red);
}
}
Sleep(1000);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TrailingStop>0) TrailingAlls(TrailingStart,TrailingStop,All());
if(OrdersTotal()<1 && IsTesting())
{
for(int i=1; i<=5;i++)
{
{
PutOrder(2,Bid-200*Point*i);//buylimit
}
}
}
Comment("\n All: ",All());
}
//+------------------------------------------------------------------+
for(int i=1;i<=Days;i++)
{
delta+=(iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i));
}
delta=(delta/Days/Koef)/Point;
//+------------------------------------------------------------------+
//| Grid.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
#property indicator_chart_window
input int Step=55; // шаг между линиями
input int Count=5; // число линий
input int Days=5; // дней для расчета
input int Koef=1; // делитель волатильности
input bool D=false; // флаг расчета по дням
input color ColorSup=Red; // цвет сопротивления
input color ColorRes=Blue; // цвет поддержки
input double Price=1.124; // точка отсчета
bool Put=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
ObjectsDeleteAll(0,0,OBJ_HLINE);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
ObjectsDeleteAll(0,0,OBJ_HLINE);
}
//+------------------------------------------------------------------+
//| Горизонтальная линия |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
double delta=0,pr1=0,pr2=0;
for(int i=1;i<=Days;i++)
{
delta+=(iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i));
}
delta=(delta/Days/Koef)/Point;
if(Put)
{
for(int i=1;i<=Count;i++)
{
if(D)
{
pr1=NormalizeDouble(Price+delta*Point*i,Digits);
PutHLine("Supp Line: "+(string)pr1,pr1,ColorSup);
pr2=NormalizeDouble(Price-delta*Point*i,Digits);
PutHLine("Res Line: "+(string)pr2,pr2,ColorRes);
Put=false;
}
if(D==false)
{
pr1=NormalizeDouble(Price+Step*Point*i,Digits);
PutHLine("Supp Line: "+(string)pr1,pr1,ColorSup);
pr2=NormalizeDouble(Price-Step*Point*i,Digits);
PutHLine("Res Line: "+(string)pr2,pr2,ColorRes);
Put=false;
}
}
}
Comment("\n Delta: ",NormalizeDouble(delta,0));
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
У меня лот привязан к величине депозита, и даже при тестировании с января 13 года лот начинает превышать допустимый для брокера и ордера уже не открываются. Можно конечно попробовать со статическим лотом.
double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);
lot=...;
if(lot>MaximumLot) lot=MaximumLot;
for(int i=1; i<=Count;i++)
{
{
PutOrder(4,Bid+Delta*Point+Step*Point*i);//buystop
PutOrder(5,Bid-Delta*Point-Step*Point*i);//sellstop
}
}
• Если стоповый ордер был активирован и достиг своего T.P. — рыночный должен быть закрыт по текущей цене (до следующего дня советник ничего не делает)
• Если в случае активации стопового ордера цена достигла T.P. рыночного ордера раньше чем стопового, стоповый ордер должен быть закрыт по текущей цене (до следующего дня советник ничего не делает)
//+------------------------------------------------------------------+
//| Delta.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 Lot1 = 0.1; // лот 1
extern double Lot2 = 0.1; // лот 2
extern int StopLoss1 = 200; // лось 1
extern int StopLoss2 = 200; // лось 2
extern int TakeProfit1 = 300; // язь 1
extern int TakeProfit2 = 300; // язь 2
extern int StartHour = 0; // час начала торговли
extern int Slip = 30; // реквот
extern int Shift = 1; // начальный бар
extern int Count = 9; // конечный бар
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot=0.1,double sl=0,double tp=0)
{
int r=0;
color clr=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(sl>0) sl=NormalizeDouble(price+sl*Point,Digits);
if(tp>0) tp=NormalizeDouble(price-tp*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(sl>0) sl=NormalizeDouble(price-sl*Point,Digits);
if(tp>0) tp=NormalizeDouble(price+tp*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 DelOrder()
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| Одна сделка в день |
//+------------------------------------------------------------------+
bool OneDayDeal()
{
bool result=true;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<6 && TimeDay(OrderOpenTime())==Day())
{
result=false;//tp
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int high=iHighest(NULL,0,MODE_HIGH,Count,Shift);
int low=iLowest(NULL,0,MODE_LOW,Count,Shift);
double h=High[high];
double l=Low[low];
if(TimeCurrent()>=StringToTime((string)StartHour+":00") && OrdersTotal()<1 && OneDayDeal())
{
if(Close[Shift]>Close[Count])
{
PutOrder(0,Ask,Lot1,StopLoss1,TakeProfit1);
PutOrder(5,l,Lot2,StopLoss2,TakeProfit2);
}
if(Close[Shift]<Close[Count])
{
PutOrder(1,Bid,Lot1,StopLoss1,TakeProfit1);
PutOrder(4,h,Lot2,StopLoss2,TakeProfit2);
}
}
if(CountTrades()<1) DelOrder();
}
//+------------------------------------------------------------------+
Уважаемый Андрей переделайте заказ zakaz.opentraders.ru/30345.html
AM2