How I assemble my advisor by trial and error - page 46

 

Indicator has 4 horizontal lines - 2 of them working from the indicator Heiken_Ashi

2 levels from which you can buy or sell. When they cross red, you get one signal -when they cross blue, you get another signal

EURJPYM1

-------------

when is in the middle (between the lines (red and blue) signals do not work - will work, as will come out to either side

Files:
LN_2.mq5  22 kb
 
Alexsandr San:

The indicator has 4 horizontal lines - 2 of them working from the indicator Heiken_Ashi

2 levels from which you can buy or sell. When they cross red, you get one signal -when they cross blue, you get another signal

-------------

when located in the middle (between the lines (red and blue) signals do not work - will work, as going in either direction

I have attached the Expert Advisor to this Indicator

You need to install the Indicator on the chart, then install the Expert Advisor on the same chart

---------------------

after a position was opened the indicator was deleted. after a while I set the indicator again (how to check the work of the Expert)

---------------

when a signal triggers, opens a position and deletes the indicator together with lines


Files:
Exp_LN_2.mq5  20 kb
 

Combined two experts for manual trading

this onehttps://www.mql5.com/ru/code/24803

and this onehttps://www.mql5.com/ru/code/26353

AutoClose Line
AutoClose Line
  • www.mql5.com
Помощник закрытия позиции, если цена пересекла линию: Правило закрытия: цена Open и цена Close текущего бара должны оказаться по разные стороны от линии. Имя линии задаётся в параметре "Line name" - эту линию пользователь проводит сам. Тип линии может быть...
Files:
 
Alexsandr San:

Combined two experts for manual trading

this onehttps://www.mql5.com/ru/code/24803

and this onehttps://www.mql5.com/ru/code/26353

Added another line

//+------------------------------------------------------------------+
//| Enum Lor or Risk                                                 |
//+------------------------------------------------------------------+
enum ENUM_TRADE_COMMAND
  {
   close_buys=0,     // Close All Buy's
   close_sells=1,    // Close All Sell's
   close_all=2,      // Close All Buy's and Sell's
   open_buy=3,       // Open Buy
   open_sell=4,      // Open Sell
   open_buy_sell=5,  // Open Buy and Sell
  };
//--- input parameters
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input ushort   InpSignalsFrequency          = 10;                // Search signals, in seconds (min value "10")
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = close_all;         // Trade command:
input bool     ObjRevers                    = false;             // Obj: Revers
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = close_all;         // Trade command:
input ulong    InpMagic                     = 78712995;          // Magic number
//---
Files:
 
Alexsandr San:

Added another line.

For a full-fledged Expert, missing -

1 - Stop Loss , Take Profit in pips (not visible)

2 - Trailing Stop from horizontal line

3 - Signal from the Indicator

I will further modify the Expert Advisor2_LineOpenClose.mq5

//--- input parameters
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input ushort   InpSignalsFrequency          = 10;                // Search signals, in seconds (min value "10")
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = close_all;         // Trade command:
input bool     ObjRevers                    = false;             // Obj: Revers
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = close_all;         // Trade command:
input ulong    InpMagic                     = 78712995;          // Magic number
//---
 
Alexsandr San:

For a full-fledged Expert, missing -

1 - Stop Loss , Take Profit in pips (not visible)

2 - Trailing Stop from Horizontal Lines

3 - The signal from the indicator

I will further modify the Expert Advisor2_LineOpenClose.mq5

Added - Signal from Indic ator

this way

//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
double iGetArray(const int handle,const int buffer,const int start_pos,const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+
//| Search trading signals                                           |
//+------------------------------------------------------------------+
bool SearchTradingSignals(void)
  {
//--- we work only at the time of the birth of new bar
   datetime time_0=iTime(m_symbol.Name(),Period(),0);
   if(time_0==ExtPrevBarsY)
      return(true);
   ExtPrevBarsY=time_0;
   if(!m_symbol.RefreshRates())
     {
      ExtPrevBarsY=0;
      return(false);
     }
//---
   double BuyBuffer[];
   double SellBuffer[];
   ArraySetAsSeries(BuyBuffer,true);
   ArraySetAsSeries(SellBuffer,true);
   if(!iGetArray(handle_iCustom,1,0,2,BuyBuffer) || !iGetArray(handle_iCustom,0,0,2,SellBuffer))
     {
      ExtPrevBarsY=0;
      return(false);
     }
//---
   if(BuyBuffer[1]!=0.0)
     {
      switch(InpTradeCommandY)
        {
         case  close_buys:
            ExtNeedCloseBuy=true;
            if(LongObjClosed())
               break;
         case  close_sells:
            ExtNeedCloseSell=true;
            if(ShortObjClosed())
               break;
         case close_all:
            ExtNeedCloseAll=true;
            if(LongShortObjClosed())
               break;
         case open_buy:
            ExtNeedOpenBuy=true;
            if(LongObjOpened())
               break;
         case open_sell:
            ExtNeedOpenSell=true;
            if(ShortObjOpened())
               break;
         default:
            ExtNeedOpenBuySell=true;
            if(LongShortObjOpened())
               break;
        }
     }
   if(SellBuffer[1]!=0.0)
     {
      switch(InpTradeCommandU)
        {
         case  close_buys:
            ExtNeedCloseBuy=true;
            if(LongObjClosed())
               break;
         case  close_sells:
            ExtNeedCloseSell=true;
            if(ShortObjClosed())
               break;
         case close_all:
            ExtNeedCloseAll=true;
            if(LongShortObjClosed())
               break;
         case open_buy:
            ExtNeedOpenBuy=true;
            if(LongObjOpened())
               break;
         case open_sell:
            ExtNeedOpenSell=true;
            if(ShortObjOpened())
               break;
         default:
            ExtNeedOpenBuySell=true;
            if(LongShortObjOpened())
               break;
        }
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+

Now in the settings

//--- input parameters
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input ushort   InpSignalsFrequency          = 10;                // Search signals, in seconds (min value "10")
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = open_buy;          // Trade command:
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = open_sell;         // Trade command:
input string   short_name             = "Examples\\ZigzagColor"; // Name Indicators
input ENUM_TRADE_COMMAND InpTradeCommandY   = open_buy;          // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU   = open_sell;         // Trade command: (SellBuffer Indicators)
input bool     ObjRevers                    = false;             // Obj: Revers
//---

Checking of an indicator signal

par

graf

Files:
XXX_Ind.mq5  52 kb
 
Alexsandr San:

For a full-fledged Expert, missing -

1 - Stop Loss , Take Profit in pips (not visible)

2 - Trailing Stop from Horizontal Lines

3 - The signal from the indicator

I will fine-tune the Expert Advisor2_LineOpenClose.mq5

I also addedTrailing Stop from Horizontal Line . I sort of added everything and now check its workability.

Here are the settings

//+------------------------------------------------------------------+
input string   t="-----  Parameters         -----";              //
input string   Template                     = "ADX";             // Имя шаблона(without '.tpl')
input double   TargetProfit                 = 999999.99;         // Цель Баланса(Ваш Баланс + сумма)
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input int      InpTakeProfit                = 50;                // Take Profit ("0"-No. 5<100)
input string   t0="----- Trailing Line      -----";              //
input string   InpObjUpName                 = "TOP";             // Obj: TOP (Horizontal Line)
input ENUM_TRADE_COMMAND InpTradeCommand    = close_sells;       // Obj:  command:
input string   InpObjDownName               = "LOWER";           // Obj: LOWER (Horizontal Line)
input ENUM_TRADE_COMMAND InTradeCommand     = close_buys;        // Obj:  command:
input ushort   InpObjTrailingStop           = 30;                // Obj: Trailing Stop (distance from price to object, in pips)
input ushort   InpObjTrailingStep           = 5;                 // Obj: Trailing Step, in pips (1.00045-1.00055=1 pips)
input string   t1="----- Line name: 1       -----";              //
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = open_buy;          // Trade command:
input string   t2="----- Line name: 2       -----";              //
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = open_sell;         // Trade command:
input string   t3="----- Indicators:        -----";              //
input string   short_name                   = "Examples\\ZigzagColor"; // Name Indicators
input bool     InpIndicators                = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY   = open_buy;          // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU   = open_sell;         // Trade command: (SellBuffer Indicators)
input string   t4="----- Revers Buy><Sell   -----";              //
input bool     ObjRevers                    = false;             //  Revers
//---


Files:
 
Alexsandr San:

AddedTrailing Stop from Horizontal Lines as well. I think I've added everything, now I just need to check if it works.

Here are the settings

The principle of work, here these parameters.

When funds reach a given target, all positions will be closed on all open pairs, and all charts will change to "ADX"pattern

( It is important - it is obligatory that figures above your balance are written in the settings) and Expert Advisor will close all opened positions and change the charts of the template

//+------------------------------------------------------------------+
input string   t="-----  Parameters         -----";              //
input string   Template                     = "ADX";             // Имя шаблона(without '.tpl')
input double   TargetProfit                 = 999999.99;         // Цель Баланса(Ваш Баланс + сумма)

-------------------------------------------------------------

lot parameter.

can you set one position as 0.06 or number of positions as 6 at 0.01

input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots

---------------------------------------------------------------

parameter with Take ProfitT.

It is triggered by the number of pips (if it is "0" it will close the position) it is necessary to specify the distance.

input int      InpTakeProfit                = 50;                // Take Profit ("0"-No. 5<100)

XXX_Trailing Line.mq5

 
Alexsandr San:

Added - Signal from Indicator

like this.

In the settings it is now like this

Checking the signal from the indicator

The indicator only opens positions to close, I took it from the Expert Advisor in the terminal (Moving Average)

I fined a little bit reversal

//+------------------------------------------------------------------+
//| Check for close position conditions                              |
//+------------------------------------------------------------------+
void CheckForClose(void)
  {
//---
   double BuyBuffer[];
   double SellBuffer[];
   ArraySetAsSeries(BuyBuffer,true);
   ArraySetAsSeries(SellBuffer,true);
   if(!iGetArray(handle_iCustom,1,0,2,BuyBuffer) || !iGetArray(handle_iCustom,0,0,2,SellBuffer))
     {
      return;
     }
//--- positions already selected before
   bool signal=false;
   long type=PositionGetInteger(POSITION_TYPE);
   if(ObjRevers)
     {
      if(type==(long)POSITION_TYPE_BUY && BuyBuffer[1]!=0.0)
         signal=true;
      if(type==(long)POSITION_TYPE_SELL && SellBuffer[1]!=0.0)
         signal=true;
     }
   if(!ObjRevers)
     {
      if(type==(long)POSITION_TYPE_BUY && SellBuffer[1]!=0.0)
         signal=true;
      if(type==(long)POSITION_TYPE_SELL && BuyBuffer[1]!=0.0)
         signal=true;
     }
//--- additional checking
   if(signal)
     {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period)>100)
         m_trade.PositionClose(_Symbol,3);
     }
//---
  }
//+------------------------------------------------------------------+

Photo by

The simplest trading system using semaphore indicators

January 13, 2012, 13:27



Samples of typical semaphore, signal indicators

There are many similar indicators in Code Base at the moment. For the purpose of this article, I will only give a few links to the source resources:


Files:
 
Alexsandr San:

From the indicator, only opens positions, to close, I took the way from the Expert Advisor in the terminal (Moving Average)

I fined up reverse a bit

I don't like it when I close a position. I am looking for a way to correct the function, to close a position from an indicator

-------------------------------------------------------------------

I fixed it. I added it from Moving Average indicator

//+------------------------------------------------------------------+
//| Position select depending on netting or hedging                  |
//+------------------------------------------------------------------+
bool SelectPosition()
  {
   bool res=false;
//--- check position in Hedging mode
   if(ExtHedging)
     {
      uint total=PositionsTotal();
      for(uint i=0; i<total; i++)
        {
         string position_symbol=PositionGetSymbol(i);
         if(_Symbol==position_symbol && InpMagic==PositionGetInteger(POSITION_MAGIC))
           {
            res=true;
            break;
           }
        }
     }
//--- check position in Netting mode
   else
     {
      if(!PositionSelect(_Symbol))
         return(false);
      else
         return(PositionGetInteger(POSITION_MAGIC)==InpMagic); //---check Magic number
     }
//--- result for Hedging mode
   return(res);
  }
//+------------------------------------------------------------------+

and in OnTick()

      if(InpCloseOpposite && InpIndicators)
        {
         //---
         if(SelectPosition())
            CheckForClose();
         else
            SearchTradingSignals();
        }
      if(!InpCloseOpposite && InpIndicators)
        {
         SearchTradingSignals();
        }

it turns outSelectPosition() should go through it

Files:
Reason: