Need help please with buy sell code

 

Greetings

To the senior members here and Coder's Guru can I say thanks for great help you have provided to all of us here who are learning programming. I have been working through the tutorials and it is a big help,

I am attempting to build an EA with nonlagdot and QQE indicators. Basically I want to do some testing with an EA that opens and closes based on the NonLagMA up and down and the QQE line cross. I have posted this strategy in the 'Suggestions for Trading' section.

I have had a go with EA Builder starting with just the nonlagma indicator. I have managed to get the EA to call the indicator but I can't get the code right for the buy sell commands. When I test the EA at the moment the EA makes the first trade and then closes it on next candle and then does about 50 open trades and closes on the same candle. Would really appreciate some help with how to code the buy sell and closebuy and sell and to understand how to input this into EABuilder. So what I am trying to do is simply buy on up change and sell on down change and close buy and sell orders on color changes as well.

I'm using a version of nonlagma called Dots.mq4. Here is the buffer information for Dots.mq4

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 RoyalBlue

#property indicator_width1 2

#property indicator_color2 Red

#property indicator_width2 2

//---- input parameters

extern int Length = 10;

extern int AppliedPrice = 0;

extern int Filter = 0;

extern double Deviation = 0;

extern int Shift = 0;

//---- indicator buffers

double UpBuffer[];

double DnBuffer[];

//---- global variables

double Cycle = 4;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(2);

SetIndexStyle(0, DRAW_ARROW);

SetIndexBuffer(0, UpBuffer);

SetIndexStyle(1, DRAW_ARROW);

SetIndexBuffer(1, DnBuffer);

SetIndexEmptyValue(0, EMPTY_VALUE);

SetIndexEmptyValue(1, EMPTY_VALUE);

SetIndexArrow(0, 159);

SetIndexArrow(1, 159);

SetIndexLabel(0, "Up");

SetIndexLabel(1, "Dn");

SetIndexShift(0, Shift);

SetIndexShift(1, Shift);

SetIndexDrawBegin(0, Length * Cycle + Length);

SetIndexDrawBegin(1, Length * Cycle + Length);

IndicatorShortName("Dots("+Length+")");

IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));

return(0);

For myEA called test4.1 here is the Variable definition

//+------------------------------------------------------------------+

//| Variable Begin |

//+------------------------------------------------------------------+

double Var1 = iCustom(NULL, 0, "Dots", 10, 0, 0, 0, 0, 0, Current + 0);

double Var2 = iCustom(NULL, 0, "Dots", 10, 0, 0, 0, 0, 1, Current + 0);

double Buy1_1 = Var1 ;

double Buy1_2 = 0;

double Sell1_1 = Var2 ;

double Sell1_2 = 0;

double CloseBuy1_1 = Var2 ;

double CloseBuy1_2 = 0;

double CloseSell1_1 = Var1 ;

double CloseSell1_2 = 0;

I have attached the whole EA.

What I was trying to do was to signal the buy with the expression Var1 > 0 or Var 1 > Var2

//+------------------------------------------------------------------+

//| Signal Begin(Entry) |

//+------------------------------------------------------------------+

if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;

if (Sell1_1 > Sell1_2) Order = SIGNAL_SELL;

And the close by with the expression Var2 = 0 or Var1 < Var2

//+------------------------------------------------------------------+

//| Signal Begin(Exit Buy) |

//+------------------------------------------------------------------+

if (CloseBuy1_1 > CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+

//| Signal Begin(Exit Sell) |

//+------------------------------------------------------------------+

if (CloseSell1_1 > CloseSell1_2) Order = SIGNAL_CLOSESELL;

Thanks in advance for any help with this.

Files:
test4.1.mq4  10 kb
 
pacinvest:
Greetings

To the senior members here and Coder's Guru can I say thanks for great help you have provided to all of us here who are learning programming. I have been working through the tutorials and it is a big help,

I am attempting to build an EA with nonlagdot and QQE indicators. Basically I want to do some testing with an EA that opens and closes based on the NonLagMA up and down and the QQE line cross. I have posted this strategy in the 'Suggestions for Trading' section.

I have had a go with EA Builder starting with just the nonlagma indicator. I have managed to get the EA to call the indicator but I can't get the code right for the buy sell commands. When I test the EA at the moment the EA makes the first trade and then closes it on next candle and then does about 50 open trades and closes on the same candle. Would really appreciate some help with how to code the buy sell and closebuy and sell and to understand how to input this into EABuilder. So what I am trying to do is simply buy on up change and sell on down change and close buy and sell orders on color changes as well.

I'm using a version of nonlagma called Dots.mq4. Here is the buffer information for Dots.mq4

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 RoyalBlue

#property indicator_width1 2

#property indicator_color2 Red

#property indicator_width2 2

//---- input parameters

extern int Length = 10;

extern int AppliedPrice = 0;

extern int Filter = 0;

extern double Deviation = 0;

extern int Shift = 0;

//---- indicator buffers

double UpBuffer[];

double DnBuffer[];

//---- global variables

double Cycle = 4;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(2);

SetIndexStyle(0, DRAW_ARROW);

SetIndexBuffer(0, UpBuffer);

SetIndexStyle(1, DRAW_ARROW);

SetIndexBuffer(1, DnBuffer);

SetIndexEmptyValue(0, EMPTY_VALUE);

SetIndexEmptyValue(1, EMPTY_VALUE);

SetIndexArrow(0, 159);

SetIndexArrow(1, 159);

SetIndexLabel(0, "Up");

SetIndexLabel(1, "Dn");

SetIndexShift(0, Shift);

SetIndexShift(1, Shift);

SetIndexDrawBegin(0, Length * Cycle + Length);

SetIndexDrawBegin(1, Length * Cycle + Length);

IndicatorShortName("Dots("+Length+")");

IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));

return(0);

For myEA called test4.1 here is the Variable definition

//+------------------------------------------------------------------+

//| Variable Begin |

//+------------------------------------------------------------------+

double Var1 = iCustom(NULL, 0, "Dots", 10, 0, 0, 0, 0, 0, Current + 0);

double Var2 = iCustom(NULL, 0, "Dots", 10, 0, 0, 0, 0, 1, Current + 0);

double Buy1_1 = Var1 ;

double Buy1_2 = 0;

double Sell1_1 = Var2 ;

double Sell1_2 = 0;

double CloseBuy1_1 = Var2 ;

double CloseBuy1_2 = 0;

double CloseSell1_1 = Var1 ;

double CloseSell1_2 = 0;

I have attached the whole EA.

What I was trying to do was to signal the buy with the expression Var1 > 0 or Var 1 > Var2

//+------------------------------------------------------------------+

//| Signal Begin(Entry) |

//+------------------------------------------------------------------+

if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;

if (Sell1_1 > Sell1_2) Order = SIGNAL_SELL;

And the close by with the expression Var2 = 0 or Var1 < Var2

//+------------------------------------------------------------------+

//| Signal Begin(Exit Buy) |

//+------------------------------------------------------------------+

if (CloseBuy1_1 > CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

//+------------------------------------------------------------------+

//| Signal Begin(Exit Sell) |

//+------------------------------------------------------------------+

if (CloseSell1_1 > CloseSell1_2) Order = SIGNAL_CLOSESELL;

Thanks in advance for any help with this.

Hi Pacinvest,

Maybe you can use this Ea i'm posting, as an example, will be helping you tomorrow if still needed, now got to get some zzz's, anyway the Ea is using nonlag (dot or ma, not sure which one) and QQE, along with some other indicators.

 

Thanks working on it

Awesome MrTools, give me a bit to work on this and I will report back.

 

Still Need Some Assistance Please with coding entry signal

Greetings

I have had a good look the the Bouncing pip EA versions and how they define the the variables, call the custom indicator and code the buy sell/ close logic. I still have not quite got there with my simple EA. The EA attached here was mostly done with EA Builder and then I tried to match the Bouncing Pip approach to the buy/sell coding. My EA calls up the indicator OK and starts to trade but then starts firing away trades on one candle after the first trade. Obviously something is not right.

Here's what the code looks like for definition of the variables:

//+------------------------------------------------------------------+

//| Variable Begin |

//+------------------------------------------------------------------+

double Var1 = iCustom(NULL, 0, "nonlagdot", NLD_Price, NLD_Displace, NLD_Filter, NLD_Color, NLD_ColorBarBack, 1, Current + 0);

double Var2 = iCustom(NULL, 0, "nonlagdot", NLD_Price, NLD_Displace, NLD_Filter, NLD_Color, NLD_ColorBarBack, 2, Current + 0);

double Var3 = iCustom(NULL, 0, "nonlagdot", NLD_Price, NLD_Displace, NLD_Filter, NLD_Color, NLD_ColorBarBack, 0, Current + 0);

double Buy1_1 = Var1 ;

double Buy1_2 = 1000;

double Sell1_1 = Var2 ;

double Sell1_2 = 1000; //can you explain please why 1000 is used here?

Here's entry signal code:

//+------------------------------------------------------------------+

//| Signal Begin(Entry) |

//+------------------------------------------------------------------+

if (Buy1_1 < Buy1_2) Order = SIGNAL_BUY;

if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;

I haven't got any close signal code in the EA yet, was just trying to get the entry code right and had the trailing stop option going to close trades in this version. I do want to be able to close on the opposite of the buy meaning when the nonlagdot changes color.

So would really appreciate some help with this. Basically with the variable defined via EA builder as I have done, I need to understand how to to write the entry signal code. It would be good to know how to do this in EA Builder too but I can work with the code fix directly in MetaEditor.

Just another thing I am not able to get the Bouncing Pips EA's to work in strategy tester. They are firing orders against the signal it seems and running up strings of losses. Not sure what is going wrong. I would very much like to do some testing with ver44 as there is so many options there. Any hints as to what is going on. Are people able to run this in Strategy Tester and are people trading with it?

I have attached the EA below. Thanking you in advance...................nldv3.mq4

Files:
nldv3.mq4  10 kb
 
pacinvest:
Greetings

I have had a good look the the Bouncing pip EA versions and how they define the the variables, call the custom indicator and code the buy sell/ close logic. I still have not quite got there with my simple EA. The EA attached here was mostly done with EA Builder and then I tried to match the Bouncing Pip approach to the buy/sell coding. My EA calls up the indicator OK and starts to trade but then starts firing away trades on one candle after the first trade. Obviously something is not right.

Here's what the code looks like for definition of the variables:

//+------------------------------------------------------------------+

//| Variable Begin |

//+------------------------------------------------------------------+

double Var1 = iCustom(NULL, 0, "nonlagdot", NLD_Price, NLD_Displace, NLD_Filter, NLD_Color, NLD_ColorBarBack, 1, Current + 0);

double Var2 = iCustom(NULL, 0, "nonlagdot", NLD_Price, NLD_Displace, NLD_Filter, NLD_Color, NLD_ColorBarBack, 2, Current + 0);

double Var3 = iCustom(NULL, 0, "nonlagdot", NLD_Price, NLD_Displace, NLD_Filter, NLD_Color, NLD_ColorBarBack, 0, Current + 0);

double Buy1_1 = Var1 ;

double Buy1_2 = 1000;

double Sell1_1 = Var2 ;

double Sell1_2 = 1000; //can you explain please why 1000 is used here?

Here's entry signal code:

//+------------------------------------------------------------------+

//| Signal Begin(Entry) |

//+------------------------------------------------------------------+

if (Buy1_1 < Buy1_2) Order = SIGNAL_BUY;

if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;

I haven't got any close signal code in the EA yet, was just trying to get the entry code right and had the trailing stop option going to close trades in this version. I do want to be able to close on the opposite of the buy meaning when the nonlagdot changes color.

So would really appreciate some help with this. Basically with the variable defined via EA builder as I have done, I need to understand how to to write the entry signal code. It would be good to know how to do this in EA Builder too but I can work with the code fix directly in MetaEditor.

Just another thing I am not able to get the Bouncing Pips EA's to work in strategy tester. They are firing orders against the signal it seems and running up strings of losses. Not sure what is going wrong. I would very much like to do some testing with ver44 as there is so many options there. Any hints as to what is going on. Are people able to run this in Strategy Tester and are people trading with it?

I have attached the EA below. Thanking you in advance...................nldv3.mq4

Hi Pacinvest,

Here's a simple Ea i put together using Nonlagdot and Qqe, it works and didn't back test all that bad but there's a lot of different settings to try out to make it better. It has money management and a trailing stop.You will need these versions of the indicators in your indicators folder for it to work.

Files:
 

Thanks MrTools

Great I will give this a try and get back to you.

 

Still struggling

Hi MrTools and friends

Well I had a go with several different approaches to the entry code for buying on the change of color of the nonlagdot indicator as per the EA and indicator version you attached in your last post. I am getting the indicator to load and some trades are made but they don't seem to happen at the right time.

The approach of your EA is to call for a buy signal if nltrend > 0 It would help if you could explain what the values are that are generated in this buffer so I had a better feeling for what I was trying to do with the buy signal code.

The other problem is closing the trades which I want to do in its basic form with the change in color of the nonlagdot indicator.

As I said in the initial post I have lots of trading ideas to build on to this that I am using in manual trading but, I think I need to get the basic EA function of opening and closing trades right with an EA before I go for next steps.

I am also curious as to the trade logic that is coded into your EA for the filter or trade signal of the QQE indicator. Could you explain as I can't see what this is from the rather odd trading pattern I get from the EA in strategy tester.

Is it possible that these problems are a result of MT4 Strategy Tester not handling custom indicator code? Probably not as I have other complicated EA's with custom indicator that do work OK on my strategy tester. Thanks for help.....

Can attach my latest EA trial referred to above if you need to look at it.

 

Hi Pacinvest,

In the code for indicator non lag dot, buffer 4 is the trend buffer if trend > 0 is uptrend and opposite for sell, for Qqe for buy or sell you only need the 1st 2 buffers for a Ea call, so the way i coded it is if non lag dot in uptrend and if qqe rsi ma(buffer 0) crosses trlevelslow(buffer 1) or rsima greater than Trlevelslow then buy and opposite for sell.

Would recommend back testing the Ea in visual mode with the indicators on your chart and watch the indicators to make sure if they repaint or not, because it could be the case, and if they don't repaint then try it fwd testing because usually back testing is usually only good to see if certain things working right, in the Ea.

 

...

For NonLagDot : make sure that the ColorBarBack parameter is set to 0 (zero) otherwise it will repaint

 

Thanks Guys

Ok I have some things to try.

I will try the trend buffer signal approach again.

I have got the EA buying and selling pretty well now with a the mode = 0 buffer or MA Buffer. The logic I used that worked is to say MA buffer = upbuffer for buy signal. This is working but there are two problems.

1) Sometimes the EA is doing trade in what appears to be the middle of the candle or before the close I think as the dot has not changed color. Do I need some code to tell the EA to execute trades at candle close?

2) When I reverse the logic for buyclose and sellclose the EA starts opening and closing trades very fast so something is wrong with this simple approach. Again the execution of close calls needs to happen at candle close. I'm thinking that EA Builder is not putting in this code. Is that correct? I will attach the EA version that has this problem with closing trades for you to have a look at. Note if I take out the close rules and use stop loss and take profit settings the execution of buy and sell looks pretty good except for the problem raised in 1) above.

If I use the trend buffer for trade logic would that overcome the problems above?

I have checked the colorback parameter that is set to 0

nldv4_1.3.mq4.

Would appreciate any comment.

Files:
nldv4_1.3.mq4  11 kb
 

More Results

Ok

I have got the buy sell code working using trend buffer as you suggest, but I still have exactly the same two problems as above with trades not being executed at candle close, or I think that is what is going wrong.

Thanks for the help guys, starting to understand this better now.

Reason: