Scalping lot calc.. Alittle lost

 

Hello!

I've tried to knock together a quick lot calc that takes the the current bar High/Low difference and divides it against 3% of your free margin..

However i'm getting unexpected results & I cant seem to work out why... It would seem that the Bid-lo & hi-Bid return results with many 0s in the decimal places


I'm sure its simple but if someone could point me in the right direction there will be love :]


#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window

int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   double hi, lo, diffa, diffb;
   int i;
   hi=iHigh(NULL,0,0);
   lo=iLow(NULL,0,0);
   diffa=(AccountFreeMargin()*0.03)/Bid-lo;
   diffb=(AccountFreeMargin()*0.03)/hi-Bid;
   if (Symbol()=="USDJPY") i=3; else i=5;
   Comment("High: "+DoubleToStr(hi, i)+"     Low: "+DoubleToStr(lo, i)+"      Lot(L): "+DoubleToStr(diffa, 2)+"    Lot(S): "+DoubleToStr(diffb, 2));
//----
   return(0);
  }
 

Looks like its caused by your not supplying the correct parameters to the candle calls.

Try replacing:

hi=iHigh(NULL,0,0);
lo=iLow(NULL,0,0);

with:

hi=iHigh(Symbol(),Period(),0);
lo=iLow(Symbol(),Period(),0);

which will give you data for current symbol and period or you can substitute alternative symbols/periods.


Or - if you are happy to limit yourself to current symbol/period then:

hi=High[0];

lo=Low[0];


CB

 
cloudbreaker:

Looks like its caused by your not supplying the correct parameters to the candle calls.

Try replacing:

with:

which will give you data for current symbol and period or you can substitute alternative symbols/periods.


Or - if you are happy to limit yourself to current symbol/period then:

hi=High[0];

lo=Low[0];


CB

Hi ya,


Ty for the reply, the Symbol() & Period() addition was the same as null and 0 unfortunately :[ I've noticed when the sum is returned it's not a whole number. e.g 0.00070

So dividing it with the free margin causes incorrect calculations... (I assume)


Any ideas welcome!

 
Bump
 
Skitch wrote >>
Bump

1.)

diffa=(AccountFreeMargin()*0.03)/(Bid-lo);

2.)

if (Bid == lo )

MakeSomething();

or

if (Bid-lo ==0)

WhatNow();

....

3.) Maybe you need:

diffa=(AccountFreeMargin()*0.03)*Point/(Bid-lo);

Reason: