The same as it looked, just a couple more curly brackets will be added:
I corrected, compiled, tested - the problem remains - When a certain condition is reached, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
externdouble Lots = 0.1;
externstring Сomment = "Pattern_1";
externint TakeProfit = 10;
externint StopLoss = 0;
externint Step = 2;
externint StepOtl = 4;
externint BULevel = 2;
externint NotBULevel = 2; // Уровень безубытка в пунктахexternint Slippage = 2; // проскальзывание externint Magic = 111;
int ticket1, ticket2, bs, ss, bsts, ssts, slms, blms;//добавил колич. ордеров по типам и их тикетыint timeprev;
double price1, price2; //цены открытия ордеров//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init()
{
return(0);
}
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
double SL,TP;
int slv=MarketInfo(Symbol(),MODE_STOPLEVEL);
if(Step<=slv || StepOtl<=slv) {Print("Step или StepOtl слишком мал"); return(0);}
CountTrades(); //подсчет ордеров по типам.
BU();
//если нет рыночных ордеров-----------------------------------------if(bs+ss+bsts+ssts+blms+slms==0)
{
if (Open[1]>Close[1] && Open[2]<Close[2] && High[1]>High[2] && Low[1]<Low[2]) // продажа
{
TP=NormalizeDouble(Bid - TakeProfit * Point, Digits);
SL=NormalizeDouble(Bid + StopLoss*Point,Digits);
if(TakeProfit==0) TP=0;
if(StopLoss==0) SL=0;
ticket1=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,"Pattern_1",Magic,0,Red);//Сразу с тейк-профитом, магик в настройкахif(OrderSelect(ticket1,SELECT_BY_TICKET,MODE_TRADES)) price1=OrderOpenPrice();//цена первого ордера
SL=NormalizeDouble(Bid+StepOtl*Point-StopLoss*Point,Digits);
if(StopLoss==0) SL=0;
ticket2=OrderSend(Symbol(),OP_BUYSTOP,Lots,NormalizeDouble(Bid+StepOtl*Point,Digits),0,SL,0,"Pattern_1",Magic,0,Blue);//тикет для BuyStopif(OrderSelect(ticket2,SELECT_BY_TICKET,MODE_TRADES)) price2=OrderOpenPrice();//цена второго ордера
}
if (Open[1]<Close[1] && Open[2]>Close[2] && High[1]>High[2] && Low[1]<Low[2]) // покупка
{
TP=NormalizeDouble(Ask + TakeProfit * Point, Digits);
if(TakeProfit==0) TP=0;
SL=NormalizeDouble(Ask-StopLoss*Point,Digits);
if(StopLoss==0) SL=0;
ticket1=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,"Pattern_1",Magic,0,Blue);//с тейком, магик в настройках if(OrderSelect(ticket1,SELECT_BY_TICKET,MODE_TRADES)) price1=OrderOpenPrice();//цена первого ордера
SL=NormalizeDouble(Bid-StepOtl*Point+StopLoss*Point,Digits);
if(StopLoss==0) SL=0;
ticket2=OrderSend(Symbol(),OP_SELLSTOP,Lots,NormalizeDouble(Bid-StepOtl*Point,Digits),0,SL,0,"Pattern_1",Magic,0,Red);//тикет для SellStopif(OrderSelect(ticket2,SELECT_BY_TICKET,MODE_TRADES)) price2=OrderOpenPrice();//цена второго ордера
}
}
return(0);
}
//+------------------------------------------------------------------+void CountTrades() // количество открытых ордеров
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)//отделяем свои ордера. Магик задается в настройках
{
int typ=OrderType(); //однократный вызов функции ускоряет работуswitch (typ)
{
case0: bs++;
case1: ss++;
case2: blms++;
case3: slms++;
case4: bsts++;
case5: ssts++;
default: break;
}
}
}
}
return;
}
//+------------------------------------------------------------------+void BU()
{
for(int a=OrdersTotal()-1; a>=0; a--)
{
if (OrderSelect(a, SELECT_BY_POS, MODE_TRADES))
{
if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
int typ=OrderType(); //вызываем функцииint tic=OrderTicket(); //один разdouble oop=OrderOpenPrice(); //это ускоряет работуdouble otp=OrderTakeProfit(); //советникаdouble osl=OrderStopLoss();
if(typ==OP_BUY)
{
if(oop<=NormalizeDouble(Bid-BULevel*Point-NotBULevel*Point,Digits) && oop>osl)// последнеее условие БУ + 20 пипсов
OrderModify(tic,oop,NormalizeDouble(oop+NotBULevel*Point,Digits),otp,0,Green);
OrderDelete(ticket2,Yellow);
}
if(typ==OP_SELL)
{
if(oop>=NormalizeDouble(Ask+BULevel*Point+NotBULevel*Point,Digits) && (oop<osl || osl==0))// последнеее условие БУ + 20 пипсов
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-NotBULevel*Point,OrderTakeProfit(),0,Red);
OrderDelete(ticket2,Yellow);
}
}
}
return;
}
Fixed, compiled, tested - the problem remains - When a certain condition occurs, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
Where does it count?
bs+ss+bsts+ssts+blms+slms
They're global. And they don't seem to reset until they're checked. And their calculation before the check - where?
Fixed, compiled, tested - the problem remains - When a certain condition occurs, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
BU re-do it, you can't delete market positions, and because of a frozen stop there won't be any more positions ))))
Fixed, compiled, tested - the problem remains - When a certain condition occurs, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
evillive: BU redo it, you can't delete market positions, and because of a hanging stop there won't be any more positions )))
Let the gurus comment on whether the BU() function needs break (commented out) or not, and let alexey1979621 think, whether this function is called there?
Also, if CountTrades(); function is used like this, it's equal to OrdersTotal(), simpler and faster.
Why count pending orders? And who is BU();?
It's a strange method to "separate" own positions from others, isn't it better to
BU(); is a Breakeven function.
What's wrong with my variant?
сюда пересчёт рыночных позиций и отложекWhat would it look like in my case?What would it look like in my case?
The same as it looked, just a couple more curly braces added:
The same as it looked, just a couple more curly brackets will be added:
I corrected, compiled, tested - the problem remains - When a certain condition is reached, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
About good - that's a pitchfork in the water. If it's fast, it's also a bit of a stretch... And if it's cheap, see point 1.
Then it goes like this:
1. Good is a bit of a stick in the mud. 2.About fast, it's also a two-edged sword... 3. And if it's cheap - see point 1.
Now I see!
Fixed, compiled, tested - the problem remains - When a certain condition occurs, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
Where does it count?
They're global. And they don't seem to reset until they're checked. And their calculation before the check - where?Fixed, compiled, tested - the problem remains - When a certain condition occurs, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
Fixed, compiled, tested - the problem remains - When a certain condition occurs, the Expert Advisor opens a trade and closes it at Take or Stop Loss. At this point, the Expert Advisor does not open deals anymore, despite the fact that the conditions for opening deals are fulfilled.
Here is the code in full.
BU redo it, you can't delete market positions, and because of a hanging stop there won't be any more positions )))
Let the gurus comment on whether the BU() function needs break (commented out) or not, and let alexey1979621 think, whether this function is called there?
Also, if CountTrades(); function is used like this, it's equal to OrdersTotal(), simpler and faster.
Let the gurus comment whether a break is needed here or not, and let alexey1979621 think, is this function called there?
Also, if we use CountTrades(); so, it's equal to OrdersTotal(), easier and faster.