Forex
Google

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


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
 
LinkBack (2) Thread Tools Display Modes
  #21 (permalink)  
Old 11-11-2005, 11:41 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Lightbulb Wait!

Quote:
Originally Posted by ferman
Hi,

can you explain, how to work with the backtesting ?
what is needed to do for preparing our EA for backtesting ?
how is backtesting works (every tick, open price ...) ?


thanks.
Hi ferman,

Could you wait for backtesting lesson very soon!
I hope you red the previous lessons?
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #22 (permalink)  
Old 11-15-2005, 11:11 AM
hua hua is offline
Member
 
Join Date: Oct 2005
Location: Athens
Posts: 75
hua is on a distinguished road
Disable alert once hit.

ONE VITAL QUESTION.
In case for an alert in EA, we can mark ''disable alert once hit''.
how we can do that on indicator alerts???
Many tks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23 (permalink)  
Old 11-15-2005, 05:22 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow

Quote:
Originally Posted by hua
ONE VITAL QUESTION.
In case for an alert in EA, we can mark ''disable alert once hit''.
how we can do that on indicator alerts???
Many tks in advance.
Hua,

Please refer to my reply here.

I can make a demo for you if you want, Please tell me the indicator you want to add to ''disable alert once hit''.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24 (permalink)  
Old 11-16-2005, 04:57 PM
yaniv_av yaniv_av is offline
Member
 
Join Date: Oct 2005
Posts: 34
yaniv_av is on a distinguished road
Hi - a simple question (I hope...)

How can I code a time base exit command ?
I want to know the duration of an open position expresse by the number of bars that position already open.
Actually, I want to close a position automatically after 30 bars (in my expert-advisor)
How can I code that in mql4?

10X !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #25 (permalink)  
Old 11-16-2005, 11:28 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Talking BarsCountDown Function (by codersguru)

Quote:
Originally Posted by yaniv_av
How can I code a time base exit command ?
I want to know the duration of an open position expresse by the number of bars that position already open.
Actually, I want to close a position automatically after 30 bars (in my expert-advisor)
How can I code that in mql4?

10X !
Hi yanuv_av,

I'm so sorry for the delay in replaying you; I've spent all the day fixing my damn car to reach my office and reply your questions .

Now you have an EA and want to close the order after 30 bars (or whatever count you want), Right?

Well

Place this function on the top of start() function:

PHP Code:
bool BarsCountDown(int count)
   {
      
      static 
bool first_call true
      static 
int start_bar 0
      if(
first_call)
      { 
         
start_bar=Bars;
         
first_call=false;
      }
      if(
Bars == (start_bar+count))
      {
         Print(
"(TRUE) Bars= " Bars " : start_bars = " start_bar);
         
first_call=true;
         return (
true);
      }
      else
      {
         Print(
"(FALSE) Bars= " Bars " : start_bars = " start_bar);
         return (
false);
      }
      
      
   } 
How to use this function:

bool BarsCountDown(30);

The line above returns false if the current bar hasn't exceeded the number 30 from the first call of the function (the 30 bars not yet counted)

And returns true if the current bar has exceeded the 30 bars

So, when you get true, close the position

In your start() function you may use code like this:

