Reply

Go Long and Go Short rules are the same, but different results

7 replies

deweymcg

Subscriber, bbp_participant, community, 24 replies.

Visit profile

6 years ago #113717

I have been trying to code a simple EA that will set pending orders to go long or short when price breaks out of the high or low of the range during a specific time of day. When I tested my first draft before adding anything else, the short trades were taken correctly when price broke the low but the long pending orders were nowhere close yet the instructions for each were the same.

 

Am I missing something? You can see from the PIC that longs and shorts are the same. is there a better way to do this?

 

Also–I want to add a condition where it will not take a trade f the difference between the highest in the range and the lowest in the range is either over a certain number or under a certain number. I assume I can use the PRICE_DIFF indicator but do I need  also to use converttorealpips or something else. For instance of the range is over 50 pips or less than 10 pips we will pass.

0

tomas262

Administrator, sq-ultimate, 678 replies.

Visit profile

6 years ago #130546

Hi deweymcg,

 

tried this in MetaTrader and it seems it takes longs and short correctly (as rules are set). If it seems not to be working properly to you, then please, provide as much information (screenshots, details on how you test) as possible so we can quickly identify the problem if there’s any.

You can simply use ConvertToPips + Subtraction function for this in your rule. I edited your example and attach it here.

 

 

0

deweymcg

Subscriber, bbp_participant, community, 24 replies.

Visit profile

6 years ago #130552

Hi deweymcg,

 

tried this in MetaTrader and it seems it takes longs and short correctly (as rules are set). If it seems not to be working properly to you, then please, provide as much information (screenshots, details on how you test) as possible so we can quickly identify the problem if there’s any.

You can simply use ConvertToPips + Subtraction function for this in your rule. I edited your example and attach it here.

 

Thanks. I did some more testing and saw why they were different but not sure how to fix it. If the last session had a buy but not a sell, it kept the previous sell stop even when I had the pending order good for X number of bars. I tried changing Replace Existing Order to true but that slowed it down tremendously and the journal showed one pending order after another as if it repeated the process with every tick. . If I could find a simple way to delete the pending order after a certain time or condition I think I could make it work properly but I only see commands for closing orders, not deleting pending orders.

0

tomas262

Administrator, sq-ultimate, 678 replies.

Visit profile

6 years ago #130585

Hi deweymcg,

 

There is a function in EA Wizard – Close position (Order magic number) – this should close any order i.e. open position OR cancel pending order too

Have you thought about using market orders instead of stop orders? For example if (Bid > HighestInRange(03:00, 07:00)) Enter Long Market. This could work well too

0

deweymcg

Subscriber, bbp_participant, community, 24 replies.

Visit profile

6 years ago #130610

For the life of me I cannot see why this now doesn’t take trades. Here is a PIC of what I am trying to do and my latest version incorporating the suggestions but I cannot see where the error is. If anyone could have a look and help it would be greatly appreciated

0

jcf

Subscriber, bbp_participant, community, 1 replies.

Visit profile

5 years ago #132972

Check magic #’s

0

tomas262

Administrator, sq-ultimate, 678 replies.

Visit profile

5 years ago #132998

Will try to check where the problem is. Magics seems to be ok

0

tomas262

Administrator, sq-ultimate, 678 replies.

Visit profile

5 years ago #133030

I think the problem is with BoxStart time which cannot a greater than BoxEnd value. So at 1 o’clock your strategy seeks for 21:00 candle which is not available for that specific date and MT4 reruns error = “Not found time from”

 

When I set BoxStart to 01:00, BoxEnd to 02:00 and HourBegin to 03:00 for example then it works since Start < End

 

Workaround here for you could be using Lowest and Highest functions for N bars back since you always know how many bars you have in that time range

0

Viewing 8 posts - 1 through 8 (of 8 total)