Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-26-2007, 09:17 PM
Junior Member
 
Join Date: Jan 2007
Posts: 26
echnaton is on a distinguished road
Although both MA lines are equal Orders where made

Hello,

although both Moving Average lines are equal an order where send by my script. But I donīt wants this.

Here some code:

PHP Code:
//Crossed function for example
int Crossed (double line1 double line2)
{
      static 
int last_direction 0;
      static 
int current_direction 0;
            
      if(
line1==line2)return (0); 

      if(
line1>line2)current_direction 1//up
      
if(line1<line2)current_direction 2//down
      
      
if(current_direction != last_direction//changed 
      
{
            
last_direction current_direction;            
            return (
last_direction);
      }
      else
      {
            return (
0);
      }
}


//Call of the function inside start() 

SEma iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1); 
LEma iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_CLOSE,1);  

   
int isCrossed  0;
   
isCrossed Crossed(SEma,LEma); 


if(
isCrossed == 1)
   {
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,Name_Expert,MAGIC,0,Green);
return(
0);
   }  
         
   if(
isCrossed == 2)
   {   
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,Name_Expert,MAGIC,0,Red);
return(
0);
   } 
Although both Moving Average lines are equivalent high often simply an order are made.

I understand that not, can me someone help?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2007, 11:12 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
Try replacing
PHP Code:
if ( line1 == line2 ) return ( ); 
with
PHP Code:
if ( MathAbsline1 line2 ) < Point ) return ( ); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 03-16-2007, 07:36 PM
Junior Member
 
Join Date: Jan 2007
Posts: 26
echnaton is on a distinguished road
Hello,

I have test it and your tip was right, thank you very much!

but I donīt now why

PHP Code:
if ( line1 == line2 ) return ( ); 
was not right.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 03-16-2007, 11:56 PM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 297
ralph.ronnquist is on a distinguished road
It has to do with "precision".

The double number representation is 64 bits, which makes it very high precision (though not mathematically exact).
Lines on the screen are limited by the screen resolution, which is of the order of 10 bits.
Obviously when plotting two double numbers onto the screen, you might need to put them on the same pixels even if the numbers are different.

As a rule of thumb, double numbers that are computed by different calculations very rarely end up equal, even when you think they should; very, very small differences (down to 20:th decimal or so), but enough for "==" to say false.

By your test, the lines were required to be equal to the highest precision offered by the representation, while by my suggestion, they are only required to be equal to a Point precision.

Perhaps you would really want "Point*Period/6" or something since the idea of MA lines "being equal" might also depend on the chart time frame; on an hourly time frame, perhaps being within 10 pips of each other is equal enough to be considered equal?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
modify orders and close pending orders bkgridley Questions 8 05-23-2007 10:49 PM
Is 1 lot in 1:10 equal to 0.1 lot in 1:100 leverage ? mpforex Metatrader 4 3 03-24-2007 11:06 AM
Need an indicator made hidethereal Indicators - Metatrader 4 12 09-28-2006 07:10 PM
What's going on? Demo shows I made a *ton* of money ycomp Metatrader 4 2 03-31-2006 02:01 AM


All times are GMT. The time now is 01:18 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.