Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 306

 
Alexey Viktorov:

And there couldn't be any other. No computer knows a year less than 1970. Start with the year that appears in the broker's quotes.

I see) Thank you.
 
Aleksey Vyazmikin:

Code in MT5

Result:


SZZY: I changed the code - it was from wrong ME.

I didn't immediately understand the idea. I haven't done it in mql5, I will have to figure it out. But you can do it in mql4 in the following way:

Create two additional buffers.

Set an offset for N bars and fill these N bars with last value of main buffers.

And of course index N+1 of these additional buffers fill with empty value.

 
Alexey Viktorov:

I didn't immediately understand the idea. I didn't do it in mql5, I'll have to figure it out. But in mql4 you can do it in the following way:

Create two additional buffers.

Set an offset for them by N bars and fill these N bars with the last value of the main buffers.

And of course index N+1 of these additional buffers fill with empty value.


Thanks for the idea - I originally did so in MT5, then I optimized it.

Anyway, went to bed at 4am (public code is not complete, of course), but did what I wanted with two buffers.

The problem was, that in MT5 the filling is from left to right, and in MT4 it is vice versa.ArraySetAsSeries function didn't help - I rewrote all logic in fact.

 

Good afternoon, Artem!

I would like to ask for help with my rework of TrExp_Nik ver. I want to add the possibility to shift it to Breakeven. However, my limited programming skills do not allow me to do that. I decided to use e-MovingInWL whose code I am trying to integrate into my EA, but I cannot combine variables properly or I do not understand correctly the code of the second Breakeven Expert Advisor. Perhaps, this is not the optimal variant. I would like to ask your advice on how to make it better or easier.

Files:
 
niktach:

Good afternoon, Artem!

I would like to ask for help with my rework of TrExp_Nik ver. I want to add the possibility to shift it to Breakeven. However, my limited programming skills do not allow me to do that. I decided to use e-MovingInWL whose code I am trying to integrate into my EA, but I cannot combine variables properly or I do not understand correctly the code of the second Breakeven Expert Advisor. Perhaps, this is not the optimal variant. I would like to ask your advice on how to improve or simplify it.

Good day. What exactly have you tried to do? I see only two attached codes. If you need someone to do everything for you, that's what freelancing is for.

And if you're trying to do it yourself, then show me exactly what you're doing and where you don't understand.

 

Hello,

Is there any way to programmatically get to the properties of the "triangle" graphic object placed on the chart? I mean the time and price coordinates of the vertices, which are displayed on the "Parameters" tab when the properties form is interactively opened. I tried to use theObjectGetInteger and ObjectGetDouble functions, but they can only get data on one vertex.

Thank you.

 
oddball:

Hello,

Is there any way to programmatically get to the properties of the "triangle" graphic object placed on the chart? I mean the time and price coordinates of the vertices, which are displayed on the "Parameters" tab when the properties form is interactively opened. I tried to use the ObjectGetInteger and ObjectGetDouble functions, but they can only get data on one vertex.

Thank you.

Yes, you can. And the direction of thought is correct. Can you show me how you tried to get the parameters?

 
Artyom Trishkin:

When the order is selected by ticket, there is no need to specify pool - MODE_TRADES is redundant here - this parameter is ignored when selecting by ticket and the order is selected from one of the two lists - from the list of closed or from the list of market positions - it depends on whether the position is closed or not yet.

After the successful selection of an order based on the ticket, in order to understand which of the two lists the order is selected from, it is necessary to check the position closing time - if it is higher than zero, then the order has already been closed and was selected from the list of historical orders, otherwise - the order is still in the market.

But in order to understand where you have an error, you need to attach the code - give more information, because there is no error in this line in principle (except that you do not check the return result of the function, you use a modifier which is ignored in this case and there is no ";" after the closing bracket).


Thank you very much for the reply.

Here's the whole function, the point is that it opens an order and then adds constant stop loss and take profit values via modification.

The order is opened but stop loss and take profit are not set (the calculation function in red, in whichOrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES) gives an error ((() )

//Open Order function, variables: symbol, order type, lot, open price, TP and SL calculation method (0 - set in the price, 1 - set in points that should be calculated from the open price), stop loss, take profit)

//Symbol/Pair, open order type - pending, open price, switch = 1, SL B TP - Stop Loss and Take Profit values are constant!

bool SendOrder(string Symb,int Type, double OP,int Mode) {
color CL;
double Pp = MarketInfo(Symb, MODE_POINT);
if (Type==0) CL=Blue;
if (Type==1) CL=Red;
if (Type==2 || Type==4) CL=DarkTurquoise;
if (Type==3 || Type==5) CL=Orange;
//verview volume
if(MarketInfo(Symb,MODE_LOTSTEP)==0.01) DG=2; else DG=1;
if (Lot<MarketInfo(Symb,MODE_MINLOT)) Lot=MarketInfo(Symb,MODE_MINLOT);
if (Lot>MarketInfo(Symb,MODE_MAXLOT)) Lot=MarketInfo(Symb,MODE_MAXLOT);
if (Lot*MarketInfo(Symb,MODE_MARGINREQUIRED)>AccountEquity()) {
PnC(StringConcatenate("Not enough money to open the trade",Type," ",DoubleToStr(Lot,DG)),0);
return;
}
// check pending orders
/*
double Slv = MarketInfo(Symb,MODE_STOPLEVEL)*Pp;
if (Type>1) {
if (Type==2 && MarketInfo(Symb,MODE_ASK)-OP<Slv) OP=MarketInfo(Symb,MODE_ASK)-Slv;
if (Type==3 && OP-MarketInfo(Symb,MODE_BID)<Slv) OP=MarketInfo(Symb,MODE_BID)+Slv;
if (Type==4 && OP-MarketInfo(Symb,MODE_ASK)<Slv) OP=MarketInfo(Symb,MODE_ASK)+Slv;
if (Type==5 && MarketInfo(Symb,MODE_BID)-OP<Slv) OP=MarketInfo(Symb,MODE_BID)-Slv;
}
*/
RefreshRates();
int Min_Dist = MarketInfo(Symb,MODE_STOPLEVEL); //Limit stop loss/stake profit level in pips. Min. distance
double Tek_Ask = MarketInfo(Symb,MODE_ASK); //The last received selling price. It is stored in the predefined variable Ask for the current symbol
double Tek_Bid = MarketInfo(Symb,MODE_BID); //The last bid price received. It is stored in the predefined variable Bid for the current symbol
double Tek_Point = MarketInfo(Symb,MODE_POINT); //Point size in the quote currency. It is stored in the predefined variable Point for the current symbol
int Tek_Digits = MarketInfo(Symb,MODE_DIGITS);//The number of digits after the decimal point in the symbol price. It is stored in the predefined variable Digits

double Slv = NormalizeDouble(Min_Dist*Tek_Point,Tek_Digits);
if (Type>1) {
if (Type==2 && Tek_Ask - OP < Slv) OP = Tek_Ask - Slv;
if (Type==3 && OP - Tek_Bid < Slv) OP = Tek_Bid + Slv;
if (Type==4 && OP - Tek_Ask < Slv) OP = Tek_Ask + Slv
if (Type==5 && Tek_Bid - OP < Slv) OP = Tek_Bid - Slv;
}
// check stops
if (SL!=0 || TP!=0) {
if (Mode==0) {
if (MathAbs(OP-SL)<Slv && SL!=0) {
if (Type==0 || Type==2 || Type==4) SL=OP-Slv; else SL=OP+Slv;
}
if (MathAbs(OP-TP)<Slv && TP!=0) {
if (Type==0 || Type==2 || Type==4) TP=OP+Slv; else TP=OP-Slv;
}
}else{
if (SL*Pp<Slv && SL!=0) SL=Slv/Pp;
if (TP*Pp<Slv && TP!=0) TP=Slv/Pp;
}
}
// october
for(int k=0;k<=TryToTrade;k++) {
if (Type==0) OP=MarketInfo(Symb,MODE_ASK);
if (Type==1) OP=MarketInfo(Symb,MODE_BID);
PnC(StringConcatenate("Trying to open an order, type: ",Type," volume: ",Lot," price: ",OP),0);
if (IsTradeAllowed()) {
int Ticket=OrderSend(Symb,Type,Lot,NormalizeDouble(OP,MarketInfo(Symb,MODE_DIGITS)),3,0,0,NULL,Tek_Magic,0,CL);
}else{ PnC(StringConcatenate("Cannot open order ",k),0;) Sleep(3000); continue; }
if (Ticket >= 0) { PnC(StringConcatenate("Order opened ",Ticket),0); break; }
LastError=Fun_Error(GetLastError());
if (LastError==0) {
RefreshRates(); Sleep(WaitTime);
if (k==TryToTrade) return(false); }
if (LastError==1) return(false);
if (LastError==2) { Work=false; return(false); }
}
// set stops
OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES);
if (SL==0 && TP==0) return;
if (Mode==1) {
if (SL!=0) {
if (Type==0 || Type==2 || Type==4) SL=OrderOpenPrice()-SL*Pp;
if (Type==1 || Type==3 || Type==5) SL=OrderOpenPrice()+SL*Pp;
}
if (TP!=0) {
if (Type==0 || Type==2 || Type==4) TP=OrderOpenPrice()+TP*Pp;
if (Type==1 || Type==3 || Type==5) TP=OrderOpenPrice()-TP*Pp;
}
}

for(k=0;k<=TryToTrade;k++) {
PnC(StringConcatenate("Trying to set stops on an order: ",Ticket," s/l: ",SL," t/p: ",TP),0);
if (IsTradeAllowed()) {
//TickeT=OrderModify(Ticket,NormalizeDouble(OrderOpenPrice(),MarketInfo(Symb,MODE_DIGITS)),NormalizeDouble(Symb,MarketInfo(Symb,MODE_DIGITS)),NormalizeDouble(TP,MarketInfo(Symb,MODE_DIGITS)),0,CLR_NONE);
TickeT=OrderModify(Ticket,NormalizeDouble(OrderOpenPrice(),MarketInfo(Symb,MODE_DIGITS)),NormalizeDouble(SL,MarketInfo(Symb,MODE_DIGITS)),NormalizeDouble(TP,MarketInfo(Symb,MODE_DIGITS)),0,CLR_NONE)
}else{ PnC(StringConcatenate("Cannot modify order ",k),0); Sleep(3000); continue; }
if (TickeT == true) { PnC(StringConcatenate("Order Modified ",Ticket),0); break; }
LastError=Fun_Error(GetLastError());
if (LastError==0) {
RefreshRates(); Sleep(WaitTime);
if (k==TryToTrade) return(false); }
if (LastError==1) return(false);
if (LastError==2) { Work=false; return(false); }
}
return(true);

}

 

Can someone explain why error 131"wrong volume" comes out when modifying an order?

The pending opens normally, the lot is normalised, when outputting to print the minimum lot is 0.01, which is not less than my volume(demo account)

I re-read everything on the forum and couldn't find the problem!

I am still wondering what is going on behind the scenes and what is not described.
 
forexman77:

Can someone explain why error 131"wrong volume" comes out when modifying an order?

The pending opens normally, the lot is normalised, when outputting to print the minimum lot is 0.01, which is not less than my volume(demo account)

I re-read everything on my forum but i couldn't find the problem!

Just do not cease to be surprised by hidden bugs that emerge and not described.

I tried it with another brokerage company and it didn't change my mind. The question is why when you call:

double MinLot = MarketInfo(Symbol(),MODE_MINLOT);
double MaxLot = MarketInfo(Symbol(),MODE_MAXLOT);
Alert("MinLot=",MinLot,"MaxLot=",MaxLot);  

deducts 0.01, and the bot prints 131?

Reason: