//+------------------------------------------------------------------+//| Check for long position opening |//+------------------------------------------------------------------+bool CSampleExpert::LongOpened_1(void)
{
bool res=false;
//--- check for long position (BUY) possibilityif(m_macd_current_1<m_signal_current_1)
{
InpTradeCommand(InpLongOpened_1Command);
//--- in any case we must exit from expert
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for short position opening |//+------------------------------------------------------------------+bool CSampleExpert::ShortOpened_1(void)
{
bool res=false;
//--- check for short position (SELL) possibilityif(m_macd_current_1>m_signal_current_1)
{
InpTradeCommand(InpShortOpened_1Command);
//--- in any case we must exit from expert
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+//| main function returns true if any position processed |//+------------------------------------------------------------------+bool CSampleExpert::Processing_1(void)
{
//--- we work only at the time of the birth of new bardatetime time_0=iTime(m_symbol.Name(),Period_1,0);
if(time_0==ExtPrevBars_1)
return(false);
ExtPrevBars_1=time_0;
if(!m_symbol.RefreshRates())
{
ExtPrevBars_1=0;
return(false);
}
//--- refresh indicatorsif(BarsCalculated(m_handle_macd_1)<2)
return(false);
if(CopyBuffer(m_handle_macd_1,0,InpBars_1,2,m_buff_MACD_main_1) !=2 ||
CopyBuffer(m_handle_macd_1,1,InpBars_1,2,m_buff_MACD_signal_1)!=2)
{
ExtPrevBars_1=0;
return(false);
}
// m_indicators.Refresh();//--- to simplify the coding and speed up access//--- data are put into internal variables
m_macd_current_1 =m_buff_MACD_main_1[0];
m_signal_current_1 =m_buff_MACD_signal_1[0];
//--- check for long position (BUY) possibilityif(LongOpened_1())
return(true);
//--- check for short position (SELL) possibilityif(ShortOpened_1())
return(true);
//--- exit without position processingreturn(false);
}
//+------------------------------------------------------------------+
ИТОГ : Индикатора "Back and forth ADX" Март Апрель - не удачный почему то
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
вот сам Индикатор
Вот Эксперт шустро работает в тестере - проверять Сигнальные Индикаторы
//+------------------------------------------------------------------+//| Back and forth ADX.mq5 |//| Copyright 2021, MetaQuotes Ltd. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2021, MetaQuotes Software Corp."#property link"http://www.mql5.com"#property version"1.00"#define MACD_MAGIC 9294501//---#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---inputdouble InpLots = 0.01; // Lotsinputint InpTakeProfit = 500; // Take Profit (in pips)inputint InpTrailingStop = 300; // Trailing Stop Level (in pips)sinput group "----------------- Indicators: -----------------------"inputstring Inp_name_1 = "Back and forth ADX"; // Name Indicatorsinputint InpBars_1 = 1; // Bars//---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_macd; // MACD indicator handle//--- indicator buffersdouble m_buff_MACD_main[]; // MACD indicator main bufferdouble m_buff_MACD_signal[]; // MACD indicator signal buffer//--- indicator data for processingdouble m_macd_current;
double m_signal_current;
//---double m_traling_stop;
double m_take_profit;
public:
CSampleExpert(void);
~CSampleExpert(void);
bool Init(void);
void Deinit(void);
bool Processing(void);
protected:
bool InitCheckParameters(constint digits_adjust);
bool InitIndicators(void);
bool LongClosed(void);
bool ShortClosed(void);
bool LongModified(void);
bool ShortModified(void);
bool LongOpened(void);
bool ShortOpened(void);
};
//--- global expert
CSampleExpert ExtExpert;
//+------------------------------------------------------------------+//| Constructor |//+------------------------------------------------------------------+
CSampleExpert::CSampleExpert(void) : m_adjusted_point(0),
m_handle_macd(INVALID_HANDLE),
m_macd_current(0),
m_signal_current(0),
m_traling_stop(0),
m_take_profit(0)
{
ArraySetAsSeries(m_buff_MACD_main,true);
ArraySetAsSeries(m_buff_MACD_signal,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(Symbol());
//--- 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_traling_stop =InpTrailingStop*m_adjusted_point;
m_take_profit =InpTakeProfit*m_adjusted_point;
//--- set default deviation for trading in adjusted points
m_trade.SetDeviationInPoints(3*digits_adjust);
//---if(!InitCheckParameters(digits_adjust))
return(false);
if(!InitIndicators())
return(false);
//--- succeedreturn(true);
}
//+------------------------------------------------------------------+//| Checking for input parameters |//+------------------------------------------------------------------+bool CSampleExpert::InitCheckParameters(constint digits_adjust)
{
//--- initial data checksif(InpTakeProfit*digits_adjust<m_symbol.StopsLevel())
{
printf("Take Profit must be greater than %d",m_symbol.StopsLevel());
return(false);
}
if(InpTrailingStop*digits_adjust<m_symbol.StopsLevel())
{
printf("Trailing Stop must be greater than %d",m_symbol.StopsLevel());
return(false);
}
//--- check for right lots amountif(InpLots<m_symbol.LotsMin() || InpLots>m_symbol.LotsMax())
{
printf("Lots amount must be in the range from %f to %f",m_symbol.LotsMin(),m_symbol.LotsMax());
return(false);
}
if(MathAbs(InpLots/m_symbol.LotsStep()-MathRound(InpLots/m_symbol.LotsStep()))>1.0E-10)
{
printf("Lots amount is not corresponding with lot step %f",m_symbol.LotsStep());
return(false);
}
//--- warningif(InpTakeProfit<=InpTrailingStop)
printf("Warning: Trailing Stop must be less than Take Profit");
//--- succeedreturn(true);
}
//+------------------------------------------------------------------+//| Initialization of the indicators |//+------------------------------------------------------------------+bool CSampleExpert::InitIndicators(void)
{
//--- create MACD indicatorif(m_handle_macd==INVALID_HANDLE)
if((m_handle_macd=iCustom(_Symbol,_Period,Inp_name_1))==INVALID_HANDLE)
{
printf("Error creating MACD indicator");
return(false);
}
//--- succeedreturn(true);
}
//+------------------------------------------------------------------+//| Check for long position closing |//+------------------------------------------------------------------+bool CSampleExpert::LongClosed(void)
{
bool res=false;
//--- should it be closed?if(m_macd_current>m_signal_current)
{
//--- close positionif(m_trade.PositionClose(Symbol()))
printf("Long position by %s to be closed",Symbol());
elseprintf("Error closing position by %s : '%s'",Symbol(),m_trade.ResultComment());
//--- processed and cannot be modified
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for short position closing |//+------------------------------------------------------------------+bool CSampleExpert::ShortClosed(void)
{
bool res=false;
//--- should it be closed?if(m_macd_current<m_signal_current)
{
//--- close positionif(m_trade.PositionClose(Symbol()))
printf("Short position by %s to be closed",Symbol());
elseprintf("Error closing position by %s : '%s'",Symbol(),m_trade.ResultComment());
//--- processed and cannot be modified
res=true;
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for long position modifying |//+------------------------------------------------------------------+bool CSampleExpert::LongModified(void)
{
bool res=false;
//--- check for trailing stopif(InpTrailingStop>0)
{
if(m_symbol.Bid()-m_position.PriceOpen()>m_adjusted_point*InpTrailingStop)
{
double sl=NormalizeDouble(m_symbol.Bid()-m_traling_stop,m_symbol.Digits());
double tp=m_position.TakeProfit();
if(m_position.StopLoss()<sl || m_position.StopLoss()==0.0)
{
//--- modify positionif(m_trade.PositionModify(Symbol(),sl,tp))
printf("Long position by %s to be modified",Symbol());
else
{
printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment());
printf("Modify parameters : SL=%f,TP=%f",sl,tp);
}
//--- modified and must exit from expert
res=true;
}
}
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for short position modifying |//+------------------------------------------------------------------+bool CSampleExpert::ShortModified(void)
{
bool res=false;
//--- check for trailing stopif(InpTrailingStop>0)
{
if((m_position.PriceOpen()-m_symbol.Ask())>(m_adjusted_point*InpTrailingStop))
{
double sl=NormalizeDouble(m_symbol.Ask()+m_traling_stop,m_symbol.Digits());
double tp=m_position.TakeProfit();
if(m_position.StopLoss()>sl || m_position.StopLoss()==0.0)
{
//--- modify positionif(m_trade.PositionModify(Symbol(),sl,tp))
printf("Short position by %s to be modified",Symbol());
else
{
printf("Error modifying position by %s : '%s'",Symbol(),m_trade.ResultComment());
printf("Modify parameters : SL=%f,TP=%f",sl,tp);
}
//--- modified and must exit from expert
res=true;
}
}
}
//--- resultreturn(res);
}
//+------------------------------------------------------------------+//| Check for long position opening |//+------------------------------------------------------------------+bool CSampleExpert::LongOpened(void)
{
bool res=false;
//--- check for long position (BUY) possibilityif(m_macd_current<m_signal_current)
{
double price=m_symbol.Ask();
double tp =m_symbol.Bid()+m_take_profit;
//--- check for free moneyif(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_BUY,InpLots,price)<0.0)
printf("We have no money. Free Margin = %f",m_account.FreeMargin());
else
{
//--- open positionif(m_trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,InpLots,price,0.0,tp))
printf("Position by %s to be opened",Symbol());
else
{
printf("Error opening BUY position by %s : '%s'",Symbol(),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 short position opening |//+------------------------------------------------------------------+bool CSampleExpert::ShortOpened(void)
{
bool res=false;
//--- check for short position (SELL) possibilityif(m_macd_current>m_signal_current)
{
double price=m_symbol.Bid();
double tp =m_symbol.Ask()-m_take_profit;
//--- check for free moneyif(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_SELL,InpLots,price)<0.0)
printf("We have no money. Free Margin = %f",m_account.FreeMargin());
else
{
//--- open positionif(m_trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,InpLots,price,0.0,tp))
printf("Position by %s to be opened",Symbol());
else
{
printf("Error opening SELL position by %s : '%s'",Symbol(),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_macd)<2)
return(false);
if(CopyBuffer(m_handle_macd,0,InpBars_1,2,m_buff_MACD_main) !=2 ||
CopyBuffer(m_handle_macd,1,InpBars_1,2,m_buff_MACD_signal)!=2)
return(false);
// m_indicators.Refresh();//--- to simplify the coding and speed up access//--- data are put into internal variables
m_macd_current =m_buff_MACD_main[0];
m_signal_current =m_buff_MACD_signal[0];
//--- 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 itif(m_position.Select(Symbol()))
{
if(m_position.PositionType()==POSITION_TYPE_BUY)
{
//--- try to close or modify long positionif(LongClosed())
return(true);
if(LongModified())
return(true);
}
else
{
//--- try to close or modify short positionif(ShortClosed())
return(true);
if(ShortModified())
return(true);
}
}
//--- no opened position identifiedelse
{
//--- check for long position (BUY) possibilityif(LongOpened())
return(true);
//--- check for short position (SELL) possibilityif(ShortOpened())
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)
{
//--- change limit time by timeout in seconds if processedif(ExtExpert.Processing())
limit_time=TimeCurrent()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+
я без понятия - слепил как есть! я же самоучка всё методом научного тыканья
\\\\\\\\\\\\\ сам удивляюсь - он ещё и результат вроде не плохой показывает - эксперт у меня тяжёлый - долго тестирует
у вас совсем другой сигнал
в оригинале крест линий плюс и минус
у вас еще и основная линия в сигнале
у вас совсем другой сигнал
в оригинале крест линий плюс и минус
у вас еще и основная линия в сигнале
да! я три линии задействовал минусовая(розовая) она как нулевая - а те две, пересекают её и дают сигнал
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
март месяц погнал вниз ---------- вот это я эксперта за-бацал я этот тест наверное к новому году закончу.(только пол пути прошла)
да! я три линии задействовал минусовая(розовая) она как нулевая - а те две, пересекают её и дают сигнал
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
март месяц погнал вниз ---------- вот это я эксперта за-бацал я этот тест наверное к новому году закончу.(только пол пути прошла)
если сов использует кастомный индикатор
то нужно просто сигнал перенести в советник
и не использовать индикатор
Я извиняюсь а по моей просьбе по индикатору adx-buy-sell сделаете советник?
если он у вас сигнальный индикатор - то можно вот этот эксперт (мт4) использовать https://www.mql5.com/ru/forum/310846/page63#comment_17088893
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
где жёлтым мечено - впишите имя вашего Индикатора
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
если использовать крест, без будущего, то там прибыли нет
если сов использует кастомный индикатор
то нужно просто сигнал перенести в советник
и не использовать индикатор
У меня тяжёлый эксперт от того что в нём много функции от Горизонтальных и Трендовых линии.
вот он https://www.mql5.com/ru/code/34046
сама функция - работы от Индикатора вот
если использовать крест, без будущего, то там прибыли нет
у меня всё же, другой результат выйдет - ещё немного осталось до конца теста
ИТОГ : Индикатора "Back and forth ADX" Март Апрель - не удачный почему то
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
вот сам Индикатор
ИТОГ : Индикатора "Back and forth ADX" Март Апрель - не удачный почему то
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
вот сам Индикатор
Вот Эксперт шустро работает в тестере - проверять Сигнальные Индикаторы
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ИСПРАВИЛ - НЕ ДОПИСАЛ ВОТ ТУТ