Помощник закрытия позиции, если цена пересекла линию: Правило закрытия: цена Open и цена Close текущего бара должны оказаться по разные стороны от линии. Имя линии задаётся в параметре "Line name" - эту линию пользователь проводит сам. Тип линии может быть...
//+------------------------------------------------------------------+//| 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 parametersinputuint maxLimits = 1; // Кол-во Позиции Открыть в одну сторонуinputdouble InpLots = 0.01; // Lotsinputushort InpSignalsFrequency = 10; // Search signals, in seconds (min value "10")inputstring InpNameR = "LineR"; // Line name (Horizontal Line or Trend Line)input ENUM_TRADE_COMMAND InpTradeCommandR = close_all; // Trade command:inputbool ObjRevers = false; // Obj: Reversinputstring InpNameS = "LineS"; // Line name (Horizontal Line or Trend Line)input ENUM_TRADE_COMMAND InpTradeCommandS = close_all; // Trade command:inputulong InpMagic = 78712995; // Magic number//---
//+------------------------------------------------------------------+//| Get value of buffers |//+------------------------------------------------------------------+double iGetArray(constint handle,constint buffer,constint start_pos,constint count,double &arr_buffer[])
{
bool result=true;
if(!ArrayIsDynamic(arr_buffer))
{
Print("This a no dynamic array!");
return(false);
}
ArrayFree(arr_buffer);
//--- reset error codeResetLastError();
//--- fill a part of the iBands array with values from the indicator bufferint copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
if(copied!=count)
{
//--- if the copying fails, tell the error codePrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculatedreturn(false);
}
return(result);
}
//+------------------------------------------------------------------+//| Search trading signals |//+------------------------------------------------------------------+bool SearchTradingSignals(void)
{
//--- we work only at the time of the birth of new bardatetime 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 parametersinputuint maxLimits = 1; // Кол-во Позиции Открыть в одну сторонуinputdouble InpLots = 0.01; // Lotsinputushort InpSignalsFrequency = 10; // Search signals, in seconds (min value "10")inputstring InpNameR = "LineR"; // Line name (Horizontal Line or Trend Line)input ENUM_TRADE_COMMAND InpTradeCommandR = open_buy; // Trade command:inputstring InpNameS = "LineS"; // Line name (Horizontal Line or Trend Line)input ENUM_TRADE_COMMAND InpTradeCommandS = open_sell; // Trade command:inputstring short_name = "Examples\\ZigzagColor"; // Name Indicatorsinput ENUM_TRADE_COMMAND InpTradeCommandY = open_buy; // Trade command: (BuyBuffer Indicators)input ENUM_TRADE_COMMAND InpTradeCommandU = open_sell; // Trade command: (SellBuffer Indicators)inputbool ObjRevers = false; // Obj: Revers//---
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
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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 is in the middle (between the lines (red and blue) signals do not work - will work, as will come out to either side
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
Combined two experts for manual trading
this onehttps://www.mql5.com/ru/code/24803
and this onehttps://www.mql5.com/ru/code/26353
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
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
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
Now in the settings
Checking of an indicator signal
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
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
-------------------------------------------------------------
lot parameter.
can you set one position as 0.06 or number of positions as 6 at 0.01
---------------------------------------------------------------
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.
XXX_Trailing Line.mq5
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
The simplest trading system using semaphore indicators
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:
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
and in OnTick()
it turns outSelectPosition() should go through it