Get Range of Stop Loss Automatically

 

Hi,


I try to code EA that can automatically get range of stoploss, but still not work. 

Here is my code, please help !


//-------------------------------------------------------------------+
//Get Range of Stop Loss  
//-------------------------------------------------------------------+
double GetSLPip() {
  
  // MQL Get Current Price.
  // Get Ask and Bid of the current pair with MarketInfo 
  // and save the values in variables.
   double PriceAsk = MarketInfo(Symbol(), MODE_ASK);
   double PriceBid = MarketInfo(Symbol(), MODE_BID);
   

 
  int slx =0; 
    
   // Counting Pips for SL Value 
   double HighSL  = High[1]+ HLPlusPoin*pt; 
   double LowSL   = Low[1] - HLPlusPoin*pt; 
   double pipSLB  = HighSL - Close[1];
   double pipSLS  = Close[1] - LowSL ;


   double BDiffPips = MathAbs(NormalizeDouble(HighSL-Ask,Digits)/Point);
   double SDiffPips = MathAbs(NormalizeDouble(Bid-LowSL,Digits)/Point);
   
   
   double pricex=Ask;
   
   
   
   for(int k=0; k>=0; k++)          
     {
      if (pricex>Low[1])  
         
         { slx+= BDiffPips; }           
      
      if (pricex<High[1])

         { slx+= SDiffPips; }
         
     }

                   
   return(slx);
}
 
ARAsyah:

Hi,


I try to code EA that can automatically get range of stoploss, but still not work. 

Here is my code, please help !


Range of stoploss for what? Opened positions? 
 
ARAsyah: I try to code EA that can automatically get range of stoploss, but still not work.
  1. Stop loss is a price not a range. Question makes no sense.

  2. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004
              When asking about code

  3. Your loop makes no sense to me. Until you can state what you want in concrete terms, it can not be coded.

  4. You have an infinite loop.

 
Navdeep Singh:
Range of stoploss for what? Opened positions? 

i want to   auto calculated  open lot with fix risk% from balance, i need to find range pips to get lot  


here is my another code to combined with get range function 


 

// To Compute a lot

   RefreshRates();
   
   double price=Ask;
   double SLos = NormalizeDouble(price-GetSLPip()*Point, _Digits);  



   if (Use_MM_Auto_Lot) lots1 = MMComputeRisk(RiskTrade, MathAbs(price-SLos), BrokerComm);              //Open AutoLot Function



//--------------------------------------------------------------------------------------------------------------
int GetSLPip()
{

   int pips = 0;
   double p = 0;
   double delta=50;
   
   for (int i=0; i<=delta; i++)
   {
       // Counting Pips for SL Value 
   double HighSL  = MathAbs (High[1]+3*Point); 
   double LowSL   = MathAbs (Low[1]-3*Point) ; 
   double pipSLB  = MathAbs (Open[0]-LowSL);
   double pipSLS  = MathAbs (HighSL - Open[0]);

                      
               
            if (Close[1]>Open[2])
            {
               p = MathAbs (Open[0]-LowSL) / Point;
               //pips = pips + NormalizeDouble(p,0);
               pips++;
            }
            
            if (Close[1]<Open[2])
            {
               p = MathAbs (HighSL - Open[0])/ Point;
               //pips =  pips + (NormalizeDouble(p,0));
               pips++;
              
            }        
        
       
   }   
   Print("Error Get SL Pips : ",GetLastError()); 
   return(pips);
}



//------------------------------------------------------------------- 

double MMComputeRisk(double RiskPercent, double sl, double comm)
{

   double MMBalance, MMRiskMoney;
   double MMMaxLot=MarketInfo( _Symbol, MODE_MAXLOT );
   double MMMinLot=MarketInfo( _Symbol, MODE_MINLOT );
   double MMLotStep= MarketInfo( _Symbol, MODE_LOTSTEP ); 
   double MMTickValue = MarketInfo( _Symbol, MODE_TICKVALUE);
   double MMTickSize = MarketInfo( _Symbol, MODE_TICKSIZE);
   
   int lotdigits=0;
   do
   {
      lotdigits++;
      MMLotStep*=10;
   }while(MMLotStep<1);
   
   MMBalance = MathMin(AccountBalance(), AccountEquity());
   MMRiskMoney=MMBalance*RiskPercent/100;
   double lot = MMRiskMoney / ( sl * ( MMTickValue / MMTickSize ) + comm );
   lot=NormalizeDouble( MathFloor(lot*MathPow(10,lotdigits))/MathPow(10,lotdigits), lotdigits );
   if( lot > MMMaxLot ){ lot=MMMaxLot; }
   if( lot < MMMinLot ){ lot=MMMinLot; }

   return NormalizeDouble( lot, lotdigits );
   
}

   
 
ARAsyah:

i want to   auto calculated  open lot with fix risk% from balance, i need to find range pips to get lot  


here is my another code to combined with get range function 


 

 with this code i get error >>> Get SL Pips = 0 


i try another code function to get range in pips (GetSLPips) than first code of this topic 

what error of this code? i still dont get fixed of this