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

 
Youri Lazurenko:

I have it like this - opening an order with zero TP and SL, and then modifying (the order) with the required TP and SL parameters. I already wrote, everything works and worked fine on other accounts, only on ndd such a thing. Haven't worked with anyone else with similar accounts before, can't compare. Maybe it's only forex4u's bleeping, or maybe all ndd accounts. I would like to know for future reference.
Since you have an error of 130, then look at the stop order parameters. In any case, they should be no closer than the StopLevel value set in the server settings. If it is equal to zero, then use double spread+1 point
 
Youri Lazurenko:

I have it like this - opening an order with zero TP and SL, and then modifying (the order) with the right TP and SL parameters. I already wrote, everything works and worked fine on other accounts, only on ndd such a thing. Haven't worked with anyone else with similar accounts before, can't compare. Maybe it's only forex4u's bleeping, or maybe all ndd accounts. Would like to know for further information.

When opening positions, use these functions to calculate correct stops and takes:

//+------------------------------------------------------------------+
double CorrectStopLoss(string symbol_name,int op,double price_set,double stop_loss) {
   if(stop_loss==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,stop_loss),dg));
   else return(NormalizeDouble(fmax(price+(lv+1)*pt,stop_loss),dg));
}
//+------------------------------------------------------------------+
double CorrectStopLoss(string symbol_name,int op,double price_set,int stop_loss) {
   if(stop_loss==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,price-stop_loss*pt),dg));
   else return(NormalizeDouble(fmax(price+(lv+1)*pt,price+stop_loss*pt),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,double take_profit) {
   if(take_profit==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,take_profit),dg));
   else return(NormalizeDouble(fmin(price-(lv+1)*pt,take_profit),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,int take_profit) {
   if(take_profit==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,price+take_profit*pt),dg));
   else return(NormalizeDouble(fmin(price-(lv+1)*pt,price-take_profit*pt),dg));
}
//+------------------------------------------------------------------+
int StopLevel(string symbol_name) {
   int sp=(int)SymbolInfoInteger(symbol_name,SYMBOL_SPREAD);
   int lv=(int)SymbolInfoInteger(symbol_name,SYMBOL_TRADE_STOPS_LEVEL);
   return((lv==0)?sp*2:lv);
}
//+------------------------------------------------------------------+
 
Alexey Viktorov:

What is the difference

Pips = Charge/Lots/Tickvalue in specific figures 8/2/4 = 1

or

Pips = Charge/(Lots*Tickvalue) in specific numbers 8/(2*4) = 8/8 = 1

Fractional numbers can also be used...


The difference is that my namesake also multiplies byPoint for some reason:(OrderCommission()/(tv*OrderLots()))*Point()
 
Artyom Trishkin:
If you have error 130, then look at parameters of stop-orders. In any case, they must not be closer than the StopLevel value set in the server settings. If it is equal to zero, then use double spread + 1 point


Thank you very much for the features given, in your next post.

The thing is, I have no stops set at all (averaging). And why this error is not present when I start the terminal in the morning and modification occurs, but only present (error) at the beginning of the session when opening an order (daily charts) and if it is one on a pair. The technical support has replied that there are no limitations for this modification either in time or distance (the spread is not important).

I will try to do some experiments with all recommendations and I will draw my conclusions later.

Thank you very much once again.

 
Vitalie Postolache:

The difference is that my namesake also multiplies by Point for some reason:(OrderCommission()/(tv*OrderLots()))*Point()

OK, I'll answer: There is a price of 1.0520, in calculations we got the number (int)Comm, then we need to add / subtract it from the price = 1.0520 + (int)Comm ? Now, in order not to multiply by Point - this is done immediately.

 
Youri Lazurenko:


Thank you very much for the features given, in your next post.

The thing is, I don't have stops (averaging) set at all. And why this error is not present when I start the terminal in the morning and modification occurs, but only present (error) at the beginning of the session when opening an order (daily charts) and if it is one on a pair. The technical support has replied that there are no limitations for this modification either in time or distance (the spread is not important).

I will try to do some experiments with all recommendations and I will draw my conclusions later.

Thank you very much once again.

You're welcome.

To use it this way: In the function of position opening, instead of the stop in pips, copy the function call, in which you place the stop in pips. Or the stop price should be entered directly - the compiler will select the required function. The same for take profit.

Example:

double price=SymbolInfoDouble(Symbol(),SYMBOL_ASK);         // Цена открытия для Buy
double sl=CorrectStopLoss(Symbol(), OP_BUY, price, 200);    // Стоп в 200 пунктов (вместо пунктов можно вписать расчётную цену, например Ask+200*Point() или значение цены МА)
double tp=CorrectTakeProfit(Symbol(), OP_BUY, price, 300);  // Тейк в 300 пунктов (если вписать расчётную цену, то будет использоваться тип функции с double-параметром)
OrderSend(Symbol(),OP_BUY,Lots,price,slippage,sl,tp,"Комментарий ордера",Magic,0,clrBlue);
 
Vitaly Muzichenko:

OK, I'll answer: There is a price of 1.0520, in calculations we got the number (int)Comm, then we need to add / subtract it from the price = 1.0520 + (int)Comm ? Now, in order not to multiply by Point - this is done immediately.


Well, then maybe so. It's just that the question was originally posed how to translate the commission into pips, not into price.
 
Artyom Trishkin:

You're welcome.

Use this way: In the function to open a position instead of the stop in pips, type the call of the function in which you want to substitute the stop in pips. Or the stop price should be entered directly - the compiler selects the required function. The same for take profit.

Example:

Once again, thank you very much. All the best.
 
Please advise Dear Sirs: I draw Fibonacci lines with different colours and style levels and always set the same as the last one, how to fix it?

                  ObjectCreate(0,Fibo_Arrow,OBJ_FIBO,0,Time[0],Close[0],Time[0],price); // создание метки стпа на графике   
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_HIDDEN,true);        // Запрет на показ имени графического объекта в списке объектов 
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_SELECTABLE,false);   // запрет на выделение перемещение объекта мышью   
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_RAY_RIGHT,false);    // луч вправо
                  ObjectSetString(0,Fibo_Arrow,OBJPROP_TOOLTIP,"r\n");       // подпись линии и и её длины в подсказку                  
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_COLOR,1,clrNONE);       // цвет   
                  
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELS,3);           // установим количество уровней   
                      
                  ObjectSetDouble(0,Fibo_Arrow,OBJPROP_LEVELVALUE,0,1.5);  // значение уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELCOLOR,0,Green);  // цвет уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELSTYLE,0,2);     // стиль уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELWIDTH,0,0);     // толщина уровня 
                  ObjectSetString(0,Fibo_Arrow,OBJPROP_LEVELTEXT,0,"0.5"); // описание уровня 
                  
                  ObjectSetDouble(0,Fibo_Arrow,OBJPROP_LEVELVALUE,1,2);  // значение уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELCOLOR,1,Lime);  // цвет уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELSTYLE,1,0);     // стиль уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELWIDTH,1,0);     // толщина уровня 
                  ObjectSetString(0,Fibo_Arrow,OBJPROP_LEVELTEXT,1,"1"); // описание уровня 
                  
                  ObjectSetDouble(0,Fibo_Arrow,OBJPROP_LEVELVALUE,2,2.5);  // значение уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELCOLOR,2,Green);  // цвет уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELSTYLE,2,2);     // стиль уровня       
                  ObjectSetInteger(0,Fibo_Arrow,OBJPROP_LEVELWIDTH,2,0);     // толщина уровня 
                  ObjectSetString(0,Fibo_Arrow,OBJPROP_LEVELTEXT,2,"1.5"); // описание уровня 
 
Money_Maker:
Dear Experts, please advise: I build Fibonacci lines with different colour and style of levels, but always set the same as the last one, how to fix? redraw and slip is not helpful in any place(

Fibo levels with this object, you can't make different styles and colours for each line. Draw separate lines if you want a rainbow.