inputstring t10="----- Trend Line Name ------"; // Trend Line Nameinputstring InpNameAverage = "AVERAGE 0"; // Trend Line Nameinputstring InpNameAverage0 = "TOP 0"; // Trend Line Nameinputstring InpNameAverage1 = "LOWER 0"; // Trend Line Name
//---inputdouble InpLots = 0.1; // Lotsinputint InpTakeProfit = 50; // Take Profit (in pips)inputstring t0="----- Trend Line Name ------";// Trend Line Nameinputstring InpNameAverage = "AVERAGE 0"; // Trend Line Nameinputstring InpNameAverage0 = "TOP 0"; // Trend Line Nameinputstring InpNameAverage1 = "LOWER 0"; // Trend Line Name//---
//+------------------------------------------------------------------+//| MACD Sample.mq5 |//| Copyright 2009-2017, MetaQuotes Software Corp. |//| http://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2009-2017, MetaQuotes Software Corp."#property link"http://www.mql5.com"#property version"5.50"#property description"It is important to make sure that the expert works with a normal"#property description"chart and the user did not make any mistakes setting input"#property description"variables (Lots, TakeProfit, TrailingStop) in our case,"#property description"we check TakeProfit on a chart of more than 2*trend_period bars"#define MACD_MAGIC 1234502//---#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---inputdouble InpLots = 0.1; // Lotsinputint InpTakeProfit = 50; // Take Profit (in pips)inputstring t0="----- Trend Line Name ------";// Trend Line Nameinputstring InpNameAverage = "AVERAGE 0"; // Trend Line Nameinputstring InpNameAverage0 = "TOP 0"; // Trend Line Nameinputstring InpNameAverage1 = "LOWER 0"; // Trend Line Name//---datetime ExtLastINAverage = 0; // "0" -> D'1970.01.01 00:00';datetime ExtLastINAverage0 = 0; // "0" -> D'1970.01.01 00:00';datetime ExtLastINAverage1 = 0; // "0" -> D'1970.01.01 00:00';datetime ExtPrevBars = 0; // "0" -> D'1970.01.01 00:00';//---int ExtTimeOut=10; // time out in seconds between trade operations//+------------------------------------------------------------------+//| MACD Sample expert class |//+------------------------------------------------------------------+class CSampleExpert
{
protected:
double m_adjusted_point; // point value adjusted for 3 or 5 points
CTrade m_trade; // trading object
CSymbolInfo m_symbol; // symbol info object
CPositionInfo m_position; // trade position object
CAccountInfo m_account; // account info wrapper//--- indicatorsint m_handle_ema; // moving average indicator handle//--- indicator buffersdouble m_buff_EMA[]; // EMA indicator buffer//--- indicator data for processingdouble m_ema_current;
double m_ema_previous;
//---double m_take_profit;
public:
CSampleExpert(void);
~CSampleExpert(void);
bool Init(void);
void Deinit(void);
bool Processing(void);
protected:
bool InitIndicators(void);
bool TrendOpened(void);
bool TrendOpened0(void);
bool TrendOpened1(void);
};
//--- global expert
CSampleExpert ExtExpert;
//+------------------------------------------------------------------+//| Constructor |//+------------------------------------------------------------------+
CSampleExpert::CSampleExpert(void) : m_adjusted_point(0),
m_handle_ema(INVALID_HANDLE),
m_ema_current(0),
m_ema_previous(0),
m_take_profit(0)
{
ArraySetAsSeries(m_buff_EMA,true);
}
//+------------------------------------------------------------------+//| Destructor |//+------------------------------------------------------------------+
CSampleExpert::~CSampleExpert(void)
{
}
//+------------------------------------------------------------------+//| Initialization and checking for input parameters |//+------------------------------------------------------------------+bool CSampleExpert::Init(void)
{
//--- initialize common information
m_symbol.Name(Symbol()); // symbol
m_trade.SetExpertMagicNumber(MACD_MAGIC); // magic
m_trade.SetMarginMode();
m_trade.SetTypeFillingBySymbol(m_symbol.Name());
//--- tuning for 3 or 5 digitsint digits_adjust=1;
if(m_symbol.Digits()==3 || m_symbol.Digits()==5)
digits_adjust=10;
m_adjusted_point=m_symbol.Point()*digits_adjust;
//--- set default deviation for trading in adjusted points
m_take_profit =InpTakeProfit*m_adjusted_point;
//--- set default deviation for trading in adjusted points
m_trade.SetDeviationInPoints(3*digits_adjust);
//---if(!InitIndicators())
return(false);
//--- succeedreturn(true);
}
//+------------------------------------------------------------------+//| Initialization of the indicators |//+------------------------------------------------------------------+bool CSampleExpert::InitIndicators(void)
{
//--- create EMA indicator and add it to collectionif(m_handle_ema==INVALID_HANDLE)
if((m_handle_ema=iCustom(m_symbol.Name(),Period(),"2 Obj Volatility_StepChannel"))==INVALID_HANDLE)
{
printf("Error creating EMA indicator");
return(false);
}
//--- succeedreturn(true);
}
//+------------------------------------------------------------------+//| Check for long position opening |//+------------------------------------------------------------------+bool CSampleExpert::TrendOpened(void)
{
bool res=false;
//--- check for long position (BUY) possibilityif(ObjectFind(0,InpNameAverage)<0)
return(true);
MqlRates ratesAverage[];
ArraySetAsSeries(ratesAverage,true);
int start_pos=0,count=3;
if(CopyRates(m_symbol.Name(),Period(),start_pos,count,ratesAverage)!=count)
return(false);
if(ratesAverage[0].time==ExtLastINAverage)
return(true);
double value_by_time=ObjectGetValueByTime(0,InpNameAverage,ratesAverage[1].time);
if(value_by_time==0.0)
return(true);
if(ratesAverage[1].open<value_by_time && ratesAverage[1].close>value_by_time)
{
double price=m_symbol.Ask();
double tp =m_symbol.Bid()+m_take_profit;
//--- open positionif(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,price,0.0,tp))
printf("Position by %s to be opened",m_symbol.Name());
else
{
printf("Error opening BUY position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
printf("Open parameters : price=%f,TP=%f",price,tp);
}
res=true;
}
if(ratesAverage[1].open>value_by_time && ratesAverage[1].close<value_by_time)
{
double price=m_symbol.Bid();
double tp =m_symbol.Ask()-m_take_profit;
if(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_SELL,InpLots,price,0.0,tp))
printf("Position by %s to be opened",m_symbol.Name());
else
{
printf("Error opening SELL position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
printf("Open parameters : price=%f,TP=%f",price,tp);
} //--- in any case we must exit from expert
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for long position opening |//+------------------------------------------------------------------+bool CSampleExpert::TrendOpened0(void)
{
bool res=false;
//--- check for long position (BUY) possibilityif(ObjectFind(0,InpNameAverage0)<0)
return(true);
MqlRates ratesAverage[];
ArraySetAsSeries(ratesAverage,true);
int start_pos=0,count=3;
if(CopyRates(m_symbol.Name(),Period(),start_pos,count,ratesAverage)!=count)
return(false);
if(ratesAverage[0].time==ExtLastINAverage0)
return(true);
double value_by_time=ObjectGetValueByTime(0,InpNameAverage0,ratesAverage[1].time);
if(value_by_time==0.0)
return(true);
if(ratesAverage[1].open<value_by_time && ratesAverage[1].close>value_by_time)
{
double price=m_symbol.Ask();
double tp =m_symbol.Bid()+m_take_profit;
//--- open positionif(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_BUY,InpLots,price,0.0,tp))
printf("Position by %s to be opened",m_symbol.Name());
else
{
printf("Error opening BUY position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
printf("Open parameters : price=%f,TP=%f",price,tp);
}
res=true;
}
if(ratesAverage[1].open>value_by_time && ratesAverage[1].close<value_by_time)
{
double price=m_symbol.Bid();
double tp =m_symbol.Ask()-m_take_profit;
if(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_SELL,InpLots,price,0.0,tp))
printf("Position by %s to be opened",m_symbol.Name());
else
{
printf("Error opening SELL position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
printf("Open parameters : price=%f,TP=%f",price,tp);
} //--- in any case we must exit from expert
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for long position opening |//+------------------------------------------------------------------+bool CSampleExpert::TrendOpened1(void)
{
bool res=false;
//--- check for long position (BUY) possibilityif(ObjectFind(0,InpNameAverage1)<0)
return(true);
MqlRates ratesAverage[];
ArraySetAsSeries(ratesAverage,true);
int start_pos=0,count=3;
if(CopyRates(m_symbol.Name(),Period(),start_pos,count,ratesAverage)!=count)
return(false);
if(ratesAverage[0].time==ExtLastINAverage1)
return(true);
double value_by_time=ObjectGetValueByTime(0,InpNameAverage1,ratesAverage[1].time);
if(value_by_time==0.0)
return(true);
if(ratesAverage[1].open<value_by_time && ratesAverage[1].close>value_by_time)
{
double price=m_symbol.Ask();
double tp =m_symbol.Bid()+m_take_profit;
//--- open positionif(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_BUY,InpLots,price,0.0,tp))
printf("Position by %s to be opened",m_symbol.Name());
else
{
printf("Error opening BUY position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
printf("Open parameters : price=%f,TP=%f",price,tp);
}
res=true;
}
if(ratesAverage[1].open>value_by_time && ratesAverage[1].close<value_by_time)
{
double price=m_symbol.Bid();
double tp =m_symbol.Ask()-m_take_profit;
if(m_trade.PositionOpen(m_symbol.Name(),ORDER_TYPE_SELL,InpLots,price,0.0,tp))
printf("Position by %s to be opened",m_symbol.Name());
else
{
printf("Error opening SELL position by %s : '%s'",m_symbol.Name(),m_trade.ResultComment());
printf("Open parameters : price=%f,TP=%f",price,tp);
} //--- in any case we must exit from expert
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| main function returns true if any position processed |//+------------------------------------------------------------------+bool CSampleExpert::Processing(void)
{
//--- refresh ratesif(!m_symbol.RefreshRates())
return(false);
//--- refresh indicatorsif(BarsCalculated(m_handle_ema)<2)
return(false);
if(CopyBuffer(m_handle_ema,0,0,2,m_buff_EMA)!=2)
return(false);
// m_indicators.Refresh();//--- to simplify the coding and speed up access//--- data are put into internal variables
m_ema_current =m_buff_EMA[0];
m_ema_previous =m_buff_EMA[1];
//--- it is important to enter the market correctly,//--- but it is more important to exit it correctly...//--- first check if position exists - try to select it//--- no opened position identified//--- no opened position identifieddatetime time_0=iTime(m_symbol.Name(),Period(),0);
if(time_0==ExtPrevBars)
return(true);
ExtPrevBars=time_0;
{
//--- try to close or modify long positionif(TrendOpened()||TrendOpened0()||TrendOpened1())
return(true);
}
//--- exit without position processingreturn(false);
}
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit(void)
{
//--- create all necessary objectsif(!ExtExpert.Init())
return(INIT_FAILED);
//--- secceedreturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert new tick handling function |//+------------------------------------------------------------------+voidOnTick(void)
{
staticdatetime limit_time=0; // last trade processing time + timeout//--- don't process if timeoutif(TimeCurrent()>=limit_time)
{
//--- check for dataif(Bars(Symbol(),Period())>2*0)
{
//--- change limit time by timeout in seconds if processedif(ExtExpert.Processing())
limit_time=TimeCurrent()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+
При создании графического объекта функцией ObjectCreate() необходимо указать тип создаваемого объекта, который может принимать одно из значений перечисления ENUM_OBJECT. Дальнейшие уточнения свойств созданного объекта возможно с помощью функций по работе с графическими объектами.
inputuint maxLimits = 1; // Кол-во Позиции Открыть в одну сторонуinputdouble InpLots = 0.1; // Lotsinputint InpTakeProfit = 50; // Take Profit (in pips)
Индикатор рисует уровни Pivot, промежуточные уровни Pivot и уровни Camarilla. Уровни могут отображаться индикаторными буферами (по всей истории) и/или только текущие уровни горизонтальными линиями. DayStartHour - Час времени начала дня. DayStartMinute - Минуты времени начала дня. PivotsBufers - Отображать уровни Pivot индикаторными буферами...
我将为专家顾问添加另一个功能
有时有必要不立即触发线,而是在它越过栏杆并稳定下来后再触发。
https://www.mql5.com/ru/forum/310846/page9#comment_11404620
https://www.mql5.com/ru/code/25309
我将为专家顾问添加另一个功能
有时有必要不立即触发线,但当它已经越过并固定住条状物时
https://www.mql5.com/ru/forum/310846/page9#comment_11404620
https://www.mql5.com/ru/code/25309
有点被骗了
从趋势线来看--如果它越过了,并且条形图保持在那里,信号就会消失。
另一个指标作弊 - 上下水平线,中间趋势线
示范版--与本指标结合使用的方式
如果绿线和蓝线一起走,就会很好。
另一个版本用于测试
现在指标中有三条趋势线,专家顾问从这三条趋势线开始建仓。
另一个版本用于测试
现在指标中有三条趋势线,专家顾问从这三条趋势线开始建仓
这里有一个版本--我是怎么做的--它完全是根据你手动画的趋势线 工作的。
的设置--它有
这是版本--我是如何做到的--从你手动绘制的趋势线 来看,它是完全可以操作的。
它所拥有的设置。
没有办法!--设置它--没有经纪人会让你注册。
这是版本--我是怎么做的--从你手动绘制的趋势线 来看,它是完全可以操作的。
它所拥有的设置。
看起来是个好指标
没有设置的专家 - 给出该指标的结果2 Obj Volatility_StepChannel.mq5
增加,位置数,向一侧开放
增加,位置数,向一侧开放
从平均趋势线添加 - 当打开时,它画出一条水平线,它在价格后面移动,从它可以设置一个命令
还有一些调整
从中间趋势线添加 - 当打开时,它画了一条水平线,在价格后面移动,可以从它指挥
还有一点调整
我还添加了一些选项--从趋势线上有一个选项可以在给定的距离上画水平线。
以避免水平线跳出 - 应设置为零
还有几个选项--从趋势线上有一个选项可以在给定的距离上放下水平线
以防止水平线掉落 - 应设置为零
水平线的另一个选项
来测试 - 你需要这个指标https://www.mql5.com/ru/code/1114