Lesson 13 - Your First Expert Advisor (Part 1) - page 5

 
KelchMonteiro:
really thanks mladen!

I saw it now.

I did the same. take a look:

for_a_new_life-1.ex4

for_a_new_life-1_1.mq4

I was testing the mine version and will test the yours too.

If this indicator is correctly, we did some great to catch reversal points.

it's because the difference between the both moving averages divided by the 2times force, can show when price is reverting in a trend with more sensitivity. Test it with another border indicator and I think you'll like.

some pics:

I'm too glad because this is my first contribution to the forum. And I could not did it without your help.

Many thanks Mladen!

Kelch

Did just one change in it : change the direction of it. It seems that this way it is showing a bit more logical values. Try it out this way too

for_a_new_life-1.01.mq4

Files:
 

Hi Mladen,

I made EA from icustom after I compile it no error dan warning but I was Backtest no OP at all?

Can I post my EA in this thread I wolud like to your help to fix it.

Thank,

best regard

 
Dova:
Hi Mladen,

I made EA from icustom after I compile it no error dan warning but I was Backtest no OP at all?

Can I post my EA in this thread I wolud like to your help to fix it.

Thank,

best regard

Dova

Post it so someone will take a look at it

 
mladen:
Kelch

Did just one change in it : change the direction of it. It seems that this way it is showing a bit more logical values. Try it out this way too

for_a_new_life-1.01.mq4

Thanks mladen!

 

Here my trial ea...

This ea while compile is ok no error or warning but no OP when BT.

I would like to this ea can reverse from OP before,

sample if position already BUY than next candle SELL arrow is appear auto reverse Position from BUY to SELL and visa versa.

add Trailling Stop too.

Sorry for my bad english

pfi.ex4ea_pfi.mq4

Thank you

Files:
pfi.ex4  6 kb
ea_pfi.mq4  4 kb
 
Dova:
Here my trial ea...

This ea while compile is ok no error or warning but no OP when BT.

I would like to this ea can reverse from OP before,

sample if position already BUY than next candle SELL arrow is appear auto reverse Position from BUY to SELL and visa versa.

add Trailling Stop too.

Sorry for my bad english

pfi.ex4ea_pfi.mq4

Thank you

For the sake of the clarity of anybody reading that post : what does the "reverse from OP" or "no OP when BT" exactly mean?

 
mladen:
For the sake of the clarity of anybody reading that post : what does the "reverse from OP" or "no OP when BT" exactly mean?

I mean OP= Open Position, BT= Backtest.

After I backtest no open positions.

When there is already open position Buy then next candle sell arrows/signal appear automatically close long positions and open short positions and vice versa (auto reverse position).

I hope my explanatian make it clear..

Thank you

 

Greetings to all ....

forgive if wrong place, because of my new members .

please its support of the master coding ,

to be coding this indicator into EA .

with the intention of EA will be able to work as I wanted , namely :

1.Open automatic buy when price touches the line TL1 .

2.open automatically sell when price touches the line TL2

3.Open automatically buy when the price is over the line TL2

4.Open automatically sell when the price is over the line TL1

5.closed automatic buy when price touches the line TL2 proceed directly open sell

6.Closed automatically sell when price touches the line TL1 proceed directly open buy

7.nomor 3 and 4 closed manually ( without TrailingStop ) .

8.SL 50 pips and put on lot 0.1

9.Time frame H4 for all pairs .

thank you very much

/ / + ----------------------------------------------- ------------------- +

/ / | SHI_Channel_true.mq4 |

/ / | Copyright © 2004 , Shurka & Kevin |

/ / | |

/ / + ----------------------------------------------- ------------------- +

# property copyright " Copyright © 2004 , Shurka & Kevin "

# property link " "

/ / ----

# property indicator_chart_window

# property indicator_buffers 1

# property indicator_color1 Red

ExtMapBuffer1 double [ ] ;

/ / ---- Input parameters

extern int AllBars = 240 ;

BarsForFract extern int = 0 ;

CurrentBar int = 0 ;

double Step = 0 ;

int B1 = -1 , B2 = -1 ;

UpDown int = 0 ;

double P1 = 0 , P2 = 0 , PP = 0 ;

int i = 0 , AB = 300 , BFF = 0 ;

ishift int = 0 ;

double iprice = 0 ;

datetime T1 , T2 ;

/ / + ----------------------------------------------- ------------------- +

/ / | Custom indicator initialization function |

/ / + ----------------------------------------------- ------------------- +

int init ( )

{

/ / ---- Indicators

SetIndexStyle ( 0 , DRAW_ARROW ) ;

SetIndexArrow ( 0 , 164 ) ;

SetIndexBuffer ( 0 , ExtMapBuffer1 ) ;

SetIndexEmptyValue ( 0 , 0.0 ) ;

/ / ----

return ( 0 ) ;

}

/ / + ----------------------------------------------- ------------------- +

/ / | Custor indicator function deinitialization |

/ / + ----------------------------------------------- ------------------- +

deinit int ( )

{

ObjectDelete ( " TL1 " ) ;

ObjectDelete ( " TL2 " ) ;

ObjectDelete ( " MIDL " ) ;

Comment ( " " ) ;

/ / ----

return ( 0 ) ;

}

/ / + ----------------------------------------------- ------------------- +

/ / | |

/ / + ----------------------------------------------- ------------------- +

DelObj void ( )

{

ObjectDelete ( " TL1 " ) ;

ObjectDelete ( " TL2 " ) ;

ObjectDelete ( " MIDL " ) ;

}

/ / + ----------------------------------------------- ------------------- +

/ / | Custom indicator iteration function |

/ / + ----------------------------------------------- ------------------- +

int start ( )

{

IndicatorCounted counted_bars = int ( ) ;

/ / ----

if ( ( AllBars == 0 ) | | ( Bars < AllBars ) )

AB = Bars ;

else AB = AllBars ; / / AB - êîëè ÷ ÷ åñòâî Ian èòûâàåìûõ áàðîâ

if ( BarsForFract > 0 )

BFF = BarsForFract ;

else

switch ( Period ( ) )

{

case 1 : BFF = 12 ; break;

case 5 : BFF = 48 ; break;

case 15 : BFF = 24 ; break;

case 30 : BFF = 24 ; break;

case 60 : BFF = 12 ; break;

case 240 : BFF = 15 ; break;

case 1440: BFF = 10 ; break;

case 10080 : BFF = 6 ; break;

default : DelObj ( ), return ( -1 ) ; break;

}

CurrentBar = 2 ; / / ñ ÷ ñ òðåòüåãî Suspected èòàåì , ÷ òîáû ôðàêòàë " çàêðåïèëñÿ

B1 = -1 ;

B2 = -1 ;

UpDown = 0 ;

while ( ( ( B1 == -1 ) | | ( B2 == -1 ) ) && ( CurrentBar < AB ) )

{

/ / UpDown = 1 ÷ eo CIA ïåðâûé ôðàêòàë íàéäåí ñâåðõó , UpDown = -1 ÷ eo CIA ïåðâûé ôðàêòàë

/ / íàéäåí ñíèçó , CIA UpDown = 0 ÷ ¸ AU EO ôðàêòàë he íàéäåí .

/ / A1 a2 è - ÿ áàðîâ íîìåðà ôðàêòàëàìè , ÷ ADAC IEO ñòðîèì îïîðíóþ ëèíèþ .

/ / È D1 D2 - ÷ öåíû ñîîòâåòñòâåííî ADAC êîòîðûå áóäåì ëèíèþ ïðîâîäèòü

if ( ( UpDown < 1 ) && ( CurrentBar == Lowest ( Symbol ( ) , Period ( ) , MODE_LOW , BFF * 2 + 1 ,

CurrentBar - BFF ) ) )

{

if ( UpDown == 0 )

{

UpDown = -1 ;

B1 = CurrentBar ;

P1 = Low [ B1 ] ;

}

else

{

B2 = CurrentBar ;

P2 = Low [ B2 ] ;

}

}

if ( ( UpDown > -1 ) && ( CurrentBar == Highest ( Symbol ( ) , Period ( ) , MODE_HIGH , BFF * 2 + 1 ,

CurrentBar - BFF ) ) )

{

if ( UpDown == 0 )

{

UpDown = 1 ;

B1 = CurrentBar ;

P1 = High [ B1 ] ;

}

else

{

B2 = CurrentBar ;

P2 = High [ B2 ] ;

}

}

CurrentBar + + ;

}

if ( ( B1 == -1 ) | | ( B2 == -1 ) )

{

DelObj ( ) ;

return ( -1 ) ;

} / / Eo ÷ CIA he íàøëè ôðàêòàëîâ ñðåäè 300 áàðîâ 8-)

Step = ( P2 - P1 ) / ( B2 - B1 ) / / Au ÷ èñëèëè OAA , åñëè ïîëîæèòåëüíûé II , OI êàíàë íèñõîäÿùèé

P1 = P1 - B1 * Step ;

B1 = 0 ; / / ïåðåñòàâëÿåì öåíó ïåðâûé AAD è ê íóëþ

/ / À ÷ eo Oi òåïåðü îïîðíóþ ïðîòèâîïîëîæíîé ëèíèè êàíàëà .

ishift = 0 ;

iprice = 0 ;

if ( UpDown == 1 )

{

PP = Low [ 2 ] - 2 * Step ;

for (i = 3 ; i < = B2 ; i + + )

{

if ( Low [ i ] < PP ​​+ Step * i )

PP = Low [ i ] - i * Step ;

}

if ( Low [ 0 ] < PP ​​)

{

ishift = 0 ;

iprice = PP ;

}

if ( Low [ 1 ] < PP ​​+ Step )

{

ishift = 1 ;

iprice = PP + Step ;

}

if ( High [ 0 ] > P1 )

{

ishift = 0 ;

iprice = P1 ;

}

if ( High [ 1 ] > P1 + Step )

{

ishift = 1 ;

iprice = P1 + Step ;

}

}

else

{

PP = High [ 2 ] - 2 * Step ;

for (i = 3 ; i < = B2 ; i + + )

{

if ( High [ i ] > PP + Step * i )

PP = High [ i ] - i * Step ;

}

if ( Low [ 0 ] < P1 )

{

ishift = 0 ;

iprice = P1 ;

}

if ( Low [ 1 ] < P1 + Step )

{

ishift = 1 ;

iprice = P1 + Step ;

}

if ( High [ 0 ] > PP )

{

ishift = 0 ;

iprice = PP ;

}

if ( High [ 1 ] > PP + Step )

{

ishift = 1 ;

iprice = PP + Step ;

}

}

/ / Òåïåðü ïåðåñòàâèì êîíå ÷ è íóþ öåíó he AAD AA , ÷ òîáû ëèíèè êàíàëà ðèñîâàëèñü ïîäëèííåå

P2 = P1 + AB * Step ;

T1 = Time [ B1 ] ;

T2 = Time [ AB ] ;

/ / Åñëè he áûëî ïåðåñå ÷ åíèÿ êàíàëà , oi 0 , EIA ÷ å ñòàâèì Ineno .

if ( iprice ! = 0 )

ExtMapBuffer1 [ ishift ] = iprice ;

DelObj ( ) ;

ObjectCreate ( " TL1 " , OBJ_TREND , 0 , T2 , PP + Step * AB , T1 , PP ) ;

ObjectSet ( " TL1 " , OBJPROP_COLOR , Lime ) ;

ObjectSet ( " TL1 " , OBJPROP_WIDTH , 2 ) ;

