Download MetaTrader 5

Please help me solve this problem

To add comments, please log in or register
Ernest Klokow
1119
Ernest Klokow  

I am not a advanced programmer, but I have written an EA that I use to open trades for me automatically when an anti-trendline is broken in a certain way.

The problem is I cannot test this EA in the Strategy Tester since it requires human intervention to draw this anti-trendline and then put the name into the EA like this: (an abstract)

input string   BUYtrendlineName;       
input string   SELLtrendlineName; 

SELLtrendlineValue = ObjectGetValueByTime(0,SELLtrendlineName,TimeCurrent(),0);
SELLtrendlineValue = NormalizeDouble(SELLtrendlineValue,MarketInfo(OrderSymbol(),MODE_DIGITS));

BUYtrendlineValue = ObjectGetValueByTime(0,BUYtrendlineName,TimeCurrent(),0);
BUYtrendlineValue = NormalizeDouble(BUYtrendlineValue,MarketInfo(OrderSymbol(),MODE_DIGITS));

I want to use an indicator by the name of TL_by_Demark_v6 that draws these anti-trendlines. (I am attaching the mq4 code for this indicator to this post)

As I see it I have two options to use this indicator in my EA to get the value of the anti-trendline that mmust be broken to open a trade:

1. Attach the indicator to the chart and then use the name of the trend line object it draws as my BUY- and SELLtrendlineName. (in the same way I would read the position of the trend line in the code above as follows:

input string   TrDup;   //name of the object in the program
input string   TrDdown; //name of the object in the program
SELLtrendlineValue = ObjectGetValueByTime(0,TrDup,TimeCurrent(),0); SELLtrendlineValue = NormalizeDouble(SELLtrendlineValue,MarketInfo(OrderSymbol(),MODE_DIGITS));            BUYtrendlineValue = ObjectGetValueByTime(0,TrDdown,TimeCurrent(),0); BUYtrendlineValue = NormalizeDouble(BUYtrendlineValue,MarketInfo(OrderSymbol(),MODE_DIGITS));

2. I can use the indicator as a custom indicator in my code with the iCustom operator. The indicator has no input parameters - only colour options)

BUYtrendlineValue = iCustom(NULL,0,"TL_by_Demark_v6",2,1);
SELLtrendlineValue = iCustom(NULL,0,"TL_by_Demark_v6",3,1);

None of the two approaches are working - the two parameter values stay at = 0

Can anybody help me to get this working? Please!

P.S. I am attaching a chart to show what the indicator displays

Marco vd Heijden
Moderator
6060
Marco vd Heijden  
You can still draw these trendlines by hand and read them by using:
ObjectGetDouble()

Function so i'm not sure why you say it can not be tested in the tester.

It does require a bit of coding but it's not too difficult to make it work..

whroeder1
16808
whroeder1  
<div class="fquote" >Marco vd Heijden: i'm not sure why you say it can not be tested in the tester.
Draw objects are not really set

The objects are disabled in order to accelerate the testing. -- Testing Features and Limits in MetaTrader 4 - MQL4 Articles

Ernest Klokow
1119
Ernest Klokow  

Thank you guys for trying to help but i am still in the dark.

Let me explain again.

I can use this EA in the tester and then test it by manually drawing the anti-trendlines at the right places and naming the trendlines that I draw the same as the names I put into the inputs of the EA before I start like this:

input string   BUY;       
input string   SELL; 

SELLtrendlineValue = ObjectGetValueByTime(0,SELL,TimeCurrent(),0);
SELLtrendlineValue = NormalizeDouble(SELL,MarketInfo(OrderSymbol(),MODE_DIGITS));

BUYtrendlineValue = ObjectGetValueByTime(0,BUYtrendlineName,TimeCurrent(),0);
BUYtrendlineValue = NormalizeDouble(BUYtrendlineValue,MarketInfo(OrderSymbol(),MODE_DIGITS));

So I rename the anti-trendlines "BUY" for the ones I use for triggering my Buy trades and "SELL" for the sell trades. Then I put these names into the inputs of the EA as shown above,

(For some or other unknown reason this does not work any more for the last couple of weeks although it worked for many months before - see my other post on this)

But doing it manually like this is laborious and slow. I want the anti-trendlines to be drawn automatically by the indicator (TL_by_Demark v6) and the EA to read the set names of the lines being drawn by the indicator and use it in the place of the names of the lines that I drew manually.

Hope this makes it a little clearer?

Ernest Klokow
1119
Ernest Klokow  
Marco vd Heijden:
You can still draw these trendlines by hand and read them by using:

Function so i'm not sure why you say it can not be tested in the tester.

It does require a bit of coding but it's not too difficult to make it work..


Marco is this operand GetObject()
Marco vd Heijden:
You can still draw these trendlines by hand and read them by using:

Function so i'm not sure why you say it can not be tested in the tester.

It does require a bit of coding but it's not too difficult to make it work..


Marco is this a MT4 or MT5 operand or both?

ObjectGetDouble()
Roberto Jacobs
49021
Roberto Jacobs  

If you use:

MarketInfo(OrderSymbol(),MODE_DIGITS);

The order must be previously selected by the OrderSelect() function.

If not, you must use

MarketInfo(Symbol(),MODE_DIGITS);
Ernest Klokow
1119
Ernest Klokow  
Roberto Jacobs:

If you use:

The order must be previously selected by the OrderSelect() function.

If not, you must use


Roberto,

Not sure which order must be previously selected since the EA does not place orders at the moment because of the problems described above for which I am stll trying to find a solution for.

Roberto Jacobs
49021
Roberto Jacobs  
Ernest Klokow:


Roberto,

Not sure which order must be previously selected since the EA does not place orders at the moment because of the problems described above for which I am stll trying to find a solution for.

I've check indicator TL_by_Denmark_v6.
For EA, try to use:

//-- You can use NormalizedDouble ---
double buy_0 = iCustom(_Symbol,0,"TL_by_Demark_v6",2,0);
double buy_1 = iCustom(_Symbol,0,"TL_by_Demark_v6",2,1);
double sel_0 = iCustom(_Symbol,0,"TL_by_Demark_v6",3,0);
double sel_1 = iCustom(_Symbol,0,"TL_by_Demark_v6",3,1);

//----------- Then:
bool BUY  = buy_0 > buy_1 && sel_0 == EMPTY_VALUE;
bool SELL = sel_0 < sel_1 && buy_0 == EMPTY_VALUE;

I've modified TL_by_Denmark_v6 indicator, by cutting trend_line using RAY_RIGHT = false, so it is easily seen the trend_line.

Files:
Ernest Klokow
1119
Ernest Klokow  

Roberto,

Thank you for your efforts to help me. Greatly appreciated!

Can you please explain what you are trying to achieve with this part of your code?


//----------- Then:
bool BUY  = buy_0 > buy_1 && sel_0 == EMPTY_VALUE;
bool SELL = sel_0 < sel_1 && buy_0 == EMPTY_VALUE;
To add comments, please log in or register