PHP Code:
start()
{
  ....
  if(
BarsCountDwon(30))
  
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // close position
  
.....

I hope you've got it.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #26 (permalink)  
Old 11-30-2005, 12:29 AM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Unhappy Worked?

Quote:
Originally Posted by codersguru
Hi yanuv_av,

I'm so sorry for the delay in replaying you; I've spent all the day fixing my damn car to reach my office and reply your questions .

Now you have an EA and want to close the order after 30 bars (or whatever count you want), Right?

Well

Place this function on the top of start() function:

PHP Code:
bool BarsCountDown(int count)
   {
      
      static 
bool first_call true
      static 
int start_bar 0
      if(
first_call)
      { 
         
start_bar=Bars;
         
first_call=false;
      }
      if(
Bars == (start_bar+count))
      {
         Print(
"(TRUE) Bars= " Bars " : start_bars = " start_bar);
         
first_call=true;
         return (
true);
      }
      else
      {
         Print(
"(FALSE) Bars= " Bars " : start_bars = " start_bar);
         return (
false);
      }
      
      
   } 
How to use this function:

bool BarsCountDown(30);

The line above returns false if the current bar hasn't exceeded the number 30 from the first call of the function (the 30 bars not yet counted)

And returns true if the current bar has exceeded the 30 bars

So, when you get true, close the position

In your start() function you may use code like this:

PHP Code:
start()
{
  ....
  if(
BarsCountDwon(30))
  
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // close position
  
.....

I hope you've got it.
yanuv_av,

Did that work for you?
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #27 (permalink)  
Old 12-06-2005, 06:05 AM
alnasiradhikari alnasiradhikari is offline
Junior Member
 
Join Date: Nov 2005
Posts: 14
alnasiradhikari is on a distinguished road
Question ema cross

Hello,
First of all I am very imprest with this site and also with coder, who is helping us to test and make difference code

I am looking to have a code to open and close my position with the following deffination

ema = 3
ema = 13
when ema 3 cross from down to ema 13 plus move 5 pips up, the order will open automatically eample ema 3 and ema 13 cross at 1.1705 for euro/usd my order will be open at 1.1710 it is something like bunnygirl system but I dont know how to make expert please help me.

same technique for selling but all technique reverse

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #28 (permalink)  
Old 12-06-2005, 06:18 AM
hua hua is offline
Member
 
Join Date: Oct 2005
Location: Athens
Posts: 75
hua is on a distinguished road
Triggerlines Alert

Dear CodersGuru, can we hv an alert when this indicator changes colour pls??
Attached Files
File Type: mq4 Triggerlines.mq4 (3.6 KB, 118 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #29 (permalink)  
Old 12-06-2005, 01:29 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Arrow Trigger Line

Quote:
Originally Posted by hua
Dear CodersGuru, can we hv an alert when this indicator changes colour pls??
Dear hua,

Please try this:

PHP Code:
//+------------------------------------------------------------------+
//|                                                     Trigger Line |
//|                             Copyright © 2005 dwt5 and adoleh2000 |
//|                                     http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005 dwt5 and adoleh2000 "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 4            
#property indicator_color1 Red      
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int width;

extern int Rperiod 15;
extern int LSMA_Period 5;
int Draw4HowLong;
int shift;
int i;
int j;
int loopbegin;
int length;
int lsma_length;

double lengthvar;
double tmp ;
double tmp2 ;
double wt[];
double sum[];
double lsma_sum[];
double lsma_ma[];
double middle[];
int c;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 7 additional buffers are used for counting.
   
IndicatorBuffers(7);   
   
//---- drawing settings
   
   
SetIndexBuffer(0,ExtMapBuffer1);
   
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   
   
SetIndexBuffer(1,ExtMapBuffer2);
   
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   
   
SetIndexBuffer(2,ExtMapBuffer3);
   
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   
   
SetIndexBuffer(3,ExtMapBuffer4);
   
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);
   
   
   
   
SetIndexBuffer(4,sum);        
   
SetIndexBuffer(5,wt);         
   
SetIndexBuffer(6,lsma_ma);
   
//---- initialization done
   
return(0);
  }

int start()

 { 
Draw4HowLong Bars-Rperiod 5;                         //Rperiod = 20
     
length Rperiod;                                         //length now = 20 
      
lsma_length LSMA_Period;
      
loopbegin Draw4HowLong length 1;   
      

      for(
shift loopbeginshift >= 0shift--)  //  MAIN For Loop
      

         
sum[1] = 0;                                             
         for(
length>= i--)             //LSMA loop
         
{
         
lengthvar length 1;                             //lengthvar = 21 
         
lengthvar /= 3;                                     //lengthvar = 7
         
tmp 0;
         
tmp = ( lengthvar)*Close[length-i+shift];         //tmp = 20 - 7 * close[20-i+shift]
         
sum[1]+=tmp;
         }
         
wt[shift] = sum[1]*6/(length*(length+1));  
         
shift;
         
lsma_ma[shift] = wt[j+1] + (wt[j]-wt[j+1])* 2/(lsma_length+1);
  
                         
//========== COLOR CODING ===========================================                     
        
        
            
ExtMapBuffer1[shift] = wt[shift]; 
            
ExtMapBuffer2[shift] = lsma_ma[shift]; 
            
ExtMapBuffer3[shift] = wt[shift]; 
            
ExtMapBuffer4[shift] = lsma_ma[shift]; 
            
            
            
            if (
wt[shift]  < lsma_ma[shift])
            {
                
//Alert("color changed");
                
ExtMapBuffer4[shift] = EMPTY_VALUE;
                
ExtMapBuffer3[shift] = EMPTY_VALUE;
           }          
        
        }
        
        
// Alerts on color change
        // added by codersguru - www.forex-tsd.com

        
static string last_clr "";
        
string current_clr;
        static 
bool first_time false;
        
        if (
first_time)
        {
         if (
wt[0]  < lsma_ma[0])
            
current_clr="Red";
         if (
wt[0]  > lsma_ma[0])
            
current_clr="Blue";
        
         if(
last_clr != current_clr//changed 
          
{
             
last_clr current_clr;
             
Alert("changed : current color is " current_clr);
          }
         }
         else
         {
            
first_time true;
         }
         
  }
//+------------------------------------------------------------------+ 
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #30 (permalink)  
Old 12-06-2005, 02:17 PM
hua hua is offline
Member
 
Join Date: Oct 2005
Location: Athens
Posts: 75
hua is on a distinguished road
Quote:
Originally Posted by codersguru
Dear hua,

Please try this:

PHP Code:
//+------------------------------------------------------------------+
//|                                                     Trigger Line |
//|                             Copyright © 2005 dwt5 and adoleh2000 |
//|                                     http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005 dwt5 and adoleh2000 "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 4            
#property indicator_color1 Red      
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int width;

extern int Rperiod 15;
extern int LSMA_Period 5;
int Draw4HowLong;
int shift;
int i;
int j;
int loopbegin;
int length;
int lsma_length;

double lengthvar;
double tmp ;
double tmp2 ;
double wt[];
double sum[];
double lsma_sum[];
double lsma_ma[];
double middle[];
int c;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 7 additional buffers are used for counting.
   
IndicatorBuffers(7);   
   
//---- drawing settings
   
   
SetIndexBuffer(0,ExtMapBuffer1);
   
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   
   
SetIndexBuffer(1,ExtMapBuffer2);
   
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   
   
SetIndexBuffer(2,ExtMapBuffer3);
   
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   
   
SetIndexBuffer(3,ExtMapBuffer4);
   
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);
   
   
   
   
SetIndexBuffer(4,sum);        
   
SetIndexBuffer(5,wt);         
   
SetIndexBuffer(6,lsma_ma);
   
//---- initialization done
   
return(0);
  }

int start()

 { 
Draw4HowLong Bars-Rperiod 5;                         //Rperiod = 20
     
length Rperiod;                                         //length now = 20 
      
lsma_length LSMA_Period;
      
loopbegin Draw4HowLong length 1;   
      

      for(
shift loopbeginshift >= 0shift--)  //  MAIN For Loop
      

         
sum[1] = 0;                                             
         for(
length>= i--)             //LSMA loop
         
{
         
lengthvar length 1;                             //lengthvar = 21 
         
lengthvar /= 3;                                     //lengthvar = 7
         
tmp 0;
         
tmp = ( lengthvar)*Close[length-i+shift];         //tmp = 20 - 7 * close[20-i+shift]
         
sum[1]+=tmp;
         }
         
wt[shift] = sum[1]*6/(length*(length+1));  
         
shift;
         
lsma_ma[shift] = wt[j+1] + (wt[j]-wt[j+1])* 2/(lsma_length+1);
  
                         
//========== COLOR CODING ===========================================                     
 &