ObjectSet ( " TL1 " , OBJPROP_STYLE , STYLE_SOLID ) ;

ObjectCreate ( " TL2 " , OBJ_TREND , 0 , T2 , P2 , T1 , P1 ) ;

ObjectSet ( " TL2 " , OBJPROP_COLOR , White ) ;

ObjectSet ( " TL2 " , OBJPROP_WIDTH , 2 ) ;

ObjectSet ( " TL2 " , OBJPROP_STYLE , STYLE_SOLID ) ;

ObjectCreate ( " MIDL " , OBJ_TREND , 0 , T2 , ( P2 + PP + Step * AB ) / 2 , T1 , ( P1 + PP ) / 2 ) ;

ObjectSet ( " MIDL " , OBJPROP_COLOR , Yellow ) ;

ObjectSet ( " MIDL " , OBJPROP_WIDTH , 1 ) ;

ObjectSet ( " MIDL " , OBJPROP_STYLE , STYLE_DOT ) ;

Comment ( " Channel size = " , DoubleToStr ( MathAbs ( PP - P1 ) / Point , 0 ) , " Slope = " ,

DoubleToStr ( - Step / Point , 2 ) ) ;

/ / ----

return ( 0 ) ;

}

/ / + ----------------------------------------------- ------------------- +

 
djiwenk:
Greetings to all ....

forgive if wrong place, because of my new members .

please its support of the master coding ,

to be coding this indicator into EA .

with the intention of EA will be able to work as I wanted , namely :

1.Open automatic buy when price touches the line TL1 .

2.open automatically sell when price touches the line TL2

3.Open automatically buy when the price is over the line TL2

4.Open automatically sell when the price is over the line TL1

5.closed automatic buy when price touches the line TL2 proceed directly open sell

6.Closed automatically sell when price touches the line TL1 proceed directly open buy

7.nomor 3 and 4 closed manually ( without TrailingStop ) .

8.SL 50 pips and put on lot 0.1

9.Time frame H4 for all pairs .

thank you very much

/ / + ----------------------------------------------- ------------------- +

/ / | SHI_Channel_true.mq4 |

/ / | Copyright © 2004 , Shurka & Kevin |

/ / | |

/ / + ----------------------------------------------- ------------------- +

# property copyright " Copyright © 2004 , Shurka & Kevin "

# property link " "

/ / ----

# property indicator_chart_window

# property indicator_buffers 1

# property indicator_color1 Red

ExtMapBuffer1 double [ ] ;

/ / ---- Input parameters

extern int AllBars = 240 ;

BarsForFract extern int = 0 ;

CurrentBar int = 0 ;

double Step = 0 ;

int B1 = -1 , B2 = -1 ;

UpDown int = 0 ;

double P1 = 0 , P2 = 0 , PP = 0 ;

int i = 0 , AB = 300 , BFF = 0 ;

ishift int = 0 ;

double iprice = 0 ;

datetime T1 , T2 ;

/ / + ----------------------------------------------- ------------------- +

/ / | Custom indicator initialization function |

/ / + ----------------------------------------------- ------------------- +

int init ( )

{

/ / ---- Indicators

SetIndexStyle ( 0 , DRAW_ARROW ) ;

SetIndexArrow ( 0 , 164 ) ;

SetIndexBuffer ( 0 , ExtMapBuffer1 ) ;

SetIndexEmptyValue ( 0 , 0.0 ) ;

/ / ----

return ( 0 ) ;

}

/ / + ----------------------------------------------- ------------------- +

/ / | Custor indicator function deinitialization |

/ / + ----------------------------------------------- ------------------- +

deinit int ( )

{

ObjectDelete ( " TL1 " ) ;

ObjectDelete ( " TL2 " ) ;

ObjectDelete ( " MIDL " ) ;

Comment ( " " ) ;

/ / ----

return ( 0 ) ;

}

/ / + ----------------------------------------------- ------------------- +

/ / | |

/ / + ----------------------------------------------- ------------------- +

