Code for risk per trade? - page 3

 

Hello 1005phillip, If you are still around this forum. Thank you for your instructions and code that you provided to calculate correct investments for cross currencies. Is it possible to use your code to open various cross currencies from one major currency chart or do the  cross currencies always have to be the current chart for your code to open the cross currencies? Please advise if you will.

 

If 1005phillip is no longer around this forum. Would anyone else know how to open various cross currencies from one major currency chart?

 

Best regards

 
Deuteronomy818:

If 1005phillip is no longer around this forum. Would anyone else know how to open various cross currencies from one major currency chart?

Best regards

1) You'd better have opened a new thread

2) What exactly do you mean with "open various crosseds .."?

a) open a new chart => ChartOpen() (look it up in the reference)

b) Request quotes from other symbols than the chart symbol => iOpen(), iClose(), ... (as well in the reference)

 
Thank you for the suggestion Gooly. I was referring to Phillip's automated lot calculation code for an EA. Best regards
 
double fLots(double dPourcentageRisque,int  iStop)
 {
    double dRisqueMax =(dPourcentageRisque/100)* AccountBalance();

    double dValeurPip = MarketInfo(Symbol(), MODE_TICKVALUE);
  if(Point == 0.001 || Point == 0.00001)
      {

          dValeurPip = dValeurPip *  10;
       }
  double dLots =(dRisqueMax / iStop) / dValeurPip;
  
  if(dLots< MarketInfo(Symbol(),MODE_MINLOT))

        dLots= MarketInfo(Symbol(),MODE_MINLOT);

  if(dLots> MarketInfo(Symbol(),MODE_MAXLOT))

     dLots= MarketInfo(Symbol(),MODE_MAXLOT);
  if(MarketInfo(Symbol(),MODE_LOTSTEP) == 0.01)

       dLots = NormalizeDouble(dLots,2);
  else 
       dLots= NormalizeDouble(dLots,1);
  
return(dLots);
  } 


 

Hi guys, sorry to bring this thread up again.


I'm currently running this few lines for my lot sizing, and after adding these lines, I'm getting to 4051 error. Check if it's my code that is causing it? Because without it, I don't have that issue.


input bool isSizingOn = true;   // Auto Lot Sizing
input int Risk = 1;  // Risk level (%)

int OnInit(){
   if(Digits == 5 || Digits == 3 || Digits == 1)P = 10;else P = 1; // To account for 5 digit brokers
   if(Digits == 3 || Digits == 2) isYenPair = true; // Adjust for YenPair
   
   if (isSizingOn == true) 
      {
         Lots = Entry_Amount;
         Lots = Risk * 0.01 * AccountBalance() / (MarketInfo(Symbol(),MODE_LOTSIZE) * Stop_Loss * P * Point); // Sizing Algo based on account size
         if(isYenPair == true) Lots = Lots * 100; // Adjust for Yen Pairs
         Lots = NormalizeDouble(Lots, 2); // Round to 2 decimal place
      }
}


Thanks!

Reason: