Please fix this indicator or EA - page 15

 
cosmiclifeform:
Hi Shaival,

The iCustom statements are missing all the "extern" variables that need to be passed from the indicator to the EA...so your EA is not getting the values from the indicator at all.

Do a search on this TSD forum for "iCustom" to see many iCustom examples to help you learn how to do it correctly.

Hope this helps,

Robert

Thanks Robert

 

the nested ifs do not recognize conditions that occur simultaneously

Hi cosmiclifeform,

thanks for your reply!

I want to specify what follows:

I had already printed variable values myOpen myClose (you can see in the EA code the line that print the values, line that I then put after "//") and I found several bars where both conditions occur simultaneously.

Now I changed the code like this: I added a variable that takes the value true only if the first condition is verified. The same is done with a second variable for the second condition. I added an if statement that prints "Both_Ifs_TrueTogether" when both variables take value true. Moreover, once both conditions are verified -if (myFirstConditionOK == true & & mySecondConditionOK == true) - I want to see if the nested if functions work fine, that is: the nested if recheck the conditions only when both the conditions are already verified by the upper if condition -if (myFirstConditionOK == true & & mySecondConditionOK == true). That's the point: the nested ifs are never taken into consideration!

I attach the new code.

As to your consideration number one: all the data included in the if conditions refer to the previous bar, so the ope and clos values always refer to a completed bar.

As to your consideration number two: don't look too much at the differences in the buy vs sell rules: I just put them to create an EA that makes my problem arise.

Examples where the two conditions are occurring simultaneously in daily EURUSD are in the following dates: July 13, 2008, October 12, 2008, April 12, 2009, 05/25/2009, 09/21/2009, 12/30/2009.

Am I crazy? (This is basically the main question, in this I search for your help...)

Thank you for any further indication, if you could run the new code I would be grateful for any advice.

Have a good day!

Here's the modified part of the code:

if (myOpen> myClose)

(

Print ("SeparateFirstCondition_OK on time", Time [0]);

myFirstConditionOK = true;

)

if ((myHigh-myClose) <= (1 / 3) * (myHigh-mylow))

(

Print ("SeparateSecondCondition_OK");

mySecondConditionOK = true;

)

if (myFirstConditionOK == true & & mySecondConditionOK == true)

