Zero Divide (Found the issue - but why?) - page 3

 
double loss_for_1_lot = pips_to_bsl/ ts * tv ;

It is NOT tv that results in a div 0. it can only be ts. On a 5 digit broker ts might print zero (4 digits)

Sounds to me like you never opened that pair to get the market info from your broker before downloading history from somewhere else.

 

I find it difficult to believe the zero divide is generated by the code posted.

DomGilberto compile this script and attach it to the chart you believe is returning a zero ticksize.

int start()
  {
//----
   int i = Bars-1;
   int cnt;
   int tscnt = 0;
   int tvcnt = 0;
   double ts = MarketInfo(Symbol(), MODE_TICKSIZE);
   double tv = MarketInfo(Symbol(), MODE_TICKVALUE);
   while(i >=0)
   {if(ts < 0.00001) tscnt++;
    if(tv < 0.00001) tvcnt++;
    i--;
   }
   Alert("TickSize returned an erroneous value ",tscnt," times.");
   Alert("TickValue returned an erroneous value ",tvcnt," times.");
//----
   return(0);
  }
 
DomGilberto:

I'm hoping this video I've made (40 seconds or so) illustrates what I am talking about ( as I am not sure if I am making it clear or not ).

Video: http://screencast.com/t/uMHY5DpM

You will see that the first part when I drop the script onto the live chart (real account) that the tick value and tick size return "0" on that "notional account", which I illustrate in the lots window (units).

The second part is with the same broker but on a lot based feed and this time it returns a tick value and tick size. Again, I illustrate that you trade using lots....

So with regards to the strategy tester, I have no idea why it has been working and sometimes it doesn't. The account has been connected whilst I run the back-tests too (on a demo notional fed account (units)).

My next question would be, if this is the typical response I will get from the notional fed account, are you able to suggest how I correct my position sizing calculation in this circumstance? It works perfectly for a lot based feed... Hope that explains it a little better?

If you are using different code in your "test" code then what does it prove ?

Are you aware that TICKVALUE returns the current value from now . . . even during a Strategy Test run ? so for any pair where the base currency isn't the deposit currency it will be incorrect and your lot calculations will be wrong . . .

 

In your video, you use GBPUSD in the first instance and then GBPJPY in the second.

I think that if you had attached your script to a GBPUSD normal lot chart, you would get a value for tickvalue, but ticksize would also be zero.

This is because your script alerts are using doubles and so 0.00001 will print as 0.

Use DoubleToStr(MarketInfo(Symbol(),MODE_TICKVALUE),8) instead

 

Ok firstly, thanks for everyone's help.

Here is the video for "Gumrai" and "SDC" confirming what you're both asking me to do. I have labelled the scripts with your MQL4 aliases, which obviously correspond to your code you've posted here. Video: http://screencast.com/t/kglCd2hCae

The broker and the corresponding feed was not changed during the pause. It is a notional feed account too (units).

@RaptorUK: Yea I knew that TICKVALUE returned the current value from now. I guess your second part looking at it now is kind of logical. I'm getting confused with how I am able to utilise tickvalue as part of my notional feed account to make sure the position sizing is correct...?

 
DomGilberto:

Ok firstly, thanks for everyone's help.

Here is the video for "Gumrai" and "SDC" confirming what you're both asking me to do. I have labelled the scripts with your MQL4 aliases, which obviously correspond to your code you've posted here. Video: http://screencast.com/t/kglCd2hCae

The broker and the corresponding feed was not changed during the pause. It is a notional feed account too (units).

@RaptorUK: Yea I knew that TICKVALUE returned the current value from now. I guess your second part looking at it now is kind of logical. I'm getting confused with how I am able to utilise tickvalue as part of my notional feed account to make sure the position sizing is correct...?


Those videos are a pain, they are too big for my screen.

Why not just post the script code and the alert result.

I don't know what you put into the script that was supposed to be my suggested code, but there is no way that it can result in "08"

Use

Alert("TICKVALUE= ",DoubleToStr(MarketInfo(Symbol(),MODE_TICKVALUE),8));
Alert("TICKSIZE= ",DoubleToStr(MarketInfo(Symbol(),MODE_TICKSIZE),8));
 
DomGilberto:


@RaptorUK: Yea I knew that TICKVALUE returned the current value from now. I guess your second part looking at it now is kind of logical. I'm getting confused with how I am able to utilise tickvalue as part of my notional feed account to make sure the position sizing is correct...?

First you have to confirm that TICKVALUE is indeed returning a zero result which you have not done yet.
 
GumRai:


Those videos are a pain, they are too big for my screen.

Why not just post the script code and the alert result.

I don't know what you put into the script that was supposed to be my suggested code, but there is no way that it can result in "08"

Use


Sorry - I realise now that I forgot to put "DoubleToStr" my bad!!

TickSize = 0.00100000

TickValue = 0.00001026

(Dropped on GBPJPY notional feed)

@SDC I simply copied your code from here and placed it into a new script. That's what was being returned.

 
Ok new update, I've played around with it repeating the precise place where the zero divide occurs.

This area in my code I have it printing out the formula to break down the maths - Where this is happening is on a BUY PENDING ORDER... yet this part of the code "pips_to_ssl" is pips to SELL stop loss... Which is NOT being used for a buy stop pending order....

double loss_for_1_lot1 = pips_to_ssl/  ts * tv  ;
   if( loss_for_1_lot1 == 0.0 )Print(" ERROR - loss_for_1_lot1 = 0.0 || The formula for this is: ", pips_to_ssl,"/",ts,"*",tv);


2013.10.02 11:57:19     2001.02.12 16:00  Trend Fishing - V1 - Notional Lots USDJPYnb,H1:  ERROR - loss_for_1_lot1 = 0.0 || The formula for this is: 0/0.001*0.0001

double pips_to_ssl=SellStopPrice-sellPrice;
   if(pips_to_ssl == 0)Print(" ERROR - pips_to_ssl = 0 || The formula for this is: ", SellStopPrice,"-",sellPrice); 

2013.10.02 12:08:01	2001.02.12 16:00  Trend Fishing - V1 - Notional Lots USDJPYnb,H1:  ERROR - pips_to_ssl = 0 || The formula for this is: 117.249-117.249

 
DomGilberto:
Ok new update, I've played around with it repeating the precise place where the zero divide occurs.

This area in my code I have it printing out the formula to break down the maths - Where this is happening is on a BUY PENDING ORDER... yet this part of the code "pips_to_ssl" is pips to SELL stop loss... Which is NOT being used for a buy stop pending order....



I refer you back to my earlier post

"Note that

double loss_for_1_lot = pips_to_bsl/ ts * tv ; //<<<<<<<<<<<<<<<<<<<<<<<<<<< This is giving me a "0" randomly sometimes?

will also result in zero if pips_to_bsl is zero. Is this possible?"

bsl or ssl, same coding.