Reply

How to make it only trade when coral indy is a particular color

10 replies

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #110903

I am having difficulty with the attached indicator. I want the EA to only make a buy order when the coral is green and only a sell order when the coral is red.

But it is making buy orders when indy is red even though it is not suppose to:

When I loaded the indy into the EA Wizard as a custom indicator, it had 4 outputs. I went into MT4 and moved the cursor around and figured out that when the indy was green, then the price was in the value 2 field.

When it was red, it was in the value 3 field.

So I named those outputs appropriately in the Custom Indicators import of EA Wizard.

Then, I put a rule saying that when the output field 2 (named "green") was greater than 0 (because when it is not green it is 0), only do buy orders. When the field 3 is greater than 0 (because when it is red it populates the field 3), then only do sell orders.

But alas. As you can see

it makes a buy order when it is red. Can you help me know how to fix this or what I am doing wrong?

Thanks,
Stearno

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #120944

I figured I would troubleshoot the coral…maybe I could figure out the problem. First elimination was to determine if it was the coral even causing the problem. So I changed it with a regular Moving Average. The rule said that if the HA price close was below the MA then only sell orders. If above, then only buy orders.

. It did not work. So that means the problem was not with the coral…

step two. Maybe my code was wrong. So simpliest thing, make simple code. So I created a new strategy and had only upon MACD cross, it would buy and reverse cross it would sell.

. Tested the EA and it was buying and selling as it should.

I then added to this working EA that the close had to be below a Exponential MA to sell

and had to close above MA for buy (also did regular price instead of HA, to eliminate HA out of the variables)

.

Ran the strategy and it still sold above the MA and bought below the MA.

So conclusion: There are only two things constant in this elimination of variables process and that is myself and the software. So one of those have to be the cause. Most likley it is me as Mark is a better coder than I am, so please look at my attached code and tell me what I have done wrong to make it not work as I would like. I have attached my original MA. I thank you in advance for the feedback.

I thank you!

-Stearno

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

11 years ago #120964

Hi Stearno,

this THV 4HA indicator you use in your strategy is same as THV4 Coral?
THV 4HA has additional True/False parameter, so I assume it is another indicator. Can you post it so I can test it with it?

When I tested your simple version EA with only MACD and Moving Average, it never opened sell above MA or buy below MA.
Could you send me the strategy that does this with your tests?

Mark

Mark
StrategyQuant architect

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #120976

I have attached the THV HA. I have tried it with the HA indi that comes with EA Wizard, and I have tried it with raw price data (EA Wizard files attached of each). I have also tried without coral and used a regular MA, which is attached as well. They all ended in same result.

I am also on my work computer right now, so I tried it on this PC to eliminate the cuase being the specific MT4 app on my personal computer. It had the same result, so it is not the specific MT4 I was using.

I did a test strategy to buy/sell based upon cross above/below 0 of MACD. Buy if above MA and sell if below MA. It worked. So it seems there is something wrong in the way I coded it.

I look forward to your feedback on what is wrong with my coding that is causing this.

-stearno

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

11 years ago #120979

Hi,

I found the error, problem is in Coral indicator. For example for short rule you have a condition iCustom(THV4 Coral, Red) > Close.
The problem is that if Coral indicator is rising (green) there is no value for Red defined, and the indicator doesn’t return 0 (as I’d expect) but returns a maximum double number.
So this comparison is always true and it doesnt prevent your EA entering to short trades.

A solution would be to use the value of Coral, not Red/Green, like this: iCustom(THV4 Coral, Coral)
another solution would be to check if THV4 Coral return value isn;t bigger than 1000 – this means it has no value.

Mark

Mark
StrategyQuant architect

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #120983

Okay, I went into the indicator code and from your guidance of the root cause, I found where the buffers were set to “= Empty_Value.” I changed the empty value to 0. It works now.

A funny side effect is when the coral changes from red to yellow, the red makes a straight line to zero and then green makes a straight line from zero up to the coral line. It is kind of funny looking.

But anyway, that is what I will use with the EA and then use the correct indy on the chart.

Thank you again!

-Stearno

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #120984

Okay, so now the EA worked after making the changes you pointed out.

I then went and added some rules a little to continue building upon this EA. The last one that works is #5 (attached) and it compiles fine.

But when I got to #6 and #6b where I added a TRIX indicator, I tried to compile it and there were errors in the MetaEditor. I went back to EA Wizard and did “Test Validity” and it said it was a valid EA. I then thought it might be the problem I had before with the MT4’s build number was a lower version to the MetaEditor’s build number. So I tried compiling it with both MedaEditor’s and it di dnot fix the problem.

What do I do to fix this as the EA Wizard says it is a valid EA, but MT4 gives warning when compiling it. I included the log files attached so can see the errors I recieved (in the ziped files).

I just tried testing and only added this one indicator to #5. That indi is what is causing the problems. I looked at the mq4 file and it looks like what is causing the problems are the extern parameters. Is this correct? What do I need to do to make it usuable? Also, why does the EA Wizard say it is valid.

**Update**
I went through the code and removed the items causing the errors. Now it works. Maybe the Validity check can check for this as well? It was a little confusing why EA Wizard allowed it but MT4 rejected it.

-Stearno

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

11 years ago #121000

Hi,

there was no attachment in your post, so can you tell me what was the error?

EA Wizard cannot check MetaTrader compiler errors, if there are errors in custom indicator.
However I can improve the validity check, just please let me know where the problem was.

Mark

Mark
StrategyQuant architect

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #121016

Mark,
Sorry, the indicator is attached.

I understand Validity cannot check MT4 compilation errors. I was more suggesting that it uses the same logic in its test as the MT4 has which produces the compilation errors. But maybe that is too difficult (too many possible errors) or you don’t have access into the software code to even see the logic. Anyway, I wanted to pass on this situation for you to decide what is best to do (or not do) for the future. I fixed my problem as I have a modified indicator that works better in an a EA.

Thanks

Stearno

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

11 years ago #121027

Hi,

the problem with that indicator was probably that EA Wizard didn’t recognize it correctly, we fixed it in the newest version.

It is not possible for EA Wizard to validate code for MetaTader, but the code generated by EAW should be without any problems.
If you’ll have any compilation error on an EA generated by EAW just send it to me (both sqw and mq4 files) and we’ll look at it.

best regards,

Mark

Mark
StrategyQuant architect

0

stearno

Customer, bbp_participant, community, 379 replies.

Visit profile

11 years ago #121030

Okay, I pass this on in case it helps.

Yes, I agree the indicator is complicated. Errors occur in any EA when using this indicator. So I have attached a simple EA sqw file to show the compilation errors with this indicator. If export the MQ4 file from EA Wizard and compile it, you will see the errors.

Also, I have inculded the same indicator that I was able to modify to work in EA Wizard.

0

Viewing 10 replies - 1 through 10 (of 10 total)