How do I solve this? please help me - page 2

 
Courage Adjetey #:

 Dear members,

how can i prevent a value from increasing or decreasing in Mql5?

The problem is, i want to calculate a "Stoploss" size that wont change even after modifying the SL price 


Or 

If there is a way to access the Initial Stoploss price because apparently HistoryOrderGetDouble(ticket,ORDER_SL) keep returning  0.

it will be very appreciated if this problem can be solved or if there is a work around of this problem because i have been on this for a while. Thanks in advance.

Post your code 

 

Search here for trailing EA and then choose CodeBase or Articles for a deeper insight: https://www.mql5.com/en/search#!keyword=trailing%20ea.

The results are mixing MT4 and MT5, select what you need.

 

Carl Schreiber #:

Search here for trailing EA and then choose CodeBase or Articles for a deeper insight: https://www.mql5.com/en/search#!keyword=trailing%20ea.

The results are mixing MT4 and MT5, select what you need.


Thanks for your time and effort Carl Schreiber:

My goal is to use SL size/points which is not hard coded as reference for trailing the SL price.

That means i should be able to make reference to the Initial SL at any time of the open position

but i am yet to see anything of that sort on the forum, articles and code base.   

 
Ugochukwu Mobi #:

Post your code 

Carl Schreiber #:

Search here for trailing EA and then choose CodeBase or Articles for a deeper insight: https://www.mql5.com/en/search#!keyword=trailing%20ea.

The results are mixing MT4 and MT5, select what you need.

Ugochukwu Mobi #:

Post your code 

Here is the code, HistoryOrderGetDouble(ticket,ORDER_SL) keeps returning 0

#include <Trade/Trade.mqh>
#include <Trade/PositionInfo.mqh>

CTrade trade;
CPositionInfo position;

   ulong ticket = PositionSelect(_Symbol);
   
   double slprice = NormalizeDouble( HistoryOrderGetDouble(ticket,ORDER_SL),1);
   
   double openprice = position.PriceOpen();
   
   double SL_size(double openprice, double slprice)
  
  {
    
      ulong ticket = PositionSelect(_Symbol);
     
      openprice = position.PriceOpen();
      slprice =  NormalizeDouble( HistoryOrderGetDouble(ticket,ORDER_SL),1);
      
      double slsize = NormalizeDouble(MathAbs(openprice - slprice)/_Point,1);
      
      
    
      return(slsize);
        
      
 }
     
   

void OnTick()
  {
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits);
     
     if (PositionsTotal()<1)
        trade.Buy(0.10, NULL,Ask,(Ask-100 * _Point));
        
        double slpoints = SL_size(openprice,slprice );
      
        ulong ticket = PositionGetInteger(POSITION_TICKET);
      
        Print("slprice"" ",slprice);
        Print("slpoints" " ",  slpoints);
        Print("ticket"" ",ticket);
   
     
  }