DelObj void ( )

{

ObjectDelete ( " TL1 " ) ;

ObjectDelete ( " TL2 " ) ;

ObjectDelete ( " MIDL " ) ;

}

/ / + ----------------------------------------------- ------------------- +

/ / | Custom indicator iteration function |

/ / + ----------------------------------------------- ------------------- +

int start ( )

{

IndicatorCounted counted_bars = int ( ) ;

/ / ----

if ( ( AllBars == 0 ) | | ( Bars < AllBars ) )

AB = Bars ;

else AB = AllBars ; / / AB - êîëè ÷ ÷ åñòâî Ian èòûâàåìûõ áàðîâ

if ( BarsForFract > 0 )

BFF = BarsForFract ;

else

switch ( Period ( ) )

{

case 1 : BFF = 12 ; break;

case 5 : BFF = 48 ; break;

case 15 : BFF = 24 ; break;

case 30 : BFF = 24 ; break;

case 60 : BFF = 12 ; break;

case 240 : BFF = 15 ; break;

case 1440: BFF = 10 ; break;

case 10080 : BFF = 6 ; break;

default : DelObj ( ), return ( -1 ) ; break;

}

CurrentBar = 2 ; / / ñ ÷ ñ òðåòüåãî Suspected èòàåì , ÷ òîáû ôðàêòàë " çàêðåïèëñÿ

B1 = -1 ;

B2 = -1 ;

UpDown = 0 ;

while ( ( ( B1 == -1 ) | | ( B2 == -1 ) ) && ( CurrentBar < AB ) )

{

/ / UpDown = 1 ÷ eo CIA ïåðâûé ôðàêòàë íàéäåí ñâåðõó , UpDown = -1 ÷ eo CIA ïåðâûé ôðàêòàë

/ / íàéäåí ñíèçó , CIA UpDown = 0 ÷ ¸ AU EO ôðàêòàë he íàéäåí .

/ / A1 a2 è - ÿ áàðîâ íîìåðà ôðàêòàëàìè , ÷ ADAC IEO ñòðîèì îïîðíóþ ëèíèþ .

/ / È D1 D2 - ÷ öåíû ñîîòâåòñòâåííî ADAC êîòîðûå áóäåì ëèíèþ ïðîâîäèòü

if ( ( UpDown < 1 ) && ( CurrentBar == Lowest ( Symbol ( ) , Period ( ) , MODE_LOW , BFF * 2 + 1 ,

CurrentBar - BFF ) ) )

{

if ( UpDown == 0 )

{

UpDown = -1 ;

B1 = CurrentBar ;

P1 = Low [ B1 ] ;

}

else

{

B2 = CurrentBar ;

P2 = Low [ B2 ] ;

}

}

if ( ( UpDown > -1 ) && ( CurrentBar == Highest ( Symbol ( ) , Period ( ) , MODE_HIGH , BFF * 2 + 1 ,

CurrentBar - BFF ) ) )

{

if ( UpDown == 0 )

{

UpDown = 1 ;

B1 = CurrentBar ;

P1 = High [ B1 ] ;

}

else

{

B2 = CurrentBar ;

P2 = High [ B2 ] ;

}

}

CurrentBar + + ;

}

if ( ( B1 == -1 ) | | ( B2 == -1 ) )

{

DelObj ( ) ;

return ( -1 ) ;

} / / Eo ÷ CIA he íàøëè ôðàêòàëîâ ñðåäè 300 áàðîâ 8-)

Step = ( P2 - P1 ) / ( B2 - B1 ) / / Au ÷ èñëèëè OAA , åñëè ïîëîæèòåëüíûé II , OI êàíàë íèñõîäÿùèé

P1 = P1 - B1 * Step ;

B1 = 0 ; / / ïåðåñòàâëÿåì öåíó ïåðâûé AAD è ê íóëþ

