11-12-2005, 12:41 AM
Senior Member
Join Date: Oct 2005
Posts: 994
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?
11-15-2005, 12:11 PM
Member
Join Date: Oct 2005
Location: Athens
Posts: 75
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.
11-15-2005, 06:22 PM
Senior Member
Join Date: Oct 2005
Posts: 994
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''.
11-16-2005, 05:57 PM
Member
Join Date: Oct 2005
Posts: 35
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 !
11-17-2005, 12:28 AM
Senior Member
Join Date: Oct 2005
Posts: 994
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.
11-30-2005, 01:29 AM
Senior Member
Join Date: Oct 2005
Posts: 994
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?
12-06-2005, 07:05 AM
Junior Member
Join Date: Nov 2005
Posts: 16
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
12-06-2005, 07:18 AM
Member
Join Date: Oct 2005
Location: Athens
Posts: 75
Triggerlines Alert
Dear CodersGuru, can we hv an alert when this indicator changes colour pls??
12-06-2005, 02:29 PM
Senior Member
Join Date: Oct 2005
Posts: 994
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 = loopbegin ; shift >= 0 ; shift --) // MAIN For Loop { sum [ 1 ] = 0 ; for( i = length ; i >= 1 ; i --) //LSMA loop { lengthvar = length + 1 ; //lengthvar = 21 lengthvar /= 3 ; //lengthvar = 7 tmp = 0 ; tmp = ( i - lengthvar )* Close [ length - i + shift ]; //tmp = 20 - 7 * close[20-i+shift] sum [ 1 ]+= tmp ; } wt [ shift ] = sum [ 1 ]* 6 /( length *( length + 1 )); j = 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 ; } } //+------------------------------------------------------------------+
12-06-2005, 03:17 PM
Member
Join Date: Oct 2005
Location: Athens
Posts: 75
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 = loopbegin ; shift >= 0 ; shift --) // MAIN For Loop
{
sum [ 1 ] = 0 ;
for( i = length ; i >= 1 ; i --) //LSMA loop
{
lengthvar = length + 1 ; //lengthvar = 21
lengthvar /= 3 ; //lengthvar = 7
tmp = 0 ;
tmp = ( i - lengthvar )* Close [ length - i + shift ]; //tmp = 20 - 7 * close[20-i+shift]
sum [ 1 ]+= tmp ;
}
wt [ shift ] = sum [ 1 ]* 6 /( length *( length + 1 ));
j = 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 ;
}
}
//+------------------------------------------------------------------+
TKS VM INDEED AGAIN YOUR ALWAYS VALUABLE ASSISTANCE.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT. The time now is 11:03 AM .