[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 224

 

I want a message to be displayed after closing on a stop loss, but nothing happens in mt4.

int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
string sy="NULL";
int op=-1;
int mn=-1;
bool isCloseLastPosByStop(string sy="", int op=-1, int mn=-1) {
datetime t;
double ocp, osl;
int dg, i, j=-1, k=OrdersHistoryTotal();

if (sy=="0") sy=Symbol();
for (i=0; i<k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if (OrderSymbol()==sy || sy=="") {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (op<0 || OrderType()==op) {
if (mn<0 || OrderMagicNumber()==mn) {
if (t<OrderCloseTime()) {
t=OrderCloseTime();
j=i;
}
}
}
}
}
}
}
if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
dg=MarketInfo(sy, MODE_DIGITS);
if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2;
ocp=NormalizeDouble(OrderClosePrice(), dg);
osl=NormalizeDouble(OrderStopLoss(), dg);
if (ocp==osl) return(True);
}
return(False);
}
int start()
{
//----
bool stopl;
stopl = isCloseLastPosByStop(sy,op,mn);
if (stopl == true)
Alert ("последняя сделка закрылась по s/l");
//----
return(0);
}

Files:
33.mq4  3 kb
 
It's awkward to read this code, all the text is greyed out...)
 
 

Dear forum members, I am putting up the "Balance Chart" indicator for review. I think it would be useful in a separate window - a visual control over the changes in your own balance in real time, control of the profitability of the Expert Advisor in the end... The problem is that it does not work... I "tinkered" it myself, I do not understand it very well. I have developed a few indicators, but I have not done anything with it... I would be grateful for a correction. I wrote down what I wanted to get. Please don't hesitate to mash them, if only the result! Perhaps someone else will need it, it seems that the thing is not superfluous...

Files:
 
you have 1 balance on all bars?) why do you need it
 
eddy:
you have 1 balance on all bars?

I may not have stated the problem accurately - maybe it would be more accurate
AccountEquity( )

insert. But that's the second one. And, most importantly, I would like to observe these changes after opening/closing positions...

It would be something like a balance line like in the tester, but on the real?

 
kulon:

I may not have stated the problem accurately - it may be more accurate to
AccountEquity( )
insert. But this is the second one. And most importantly, I would like to observe these changes after opening/closing positions...


You need to read the trades history and read the balance at the time when the next position was closed.

Equity is a little more complicated, but it can be done in exactly the same way.

You can convert all calculations to a standard lot or count in pips

 

Question with window...

I insert #property indicator_separate_window line into standard indicator - after that MT4 does not want to attach it to a finance tool. Why?

 
100yan:

Question with window...

I insert #property indicator_separate_window line into standard indicator - after that MT4 does not want to attach it to a finance tool. Why?


Maybe the values are just very small and are somewhere at the bottom (outside the window)
 
Vinin:

Maybe the values are just very small and are somewhere at the bottom (outside the window)


But in theory there should be a separate window, albeit an empty one?

Also - neither the indicator nor the advisor.... attaches

 
100yan:

Question with window...

I insert #property indicator_separate_window line into standard indicator - after that MT4 does not want to attach it to a finance tool. Why?

Have a look atanalogues. In particular Equity_simple.mq4