/ / À ÷ eo Oi òåïåðü îïîðíóþ ïðîòèâîïîëîæíîé ëèíèè êàíàëà .

ishift = 0 ;

iprice = 0 ;

if ( UpDown == 1 )

{

PP = Low [ 2 ] - 2 * Step ;

for (i = 3 ; i < = B2 ; i + + )

{

if ( Low [ i ] < PP ​​+ Step * i )

PP = Low [ i ] - i * Step ;

}

if ( Low [ 0 ] < PP ​​)

{

ishift = 0 ;

iprice = PP ;

}

if ( Low [ 1 ] < PP ​​+ Step )

{

ishift = 1 ;

iprice = PP + Step ;

}

if ( High [ 0 ] > P1 )

{

ishift = 0 ;

iprice = P1 ;

}

if ( High [ 1 ] > P1 + Step )

{

ishift = 1 ;

iprice = P1 + Step ;

}

}

else

{

PP = High [ 2 ] - 2 * Step ;

for (i = 3 ; i < = B2 ; i + + )

{

if ( High [ i ] > PP + Step * i )

PP = High [ i ] - i * Step ;

}

if ( Low [ 0 ] < P1 )

{

ishift = 0 ;

iprice = P1 ;

}

if ( Low [ 1 ] < P1 + Step )

{

ishift = 1 ;

iprice = P1 + Step ;

}

if ( High [ 0 ] > PP )

{

ishift = 0 ;

iprice = PP ;

}

if ( High [ 1 ] > PP + Step )

{

ishift = 1 ;

iprice = PP + Step ;

}

}

/ / Òåïåðü ïåðåñòàâèì êîíå ÷ è íóþ öåíó he AAD AA , ÷ òîáû ëèíèè êàíàëà ðèñîâàëèñü ïîäëèííåå

P2 = P1 + AB * Step ;

T1 = Time [ B1 ] ;

T2 = Time [ AB ] ;

/ / Åñëè he áûëî ïåðåñå ÷ åíèÿ êàíàëà , oi 0 , EIA ÷ å ñòàâèì Ineno .

if ( iprice ! = 0 )

ExtMapBuffer1 [ ishift ] = iprice ;

DelObj ( ) ;

ObjectCreate ( " TL1 " , OBJ_TREND , 0 , T2 , PP + Step * AB , T1 , PP ) ;

ObjectSet ( " TL1 " , OBJPROP_COLOR , Lime ) ;

ObjectSet ( " TL1 " , OBJPROP_WIDTH , 2 ) ;

ObjectSet ( " TL1 " , OBJPROP_STYLE , STYLE_SOLID ) ;

ObjectCreate ( " TL2 " , OBJ_TREND , 0 , T2 , P2 , T1 , P1 ) ;

ObjectSet ( " TL2 " , OBJPROP_COLOR , White ) ;

ObjectSet ( " TL2 " , OBJPROP_WIDTH , 2 ) ;

ObjectSet ( " TL2 " , OBJPROP_STYLE , STYLE_SOLID ) ;

ObjectCreate ( " MIDL " , OBJ_TREND , 0 , T2 , ( P2 + PP + Step * AB ) / 2 , T1 , ( P1 + PP ) / 2 ) ;

ObjectSet ( " MIDL " , OBJPROP_COLOR , Yellow ) ;

ObjectSet ( " MIDL " , OBJPROP_WIDTH , 1 ) ;

ObjectSet ( " MIDL " , OBJPROP_STYLE , STYLE_DOT ) ;

Comment ( " Channel size = " , DoubleToStr ( MathAbs ( PP - P1 ) / Point , 0 ) , " Slope = " ,

DoubleToStr ( - Step / Point , 2 ) ) ;

/ / ----

return ( 0 ) ;

}

/ / + ----------------------------------------------- ------------------- +

djiwenk

You do know that shi channel changes all the time (as current price changes shi channel will change too)?

 

ea creating book

create your own ea

Files:
eaprog.pdf  1296 kb
Reason: