How to call an .ex4 file into an EA?

Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

Hello,
I have built a simple EA but it's not working. I mean it hasn't opened any trade yet. :(
Please review it and match with my requirements [stated in previous post] and let me know what wrong I did.
*** I think the problem lies in the EarlySignal and M3_Coral_Filter defining in the EA template.
I defined them as 'bool'. But after opening the EA in the chart, I have seen that both these variables are 'False'. Can this be a problem?

*I have attached the used indicators.

My Code:

Code: Select all

#property copyright ""
#property link      ""

//--- input parameters
extern double    LotSize=1.0;
extern double    StopLoss=30.0;
extern double    TakeProfit=10.0;
extern int       Slippage=5;
extern int       MagicNumber=786;
extern bool      EarlySignal;
extern bool      M3_Coral_Filter;
int BuyOrder;
int SellOrder;

int start()
  {
{
        double Y1, Y2, Y3, Y4;
        Y1 = iCustom(NULL,0,"FIM",EarlySignal,M3_Coral_Filter,1,0);
        Y2 = iCustom(NULL,0,"MoneyFlowIndex",EarlySignal,M3_Coral_Filter,1,0);
	     Y3 = iCustom(NULL,0,"FIM",EarlySignal,M3_Coral_Filter,0,0);
        Y4 = iCustom(NULL,0,"MoneyFlowIndex",EarlySignal,M3_Coral_Filter,2,0);
        return (Y1);
        return (Y2);
        return (Y3);
        return (Y4);
        }
        if (Y1==1 && Y2==1)
        {
double OpenPrice=Ask;
BuyOrder=OrderSend(Symbol() , OP_BUY , LotSize,OpenPrice,Slippage ,StopLoss ,TakeProfit , "Buy Order",MagicNumber , 0,Blue);

       }

	if (Y3==0 && Y4==0)
        {
        OpenPrice=Bid;
SellOrder=OrderSend(Symbol() , OP_SELL , LotSize,OpenPrice,Slippage ,StopLoss ,TakeProfit , "Sell Order",MagicNumber , 0,Red);

        }

   return(0);
  }
You do not have the required permissions to view the files attached to this post.
garyfritz

Re: How to call an .ex4 file into an EA?

Post by garyfritz »

Arav » Fri Jan 31, 2014 10:40 am wrote: I think the problem lies in the EarlySignal and M3_Coral_Filter defining in the EA template.
I defined them as 'bool'. But after opening the EA in the chart, I have seen that both these variables are 'False'. Can this be a problem?
No. That's just the default value, since you didn't specify a default initial value (like you did for the other extern inputs). You can change the inputs when you run the EA or by hitting F7 while it's running.

You have more serious problems.

return() says "exit this function and return this value to the function that called me." You have 4 return()s after your iCustom() calls. That means you never execute the rest of the start() function. You make the iCustom() calls, then you return Y1 and quit. You don't want those 4 return()s.

Also, on line 22 you call MoneyFlowIndex on bar 2, not bar 1. Is that what you wanted?

You're still sending an order on EVERY TICK when Y1 & Y2 are 1, or when Y3 & Y4 are 0. I doubt you really want that.
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

No. That's just the default value, since you didn't specify a default initial value (like you did for the other extern inputs). You can change the inputs when you run the EA or by hitting F7 while it's running.
Yes I know I can but not sure what to change. As I haven't defined them by default, so how changing them will affect the overall activities?
return() says "exit this function and return this value to the function that called me." You have 4 return()s after your iCustom() calls. That means you never execute the rest of the start() function. You make the iCustom() calls, then you return Y1 and quit. You don't want those 4 return()s.
Yes I understood what you have said. I also thought about it but to make the EA error Free, I separated them. Is there really any need to return the values at that stage or it can be done other way? You are right that the function isn't going to logical part.
Also, on line 22 you call MoneyFlowIndex on bar 2, not bar 1. Is that what you wanted?
No there '2' means the buffer number. I identified that 'R' of 2nd indicator is buffer 2. I might be wrong.
You're still sending an order on EVERY TICK when Y1 & Y2 are 1, or when Y3 & Y4 are 0. I doubt you really want that.
If I want to send an order on closing of every bar then would I use 1 always in the place of '0' [current bar]?

Thanks
garyfritz

Re: How to call an .ex4 file into an EA?

Post by garyfritz »

Arav » Fri Jan 31, 2014 12:36 pm wrote:Yes I know I can but not sure what to change. As I haven't defined them by default, so how changing them will affect the overall activities?
If you don't set a value, the input will have a default value. For booleans that's False. You're passing that value into your indicator. You have to decide if that's the right value for your needs. I can't tell what those indicators do, or what parameters they take.
Yes I understood what you have said. I also thought about it but to make the EA error Free, I separated them. Is there really any need to return the values at that stage or it can be done other way? You are right that the function isn't going to logical part.
No, there's no reason to return at that point. You haven't done anything yet except call the indicators.
Also, on line 22 you call MoneyFlowIndex on bar 2, not bar 1. Is that what you wanted?
No there '2' means the buffer number. I identified that 'R' of 2nd indicator is buffer 2. I might be wrong.
You're right, my mistake.
You're still sending an order on EVERY TICK when Y1 & Y2 are 1, or when Y3 & Y4 are 0. I doubt you really want that.
If I want to send an order on closing of every bar then would I use 1 always in the place of '0' [current bar]?
No, the start() function gets called on every tick. That means anything you do it in will get executed on every tick. So (assuming you remove those 4 return() calls) when the Y1/Y2 values are 1 or Y3/Y4 are 0, you will execute those orders on every tick. You need to add logic so the orders only get placed when they should -- for example, when Y1/Y2 FIRST become 1.

Arav, I give you credit for figuring out a lot of details on this, when it's clear you have no experience with Empty4. But the questions you're asking indicate a lack of understanding of basic programming concepts. You need to learn how to program before you come here and ask us to debug your EA for you. For now, you're probably going to have to find someone to program it for you. And no, that's not me.

Gary
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

But the questions you're asking indicate a lack of understanding of basic programming concepts. You need to learn how to program before you come here and ask us to debug your EA for you. For now, you're probably going to have to find someone to program it for you. And no, that's not me.

Gary
Gary Thanks a lot for all your Helps. You helped me a lot to get idea and discover reasons about all the buffer things and iCustom().
Actually I have some base of C & C++ because of my Study purpose. So I have some idea how to implement logic. My novish questions were mostly about the iCustom() and Buffer because I am confused about the way of utilizing them in an EA. Also I haven't found a single reference on calling an .ex4 indicator into an EA with a complete example. I had book's reference with hundreds of examples for C, C++ but here I have no other way than asking experts.
I am reading and taking help from 'Andrew r Young's' EA programming book but even there he hadn't discuss much about calling .ex4 file. His examples also about just for .mq4 files.

I am not asking anyone to do my coding. I am just asking why and how, then I am doing it by myself and asking for correction again.
Anyway, I will Keep Trying. Thanks
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: How to call an .ex4 file into an EA?

Post by SteveHopwood »

Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
Arav
Trader
Posts: 15
Joined: Tue Jan 21, 2014 2:06 pm

Re: How to call an .ex4 file into an EA?

Post by Arav »

Thanks a Lot Steve!
Probably this is something I needed. I hope after finishing this, I'd be able to express my thoughts and queries more maturely.
Post Reply

Return to “Coders Hangout”