(

Print ("Both_Ifs_TrueTogether");

if (myOpen> myClose) / / If First !!!!!!!!!!!

(

Print ("Check_If_1");

if ((myHigh-myClose) <= (1 / 3) * (myHigh-mylow)) / / If Second !!!!!!!!!!

(

Print ("Check_If_2");

)

Print ("Check_AfterSecondIf");

Files:
nestedif3.mq4  4 kb
 
lucalupi75:
Hi cosmiclifeform,

thanks for your reply!

Now I changed the code like this: I added a variable that takes the value true only if the first condition is verified. The same is done with a second variable for the second condition. I added an if statement that prints "Both_Ifs_TrueTogether" when both variables take value true. Moreover, once both conditions are verified -if (myFirstConditionOK == true & & mySecondConditionOK == true) - I want to see if the nested if functions work fine, that is: the nested if recheck the conditions only when both the conditions are already verified by the upper if condition -if (myFirstConditionOK == true & & mySecondConditionOK == true). That's the point: the nested ifs are never taken into consideration!

Am I crazy? (This is basically the main question, in this I search for your help...)

Thank you for any further indication, if you could run the new code I would be grateful for any advice.

Have a good day!

Lucalupi75,

I ran the EA again... From what I see...it looks like your nesting does work...

However....I could not get it to work using your buy/sell formulas so I simplified it - I blanked out your formulas and used simple values to test the nesting.

extern double AA = 5;

extern double BB = 4;

extern double CC = 3;

1st Condition

AA > BB

2nd Condition

BB>CC

if AA>BB and BB>CC

{do this}

Started with BB=4 (less than AA and greater than CC)

This printed the nesting correctly in the log, showing the 1st condition, then the 2nd condition was met.

12:51:52 2010.06.25 00:00 NestedIf3-Test EURUSD,H1: !!!!!!!!!!!!!!!!!!!!!!!!!!!Both_Ifs_TrueTogether!!!!!!!!!!!!!!!!!!!!!!!!!!!!

12:51:52 2010.06.25 00:00 NestedIf3-Test EURUSD,H1: (AA>BB) - Check_If_1

12:51:52 2010.06.25 00:00 NestedIf3-Test EURUSD,H1: (BB > CC) - Check_If_2

12:51:52 2010.06.25 00:00 NestedIf3-Test EURUSD,H1: Check_AfterSecondIf

12:51:52 2010.06.25 00:00 NestedIf3-Test EURUSD,H1: open #2 sell 0.10 EURUSD at 1.23320 ok

12:51:52 2010.06.25 00:00 NestedIf3-Test EURUSD,H1: modify #2 sell 0.10 EURUSD at 1.23320 sl: 1.23840 tp: 1.22620 ok

I then changed BB=2 (less than AA and less than CC)and it correctly passed by the 2nd nest, showing only the 1st condition met.

12:50:34 2010.06.23 22:27 NestedIf3-Test EURUSD,H1: BB>CC --> NOT TRUE

12:50:34 2010.06.23 22:27 NestedIf3-Test EURUSD,H1: zzz 1277326800 1.2272 1.2343 1.227 1.2322

12:50:34 2010.06.23 22:27 NestedIf3-Test EURUSD,H1: BB>CC --> NOT TRUE

12:50:34 2010.06.23 22:28 NestedIf3-Test EURUSD,H1: zzz 1277326800 1.2272 1.2343 1.227 1.2322

Suggestion - try using simple values to get your nesting to work, then you can add your complex formulas with confidence later..

BTW, I find it helpful to display values and conditions as Comments directly on the chart...so you can actually watch the values change on the screen (and not have to watch the journal log).

Here's a couple of statements to add as Print/Comments if you like - they show True/False (1/0) for your condition statements.

Comments (

"\n myFirstConditionOK = ",myFirstConditionOK,

"\n mySecondConditionOK = ",mySecondConditionOK,

"\n" ) ;

Hope this helps. Let us know how it goes.

Robert

 

how to add a sliding stop loss to an ea?

Hi all,

I am new to this and have been struggling to figure out how to add a sliding stop loss to an ea.

The idea is that the ea will open a buy and sell position at the same time at the start of each new bar. After x pips the loosing trade will close by way of hitting a trailing stop loss but the winning trade will continue and hit either a tp or come back to it's trailing stop.

What I would like is to add a sliding stop, so after the first trade has hit its trailing stop the remaining open side cannot return to below 'breakeven' point.

I have picked this ea up and would like to know if it's possible to do this.

Have read about swiss army and know that sliding stops can be added but at this time it's beyond my skills.

Any ideas or could someone help with this?

many thanks in advance

Files:
 

Help modify Spread EA

Hello Traders...

Can somebody help me to modify my EA code that only by or sell when the Spread is between maybe between 10-50 points,don't to by or sell under 10 and over 50 pips.

Can anybody help haw to add this in my code?Is this the Slippage ?

Sorry for my English and thanks for any help.

zoom

 

Indicator - GURU- HELP Needed

Hi gurus, I apologize that I am unable to be of much assistance in the forum, as I am very new to trading.

I have a request, can someone please add the code to alert (and email alert) when price crosses above or below the indicator line that is created by the following code:

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 White

#property indicator_color2 White

#property indicator_color3 White

//---- input parameters

extern int kama_period = 20;

extern double fast_ma_period = 2.0;

extern double slow_ma_period = 60.0;

//---- buffers

double KAMA[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,KAMA);

SetIndexLabel(0, "KAMA");

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//----

int i = Bars - counted_bars;

double fastest = 2 / (fast_ma_period + 1);

double slowest = 2 / (slow_ma_period + 1);

while(i>0){

double er = 1;

double signal = MathAbs(Close - Close);

double noise = 0;

for (int j=0; j<kama_period; j++)

noise += MathAbs(Close - Close);

if (noise > 0)

er = signal / noise;

double sc = MathPow((er * (fastest - slowest) + slowest), 2);

KAMA = KAMA + sc * (Close - KAMA);

i--;

}

//----

return(0);

}

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

And please can you assist in my learning by posting the mql file or the actual code in your reply.

Thanks very much.

TF

 

added code in bold

i did not dl the indy nor test, i simply pasted in some code from a indy i did the other day for some1

the alert will trigger once per bar cause the ibarshift

tonguefu:
Hi gurus, I apologize that I am unable to be of much assistance in the forum, as I am very new to trading.

I have a request, can someone please add the code to alert (and email alert) when price crosses above or below the indicator line that is created by the following code:

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 White

#property indicator_color2 White

#property indicator_color3 White

//---- input parameters

extern int kama_period = 20;

extern double fast_ma_period = 2.0;

extern double slow_ma_period = 60.0;

extern bool sound=true;

extern bool email=true;

extern int alert_pips=2;

double my_point;

int current_bar;

//---- buffers

double KAMA[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,KAMA);

SetIndexLabel(0, "KAMA");

if (Point==0.0001)my_point=0.0001;

if (Point==0.00001)my_point=0.0001;

if (Point==0.01)my_point=0.01;

if (Point==0.001)my_point=0.01;

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//----

int i = Bars - counted_bars;

double fastest = 2 / (fast_ma_period + 1);

double slowest = 2 / (slow_ma_period + 1);

while(i>0){

double er = 1;

double signal = MathAbs(Close - Close);

double noise = 0;

for (int j=0; j<kama_period; j++)

noise += MathAbs(Close - Close);

if (noise > 0)

er = signal / noise;

double sc = MathPow((er * (fastest - slowest) + slowest), 2);

KAMA = KAMA + sc * (Close - KAMA);

i--;

}

if (current_bar!=iBarShift(NULL,0,0)&&BidKAMA[0] -alert_pips*my_point)

{

if (sound)PlaySound("alert.wav");

if (email)SendMail("kama_"+Symbol()+"_"+DoubleToStr(Bid,Digits), "Support-Resistance_alert_"+Symbol()+DoubleToStr(Bid,Digits));

current_bar=iBarShift(NULL,0,0);

}

//----

return(0);

}

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

And please can you assist in my learning by posting the mql file or the actual code in your reply.

Thanks very much.

TF
 

Not working yet

errrr, ummm... I tested this and it did not alert on a 15M chart when price came within 1 pip of line (I had the variable set to 5 pips) so it shoulda kicked off an alert, no?

Thanks

 

Code Enhancements

Hi there, and thank you so much for your help. I sure am learning a lot about mql (the painfully hard way).

Are you able to enhance the following code that I posted to only alert when price crosses (like you did for me) but only when the cross is going UP through the line when price is ABOVE the 10D SMA... and reverse logic when price crosses going down?

I am certainly not a pro, but have noticed that when the price goes up through the KAUF line (KAMA) AND the price action is above the 10D SMA (15m-1HR charts) that the moves are fairly easy to manage with limited drawdown...

Anyway, I appreciate what you have done for me already but if you can find the time to enhance the code posted below to only alert/email when the price crosses the KAMA line when price is ABOVE 10d sma for a BUY signal and reverse that logic for a sell signal, it would be very cool to test...

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 White

#property indicator_color2 White

#property indicator_color3 White

//---- input parameters

extern int kama_period = 20;

extern double fast_ma_period = 2.0;

extern double slow_ma_period = 60.0;

extern bool sound=true;

extern bool email=true;

extern int alert_pips=2;

double my_point;

int current_bar;

//---- buffers

double KAMA[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,KAMA);

SetIndexLabel(0, "KAMA");

if (Point==0.0001)my_point=0.0001;

if (Point==0.00001)my_point=0.0001;

if (Point==0.01)my_point=0.01;

if (Point==0.001)my_point=0.01;

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//----

int i = Bars - counted_bars;

double fastest = 2 / (fast_ma_period + 1);

double slowest = 2 / (slow_ma_period + 1);

while(i>0){

double er = 1;

double signal = MathAbs(Close - Close);

double noise = 0;

for (int j=0; j<kama_period; j++)

noise += MathAbs(Close - Close);

if (noise > 0)

er = signal / noise;

double sc = MathPow((er * (fastest - slowest) + slowest), 2);

KAMA = KAMA + sc * (Close - KAMA);

i--;

}

if (current_bar!=iBarShift(NULL,0,0)&&BidKAMA[0] -alert_pips*my_point)

{

if (sound)PlaySound("alert.wav");

if (email)SendMail("kama_"+Symbol()+"_"+DoubleToStr(Bid,Digits), "Support-Resistance_alert_"+Symbol()+DoubleToStr(Bid,Digits ));

current_bar=iBarShift(NULL,0,0);

}

//----

return(0);

}

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

 

Help

Hi there, can someone help me tweak the code below to actually do a pop-up alert and send an email. Although the code below compiles correctly, this indicator does NOT in fact pop-up or send an email... A GURU's help here would be greatly appreciated...

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 White

#property indicator_color2 White

#property indicator_color3 White

//---- input parameters

extern int kama_period = 20;

extern double fast_ma_period = 2.0;

extern double slow_ma_period = 60.0;

extern bool sound=true;

extern bool email=true;

extern int alert_pips=2;

double my_point;

int current_bar;

//---- buffers

double KAMA[];

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,KAMA);

SetIndexLabel(0, "KAMA");

if (Point==0.0001)my_point=0.0001;

if (Point==0.00001)my_point=0.0001;

if (Point==0.01)my_point=0.01;

if (Point==0.001)my_point=0.01;

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

//----

int i = Bars - counted_bars;

double fastest = 2 / (fast_ma_period + 1);

double slowest = 2 / (slow_ma_period + 1);

while(i>0){

double er = 1;

double signal = MathAbs(Close - Close);

double noise = 0;

for (int j=0; j<kama_period; j++)

noise += MathAbs(Close - Close);

if (noise > 0)

er = signal / noise;

double sc = MathPow((er * (fastest - slowest) + slowest), 2);

KAMA = KAMA + sc * (Close - KAMA);

i--;

}

if (current_bar!=iBarShift(NULL,0,0)&&BidKAMA[0] -alert_pips*my_point)

{

if (sound)PlaySound("alert.wav");

if (email)SendMail("kama_"+Symbol()+"_"+DoubleToStr(B id,Digits), "Support-Resistance_alert_"+Symbol()+DoubleToStr(Bid,Digits ));

current_bar=iBarShift(NULL,0,0);

}

//----

return(0);

}

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

Reason: