Supertrend EA Only Taking Shorts

Ebarrow123

Newbie
Feb 2, 2023
8
0
2
29
Hello,

I made an EA that takes trades in the direction of the supertrend. The problem is that when I run it through the strategy tester it is only taking short positions. I am using eabuilder.com to make the code for this ea, I don't know how to code them but If I have someone diagnose the potential error in the code i'm sure I could figure it out.

I have tried parameters from several different supertrend indicators on both MT4 and MT5 and am always getting the same result. I will attach the source code for a simple supertrend bot (9/20 ema cross in the direction of the supertrend) as well as the code for the supertrend indicator that the bot is made with. I am wondering if this in an error with the actual code, the Metatrader Stradegy tester, or a problem with eabuilder.com with generating the code. Any solution or advice for this issue would be greatly appreciated!
 

Attachments

  • supertrend (3).mq5
    5.3 KB · Views: 12
  • SuperTrend Bot.mq5
    16.5 KB · Views: 14

Ebarrow123

Newbie
Feb 2, 2023
8
0
2
29
What does it say in the Journal tab for the tests you run? It should report if there are some execution errors.
Thanks for your reply

There is nothing in the Journal tab but I was able to troubleshoot this a little bit further. I laid out the codes side by side and observed the differences and deleting this "_1" in the "open buy order" code it made it start taking buy orders. I will attach a picture for reference.

My problem now is I want price to be above the (10,1) supertrend but I also want price to be above (10,3) supertrend. So i tried to do the same procedure adding a 3 multiplier... I will attach this new bot example too. Notices in lines 443 and 444 of the attached example there is a _1 and a _12 for the 1 multiplier and 3 multiplier respectively. I deleted the _1 and _12 to make the buy order identical to the sell order (lines 468 and 469) just as I did in my first example and again it wont take buy orders for this new example.

So Ive identified the issue lies somewhere in those lines of code. Any insight on this would be greatly appreciated!
 

Attachments

  • examplebot.mq5
    19.3 KB · Views: 9
  • IMG_1631.jpg
    IMG_1631.jpg
    477.6 KB · Views: 5

Ebarrow123

Newbie
Feb 2, 2023
8
0
2
29
also to reiterate I use eabuilder.com to make these EAs and I dont know much about code so it might be something that the EAbuilder software is doing to the code. This is probably a very easy fix for someone who knows about code.
 

Ebarrow123

Newbie
Feb 2, 2023
8
0
2
29
I believe you are reading the wrong buffer numbers from the Supertrend indicator. I think you are supposed to read the buffer number 2 for both cases - the Buy and Sell signals.
What does that mean? How should it appear in the code to make it place orders?
 

Ebarrow123

Newbie
Feb 2, 2023
8
0
2
29
You mention buffer number in the CopyBuffer calls. I think you can control that via EABuilder too because you somehow managed to set different buffers for Buy and Sell (1 and 0).
as I am completely lost when it comes to coding jargon, what must the buy order code lines read so that they may execute orders just as the sell lines do. Thank you for your help.
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
Try changing 1's and 0's that are bolded in these lines to 2:
if(CopyBuffer(supertrend3_handle, 1, 0, 200, supertrend3_1) <= 0) return;
if(CopyBuffer(supertrend3_handle2, 1, 0, 200, supertrend3_12) <= 0) return;
if(CopyBuffer(supertrend3_handle, 0, 0, 200, supertrend3) <= 0) return;
if(CopyBuffer(supertrend3_handle2, 0, 0, 200, supertrend32) <= 0) return;
 

Ebarrow123

Newbie
Feb 2, 2023
8
0
2
29
Try changing 1's and 0's that are bolded in these lines to 2:
if(CopyBuffer(supertrend3_handle, 1, 0, 200, supertrend3_1) <= 0) return;
if(CopyBuffer(supertrend3_handle2, 1, 0, 200, supertrend3_12) <= 0) return;
if(CopyBuffer(supertrend3_handle, 0, 0, 200, supertrend3) <= 0) return;
if(CopyBuffer(supertrend3_handle2, 0, 0, 200, supertrend32) <= 0) return;
This was the answer!! all is working. Thank you