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

 

Still, there is a difference in the code, the signal from the Indicator is different

If so, less indicators are suitable

//---
   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)
     {

This is better.

//---
   double main[],signal[];
   ArraySetAsSeries(main,true);
   ArraySetAsSeries(signal,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iCustom,MAIN_LINE,start_pos,count,main) ||
      !iGetArray(handle_iCustom,SIGNAL_LINE,start_pos,count,signal))
     {
      ExtPrevBarsY=0;
      return(false);
     }

   if(main[1]>signal[1])
     {

I have changed it to this one! I still check the Expert Advisor for availability, everything seems to work.

it works well with an indicator of this type (the file below)

Files:
2.mq5  17 kb
 

To avoid confusion with position opening and closing, it's better to set all lines and the indicator in the right direction, and not to use reverse

otherwise, you can get confused - especially since there is an option in settings (reversing applies to all lines and the indicator)

input string   t3="----- Indicators:        -----";              //
input string   short_name                   = "Examples\\MACD";  // Name Indicators
input bool     InpIndicators                = false;             // Indicators: Start (true)
input bool     InpCloseOpposite             = false;             // Close opposite
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

you can simply deletethe input in the code itself
like this

string   t4="----- Revers Buy><Sell   -----";              //
bool     ObjRevers                    = false;             //  Revers
 
Alexsandr San:

To avoid confusion with position opening and closing, it's better to set all lines and the indicator in the right direction, and not to use reverse

otherwise, you can get confused - especially since there is an option in settings (reversing applies to all lines and the indicator)

you can simply deletethe input in the code itself
like this

no! the indicator needs reversing

 

I'm trying to get some new features out of the Indicator, and I'm trying to do it all.

input string   t3="----- Indicators: SELL   -----";              //
input string   short_name                   = "2";               // Name Indicators "SELL"
input bool     InpIndicators                = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY   = open_sell;         // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU   = close_sells;       // Trade command: (SellBuffer Indicators)
input string   t4="----- Indicators: BUY    -----";              //
input string   short_name1                  = "2";               // Name Indicators "BUY"
input bool     InpIndicators1               = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY1  = close_buys;        // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU1  = open_buy;          // Trade command: (SellBuffer Indicators)

I can fantasize with one indicator or two.

you just need to pick up, Indicator - like this (photo)

https://www.mql5.com/ru/code/392

Photo by

I've made an indicator called ( 2 )

Files:
2.mq5  17 kb
 
Alexsandr San:

I'm trying to get some new features out of the Indicator, and I'm trying to do it all.

I can fantasize with one indicator or two.

You just need to choose, Indicator - like this (photo)

https://www.mql5.com/ru/code/392

I cheated the indicator which is called ( 2 )

I check how it works for 1 minute - it works fine

Snapshot2

 
Alexsandr San:

Checking how it works for 1 minute - works fine


expertWWWW_Trailing_Line.mq596 kb works fine, no errors.

only, need to add a panel for information and for testing, in the tester in the manual version

panel

 
Alexsandr San:

expert works wellWWWW_Trailing_Line.mq596 kb, no errors.

Only, you need to add a panel for information and for testing, in the tester in the manual version

I have added a panel - now you can do some manual testing in the tester.

Command_Trailing Line

what are its 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: SELL   -----";              //
input string   short_name                   = "2";               // Name Indicators "SELL"
input bool     InpIndicators                = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY   = open_sell;         // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU   = close_sells;       // Trade command: (SellBuffer Indicators)
input string   t4="----- Indicators: BUY    -----";              //
input string   short_name1                  = "2";               // Name Indicators "BUY"
input bool     InpIndicators1               = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY1  = close_buys;        // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU1  = open_buy;          // Trade command: (SellBuffer Indicators)
input string   t5="----- Button:            -----";              //
input ENUM_TRADE_COMMAND InpTradeCommandBut = open_buy;          // Obj(BUY):  command:Button: BUY
input ENUM_TRADE_COMMAND InTradeCommandBut  = open_sell;         // Obj(SELL):  command:Button: SELL
input int      TrailingStop_STOP_LEVEL      = 36;                // Button: Trailing Stop LEVEL
Files:
 
Alexsandr San:

added a panel - now you can still in the tester, get your hands on it.

what settings does it have

Damn! missed the insertion in OnDeinit

when you remove the Expert Advisor from the chart - the panel is not removed without it

the code is open, you can copy and paste it yourself

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   for(int i=0; i<ArraySize(_name); i++)
     {
      ObjectDelete(0,Symbol()+_name[i]);
     };
   EventKillTimer();
//---
   Print(TimeCurrent(),": ",__FUNCTION__," reason code = ",reason);
   Comment("");
  }
//+------------------------------------------------------------------+
 
Alexsandr San:

added a panel - now you can still in the tester, get your hands on it.

what settings it has.

i need to add one more function.

For example - a signal for SELL is triggered, not to open a position - but to draw a horizontal line N points back and when the price goes back and from this line - to open a position.

EURUSDH1

 
Alexsandr San:

we need to add one more function.

For example - a signal for SELL is triggered, not to open a position, but to draw a horizontal line N points back and when the price goes back and from this line - to open a position.


I've tried to keep it simple. If someone gets interested, ask us, we'll try to figure it out together.

Photo by

Snapshot2