SGarnov: Tried to insert it, it doesn't compile. The entire code, if necessary, I will put a screenshot of the compilation. I think there may be another problem, my TP is set in relation to STOP by coefficient (external variable), maybe it can be changed to manual setting and it will be easier for EA to add?
from global scope, remove magic=0 for compilation.
Removed, no compilation errors, only 1 warning pops up in third function line in column tp=0 with hearing on external variable int tp=0. I don't quite understand what the programmer doesn't like. All code attached, if you're not hard to correct, the truth is somewhere near.
Removed, no compilation errors, only 1 warning pops up in third line of function in column tp=0 with hearing on external variable int tp=0. I don't quite understand what the programmer doesn't like. All code attached, if you're not hard to correct, the truth is somewhere near.
It looks like this
//+------------------------------------------------------------------+//| SGarnov.v2.mq4 |//| Copyright 2020, DrMak. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2020, DrMak."#property link"https://www.mql5.com"#property version"1.00"#property strict//--- input parametersinputint T_Profit = 2; // Коэффициент Take Profitinputint S_Loss = 100; // Уровень Stop Lossinputdouble O_Lots = 0.01; //Лотыinputint Input4;
inputint Input5;
inputint Input6;
double sl_price,tp_price,t_profit,s_loss;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---
t_profit = S_Loss*T_Profit;
s_loss = MathMax(S_Loss, MarketInfo(Symbol(), MODE_STOPLEVEL));
// Проверяем наличие ордеров BUYif(CountOrders(_Symbol, 0)>0)
{
// Проверяем последний закрытый ордер SELL на наличие убытка в пунктахif(GetPointLastLoss(1)>0)
{
// Если убыток есть, то добавляем пункты убытка
sl_price = NormalizeDouble(Point() * s_loss, Digits);
tp_price = NormalizeDouble(GetPointLastLoss(1)+Point() * t_profit, Digits);
ModifyOrder(_Symbol, sl_price, tp_price);
}
else
{
// Если убытка нет
sl_price = NormalizeDouble(Point() * s_loss, Digits);
tp_price = NormalizeDouble(Point() * t_profit, Digits);
ModifyOrder(_Symbol, sl_price, tp_price);
}
}
// Проверяем наличие ордеров SELLif(CountOrders(_Symbol, 1)>0)
{
// Проверяем последний закрытый ордер BUY на наличие убытка в пунктахif(GetPointLastLoss(0)>0)
{
// Если убыток есть, то добавляем пункты убытка
sl_price = NormalizeDouble(Point() * s_loss, Digits);
tp_price = NormalizeDouble(GetPointLastLoss(0)+Point() * t_profit, Digits);
ModifyOrder(_Symbol, sl_price, tp_price);
}
else
{
// Если убытка нет
sl_price = NormalizeDouble(Point() * s_loss, Digits);
tp_price = NormalizeDouble(Point() * t_profit, Digits);
ModifyOrder(_Symbol, sl_price, tp_price);
}
}
}
//+--------------------------------------------------------------------------------------------------------------------+//| Подсчет ордеров по типу |//+--------------------------------------------------------------------------------------------------------------------+//| 0 - ордера типа BUY 1 - ордера типа SELL |//| 2 - ордера типа BUYLIMIT 3 - ордера типа SELLLIMIT |//| 4 - ордера типа BUYSTOP 5 - ордера типа SELLSTOP |//| 6 - ордера типа Balance -1 - Все типы ордеров |//+--------------------------------------------------------------------------------------------------------------------+int CountOrders(string symb="", int or_ty=-1)
{
int cnt=0;
if(symb=="0") symb=_Symbol;
for(int pos=OrdersTotal()-1;pos>=0;pos--)
{
if(OrderSelect(pos,SELECT_BY_POS)==true)
{
if(OrderSymbol()==symb || symb=="")
{
if(or_ty<0 || or_ty==OrderType()) cnt++;
}
}
}
return(cnt);
}
//+----------------------------------------------------------------------------+//| Модификация ордера |//+----------------------------------------------------------------------------+//| sl - ценовой уровень стопа |//| tp - ценовой уровень тейка |//+----------------------------------------------------------------------------+void ModifyOrder(string symb="", double sl=0, double tp=0)
{
if(symb=="0") symb=_Symbol;
for(int pos=OrdersTotal()-1;pos>=0;pos--)
{
if(OrderSelect(pos,SELECT_BY_POS)==true)
{
if(OrderSymbol()==symb || symb=="")
{
if(OrderStopLoss()==0)
{
if(OrderType()==OP_BUY)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-sl_price, OrderOpenPrice()+tp_price, OrderExpiration()))
{Print("Ордер модифицирован");}
else
{Print("Ошибка модификации ордера:", GetLastError());}
}
if(OrderType()==OP_SELL)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+sl_price, OrderOpenPrice()-tp_price, OrderExpiration()))
{Print("Ордер модифицирован");}
else
{Print("Ошибка модификации ордера:", GetLastError());}
}
}
}
}
}
}
//+----------------------------------------------------------------------------+//| Возвращает пункты убытка последнего закрытого ордера в пунктах |//| 0 - последний ордер BUY |//| 1 - последний ордер SELL |//+----------------------------------------------------------------------------+double GetPointLastLoss( int or_ty=-1)
{
datetime t=0;
double result=0,p=0;
int i=OrdersHistoryTotal();
for(int pos=0; pos<i; pos++)
{
if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
{
if((OrderSymbol()==_Symbol))
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
{
if(t<OrderCloseTime())
{t=OrderCloseTime(); p=OrderProfit(); or_ty=OrderType();
if(or_ty==OP_BUY&&p<0)
{
result=OrderOpenPrice()-OrderClosePrice();
} else {result=0;}
if(or_ty==OP_SELL&&p<0)
{
result=OrderClosePrice()-OrderOpenPrice();
} else {result=0;}
}
}
}
}
}
return(result);
}
//+------------------------------------------------------------------+
A) If the price reaches Takei - the Expert Advisor removes Stop Loss and a pending Sell order;
Variant 2.
B) If the stop loss is triggered and the EA "went to history", then:
A Sell order is opened and the Expert Advisor re-positions this order:
stop loss (external parameter is set in settings)
Take Profit + a triggered Stop Loss from the history;
a pending buy order at the stop loss level.
The price reaches the take - the Expert Advisor removes the stop loss and the pending Buy order.
And vice versa, if the work starts with a pending sell order.
And so advisor works until it stops its work with external parameter Stop Loss number (in my case it is 2, it means variant 2 will be repeated 3 times and advisor will stop working in future and will delete all pending orders, the first stop is not taken into account).
If takei is not reached and variant 2 is repeated, then 2 stops are added to takei and so on, it depends on set external parameter"Stop Loss count".
The code, which I put up works as it should, except for the problem, which I described (does not see in the history of 1 stop or 2 stops, which should add to the take).
A) If the price reaches Takei - the Expert Advisor removes Stop Loss and a pending Sell order;
Variant 2.
B) If the stop loss is triggered and the EA "went to history", then:
A Sell order is opened and the Expert Advisor re-positions this order:
stop loss (external parameter is set in settings);
Take Profit + a triggered Stop Loss from the history;
a pending buy order at the stop loss level.
The price reaches the take - the Expert Advisor removes the stop loss and the pending Buy order.
And vice versa, if the work starts with a pending sell order.
And so advisor works until it stops its work with external parameter Stop Loss number (in my case it is 2, it means variant 2 will be repeated 3 times and advisor will stop working in future and will delete all pending orders, the first stop is not taken into account).
If takei is not reached and variant 2 is repeated, then 2 stops are added to takei and so on, it depends on set external parameter"Stop Loss count".
The code, which I put up works as it should, except for the problem, which I described (does not see in the history of 1 stop or 2 stops, which should add to the take).
It goes like this.
"Number of Stop Losses" - in a row or for the current day?
"Number of Stop Losses" - in a row or for the current day?
The number of stops in a row on a currency pair.
In order to analyse the history, the Expert Advisor initially labels the orders with their IDs, but does not find them in the history, I thought that OrderMagikNumber() will search for them. Maybe because of the fact that in the history stops from different currency pairs the EA stops "seeing" them?
put up the source again? All he needs to do is correct "search for stop trades from history and make it add to the newly placed take".
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.
Do you have an EA which supports manually placed orders?
Tried to insert it, it doesn't compile. The entire code, if necessary, I will put a screenshot of the compilation. I think there may be another problem, my TP is set in relation to STOP by coefficient (external variable), maybe it can be changed to manual setting and it will be easier for EA to add?
The function
from the global scope. magic=0 for compilation.
magic=0The function
from global scope, remove magic=0 for compilation.
Removed, no compilation errors, only 1 warning pops up in third function line in column tp=0 with hearing on external variable int tp=0. I don't quite understand what the programmer doesn't like. All code attached, if you're not hard to correct, the truth is somewhere near.
Removed, no compilation errors, only 1 warning pops up in third line of function in column tp=0 with hearing on external variable int tp=0. I don't quite understand what the programmer doesn't like. All code attached, if you're not hard to correct, the truth is somewhere near.
It looks like this
You don't need magic at all in your case
That's about right.
In your case magic is not needed at all.Thanks, will test it, will report back. I hope it works the same as mine, but adds a stop (if it's triggered) to the new take.
What are the external parameters Input4; 5; 6 needed for?
Thank you, I will test it and report back. I hope it works the same as mine, but adds a stop (if it triggered) to a new take.
There is only modification here. There is no order deletion or reversal.
If you describe what the EA should do, I will try to help.
What are the external parameters Input4; 5; 6 needed for?
If you describe what the EA should do, I will try to help.
I place a buy pending order - the EA is working - the pending order triggers - the EA "sees" this and places a stop loss on this open order:
stop loss (external parameter is set in settings);
Take Profit(external parameter is set in the settings using the ratio of e.g. 1 to 2);
pending sell order at stop loss level.
Possible scenarios.
Variant 1.
A) If the price reaches Takei - the Expert Advisor removes Stop Loss and a pending Sell order;
Variant 2.
B) If the stop loss is triggered and the EA "went to history", then:
A Sell order is opened and the Expert Advisor re-positions this order:
stop loss (external parameter is set in settings)
Take Profit + a triggered Stop Loss from the history;
a pending buy order at the stop loss level.
The price reaches the take - the Expert Advisor removes the stop loss and the pending Buy order.
And vice versa, if the work starts with a pending sell order.
And so advisor works until it stops its work with external parameter Stop Loss number (in my case it is 2, it means variant 2 will be repeated 3 times and advisor will stop working in future and will delete all pending orders, the first stop is not taken into account).
If takei is not reached and variant 2 is repeated, then 2 stops are added to takei and so on, it depends on set external parameter"Stop Loss count".
The code, which I put up works as it should, except for the problem, which I described (does not see in the history of 1 stop or 2 stops, which should add to the take).
Like this.
I put a pending buy order - the EA is working - the pending order triggers - the EA "sees" this and places a stop loss on this open order:
stop loss (external parameter is set in settings);
Take Profit(external parameter is set in the settings using the ratio of e.g. 1 to 2);
pending sell order at stop loss level.
Possible scenarios.
Variant 1.
A) If the price reaches Takei - the Expert Advisor removes Stop Loss and a pending Sell order;
Variant 2.
B) If the stop loss is triggered and the EA "went to history", then:
A Sell order is opened and the Expert Advisor re-positions this order:
stop loss (external parameter is set in settings);
Take Profit + a triggered Stop Loss from the history;
a pending buy order at the stop loss level.
The price reaches the take - the Expert Advisor removes the stop loss and the pending Buy order.
And vice versa, if the work starts with a pending sell order.
And so advisor works until it stops its work with external parameter Stop Loss number (in my case it is 2, it means variant 2 will be repeated 3 times and advisor will stop working in future and will delete all pending orders, the first stop is not taken into account).
If takei is not reached and variant 2 is repeated, then 2 stops are added to takei and so on, it depends on set external parameter"Stop Loss count".
The code, which I put up works as it should, except for the problem, which I described (does not see in the history of 1 stop or 2 stops, which should add to the take).
It goes like this.
"Number of Stop Losses" - in a row or for the current day?
"Number of Stop Losses" - in a row or for the current day?
The number of stops in a row on a currency pair.
In order to analyse the history, the Expert Advisor initially labels the orders with their IDs, but does not find them in the history, I thought that OrderMagikNumber() will search for them. Maybe because of the fact that in the history stops from different currency pairs the EA stops "seeing" them?
put up the source again? All he needs to do is correct "search for stop trades from history and make it add to the newly placed take".