Coding help - page 722

 
Tigra:


In this indicator, there are some problems when using the 4 digit quotes. But it is not critical, the problem is the scale at 4 digit to the level of 100, tried to show the pictures, looking at the right time is very straining your eyes (after a few days, whether as a thread to change the scale to the level of 40 - it would be better to be seen histograms and right corner of the text that would indicate the current value? 

 Оставлю оригинальный текст на русском, тк возможны искажения при переводе(

У этого индикатора есть некоторые проблемы при использовании 4 значных котировок. Но это не критично, самая проблемы это масштабирование на 4 значном до уровня 100, постарался показать на картинках, разглядывать нужный момент весьма напрягает глаза( после нескольких дней, можно ли как нить поменять масштаб до уровня 40 - что бы лучше было видно гистограммы и в правом углу текстом что бы обозначалось текущее значение? Еще не могу понять почему появляються черные гистограммы поверх при увеличении (

 

 

 

 

Isn't that the repainter?
 

Mladen, 

I'm working with MT5.

I have this "simple trailing function" that I need to convert to "trailing with step", could you give a tip?

in the EA I have
===================
input "Trailing"  (by points) 

=> example:
trailing:  4000  (4 points)
(old method) if priced moved 4points  move stoploss 4 points 

but I need to modify to

===================
input "Trailing (Distance) in points"
input "Trailing (Step) in points"

=> example: 
trailing distance:  4000  (4 points)
trailing step      :  1500  (1,5 points)

(new method) if priced moved 4points  move stoploss 1,5 points 

 

//+------------------------------------------------------------------+
//| Simple Trailing function                                         |
//+------------------------------------------------------------------+
void fSimpleTrailing(){
   if(Trailing<=0){
      return;
   }        
   if(!Pos.Select(_Symbol)){
      return;
   }        
   if(!Sym.RefreshRates()){
      return;  
   }  
   double nsl,tmsl,psl;  
   switch(Pos.PositionType()){
      case POSITION_TYPE_BUY:
         nsl=Sym.NormalizePrice(Sym.Bid()-_Point*Trailing);
            if(nsl>=Sym.NormalizePrice(Pos.PriceOpen())){
               if(nsl>Sym.NormalizePrice(Pos.StopLoss())){
                  tmsl=Sym.NormalizePrice(Sym.Bid()-_Point*Sym.StopsLevel());
                     if(nsl<tmsl){
                        Trade.PositionModify(_Symbol,nsl,Pos.TakeProfit());
                     }
               }
            }
      break;
      case POSITION_TYPE_SELL:
         nsl=Sym.NormalizePrice(Sym.Ask()+_Point*Trailing);
            if(nsl<=Sym.NormalizePrice(Pos.PriceOpen())){
               psl=Sym.NormalizePrice(Pos.StopLoss());
                  if(nsl<psl || psl==0){
                     tmsl=Sym.NormalizePrice(Sym.Ask()+_Point*Sym.StopsLevel());
                        if(nsl>tmsl){
                           Trade.PositionModify(_Symbol,nsl,Pos.TakeProfit());
                        }
                  }
            }      
      break;
   }
}
 
nbtrading:
Isn't that the repainter?

Yes, he recounts, but the color is not important in this indicator, for me it is very good shows out.
 
baraozemo:

Mladen, 

I'm working with MT5.

I have this "simple trailing function" that I need to convert to "trailing with step", could you give a tip?

in the EA I have
===================
input "Trailing"  (by points) 

=> example:
trailing:  4000  (4 points)
(old method) if priced moved 4points  move stoploss 4 points 

but I need to modify to

===================
input "Trailing (Distance) in points"
input "Trailing (Step) in points"

=> example: 
trailing distance:  4000  (4 points)
trailing step      :  1500  (1,5 points)

(new method) if priced moved 4points  move stoploss 1,5 points 

 

//+------------------------------------------------------------------+
//| Simple Trailing function                                         |
//+------------------------------------------------------------------+
void fSimpleTrailing(){
   if(Trailing<=0){
      return;
   }        
   if(!Pos.Select(_Symbol)){
      return;
   }        
   if(!Sym.RefreshRates()){
      return;  
   }  
   double nsl,tmsl,psl;  
   switch(Pos.PositionType()){
      case POSITION_TYPE_BUY:
         nsl=Sym.NormalizePrice(Sym.Bid()-_Point*Trailing);
            if(nsl>=Sym.NormalizePrice(Pos.PriceOpen())){
               if(nsl>Sym.NormalizePrice(Pos.StopLoss())){
                  tmsl=Sym.NormalizePrice(Sym.Bid()-_Point*Sym.StopsLevel());
                     if(nsl<tmsl){
                        Trade.PositionModify(_Symbol,nsl,Pos.TakeProfit());
                     }
               }
            }
      break;
      case POSITION_TYPE_SELL:
         nsl=Sym.NormalizePrice(Sym.Ask()+_Point*Trailing);
            if(nsl<=Sym.NormalizePrice(Pos.PriceOpen())){
               psl=Sym.NormalizePrice(Pos.StopLoss());
                  if(nsl<psl || psl==0){
                     tmsl=Sym.NormalizePrice(Sym.Ask()+_Point*Sym.StopsLevel());
                        if(nsl>tmsl){
                           Trade.PositionModify(_Symbol,nsl,Pos.TakeProfit());
                        }
                  }
            }      
      break;
   }
}
If price moved compared to : what?
 
mladen:
If price moved compared to : what?

before call the function you have

if price is "growing up" , you check the "distance" in points.. if it match the "distance" you move stoploss using step (in points)

example:

stoploss =8000
trailing distance = 4000
trailing step = 2000

you buy at price 10000

now price is 14000   (trailing distance target reached=4000) , now you need to move stoploss to 6000  (8000 - trailing step)

now price is 18000 (trailing distance target reached=4000 ), now you need to move stoploss to 2000 (6000 - trailing step)

now price is 22000 (trailing distance target reached=4000), now you need to move stoploss to "entrance" + 2000 (2000 - trailing step =-2000)

now price is 24000 (trailing distance target reached=4000), now you need to move stoploss to "entrance" + 6000 (-2000 - trailing step =-6000) 

 
baraozemo:

before call the function you have

if price is "growing up" , you check the "distance" in points.. if it match the "distance" you move stoploss using step (in points)

example:

stoploss =8000
trailing distance = 4000
trailing step = 2000

you buy at price 10000

now price is 14000   (trailing distance target reached=4000) , now you need to move stoploss to 6000  (8000 - trailing step)

now price is 18000 (trailing distance target reached=4000 ), now you need to move stoploss to 2000 (6000 - trailing step)

now price is 22000 (trailing distance target reached=4000), now you need to move stoploss to "entrance" + 2000 (2000 - trailing step =-2000)

now price is 24000 (trailing distance target reached=4000), now you need to move stoploss to "entrance" + 6000 (-2000 - trailing step =-6000) 

Yes, but if you do not have it recorded (as it is usually a case with the stop loss or take profit prices : when they get changed they start being a criteria for another change) you are forced to have that in variables and that is anything but error proof. What you are trying is not repeatable by the code or you have to hard code those stops for each and every case, which makes it unusable for any open price that is not exactly the same as the hard coded prices
 

Hi,

I would like to write a function that draw a arrow. I would like the arrow floating. Any idea? :)

void DrawArrow(string name, int IdSymbol, int x, int y, int width, int corner, color clr)
{
   ObjectCreate(0,name,OBJ_ARROW,0,0,0,0,0);
      ObjectSetInteger(0,name,OBJPROP_ARROWCODE,IdSymbol);
      ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
      ChartRedraw(0);
}

 
mladen:
Yes, but if you do not have it recorded (as it is usually a case with the stop loss or take profit prices : when they get changed they start being a criteria for another change) you are forced to have that in variables and that is anything but error proof. What you are trying is not repeatable by the code or you have to hard code those stops for each and every case, which makes it unusable for any open price that is not exactly the same as the hard coded prices

Hi mladen,

here is the sample-ea 

Files:
sample-ea.mq5  36 kb
 
Tartut:

Hi,

I would like to write a function that draw a arrow. I would like the arrow floating. Any idea? :)

void DrawArrow(string name, int IdSymbol, int x, int y, int width, int corner, color clr)
{
   ObjectCreate(0,name,OBJ_ARROW,0,0,0,0,0);
      ObjectSetInteger(0,name,OBJPROP_ARROWCODE,IdSymbol);
      ObjectSetInteger(0,name,OBJPROP_CORNER,corner);
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
      ChartRedraw(0);
}

What does the "floating" arrow mean?

PS: arrow objects are not using x and y coordinates or the corner. They are using time and price

 

hi mr mladen

please make MTF to it

regard

Reason: