need coding help please - page 2

unclebigpete
66
unclebigpete  

deVries, if you stopped your rant long enough to explain WHY the code I started with is so 'bad' I might understand what I can do to fix it. Read your response again, and then explain how your answer could help anyone.

Thank you, RaptorUK, finally an answer I can use.

To help explain, I only want this EA to run one one pair, one trade at a time. As I said earlier '... and placed one on each of 5 different pair charts, all on the same MT4 platform...' giving 5 separate (?) charts with that EA on them. At this stage I don't want or need to check Magic Numbers, do I ?

Re the comment on bars, thank you.

Re the slippage, 4/5 brokers etc, at this stage that doesn't matter, does it ? I'm using this for myself, on the same broker etc.

unclebigpete
66
unclebigpete  
and I forgot to add, I'm not looking for a short cut, just some help to get over a problem.
unclebigpete
66
unclebigpete  
Sorry, somehow I missed the other answers, so I apologise for the 'rant' comment. and thank you for the actual assistance.

And I have tested it, and it works fine, no errors, no warnings. So why doesn't it work on a live chart ? (I haven't implemented the suggestions above yet)
Simon Gniadkowski
17392
Simon Gniadkowski  
unclebigpete:

1. At this stage I don't want or need to check Magic Numbers, do I ?

2. Re the slippage, 4/5 brokers etc, at this stage that doesn't matter, does it ? I'm using this for myself, on the same broker etc.

1. If you are never going to place a manual trade on any of the same pairs . . . then you can work without Magic Numbers . . . if you forget and happen to place a manual trade on one of the pairs that you have this EA running on then the EA will manage your manual trade too . . . if you code it properly then this won't be an issue.

2. It doesn't matter . . as long as you always remember to set the extern parameters correctly . . for example, the code you posted has a Slippage of 3 . . . on a 5 digit Broker this will equate to 0.3 pip slippage . . . if you code it properly then 3 will always mean 3 pips on both a 4 or 5 digit Broker and then you will have less scope for errors. Not coding it correctly is a short cut that will probably cost you time in the long run . . .

Simon Gniadkowski
17392
Simon Gniadkowski  
unclebigpete:

And I have tested it, and it works fine, no errors, no warnings. So why doesn't it work on a live chart ? (I haven't implemented the suggestions above yet)
You tested it where ? in the Strategy Tester ? where did you look for the errors ?
unclebigpete
66
unclebigpete  
Yes, tested in the strategy tester, and compiled it, getting the 'no errors, no warnings' response.
onewithzachy
1863
onewithzachy  

Al right here's mine :

Get discipline with coding, first parameter of iCustom is <string Symbol>, use Symbol() or NULL instead of zero.

MetaEditor > Navigator Window (Ctrl +D) > dictionary tab > Technical indicator > iCustom

int QQE_4hr    = iCustom( Symbol(), 240, "c_QQEA",  SF,     RSI_Period,    DART_Factor,     0, 1 );
int QQE_4hr_2  = iCustom( Symbol(), 240, "c_QQEA",  SF,     RSI_Period,    DART_Factor,     0, 2 );

You using shift 1 and 2 in 4hrs chart, that's gonna be very long.

The order select I mention before, write it like this.

MetaEditor > Navigator Window (Ctrl +D) > dictionary tab > Trading functions > OrderSelect()

for(int i=0; i<Total; i++)
     {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
        {

I will write more about that OrderSelect() thing.

There are 2 order close, write it like this, both of them

MetaEditor > Navigator Window (Ctrl +D) > dictionary tab > Trading functions > OrderClose()

OrderClose(OrderTicket(),
           OrderLots(),
           OrderClosePrice(),//Bid,
           Slippage,
           MediumSeaGreen);

And I have different approach than RaptorUK's, that give same result though, there are 2 of these, and you have change both of them

if (Ticket > 0)
  {
  if(OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES))
     {
      Print("SELL order opened : ",
             OrderOpenPrice());
             if(SignalMail)
                SendMail("[Signal Alert]",
                         "["
                         +Symbol()
                         +"] "
                         +DoubleToStr(Bid,Digits)
                         +" Open Sell");
       } // if(Order... // ==>> moved from below 
     } // if(Ticket...   
     else
     {
     Print("Error opening SELL order : ",
           GetLastError());
     } // else
   } ==>> move this parenthesis up there

Have fun

:)

Simon Gniadkowski
17392
Simon Gniadkowski  
unclebigpete:
Yes, tested in the strategy tester, and compiled it, getting the 'no errors, no warnings' response.
OK, so no errors when compiled . . . what about errors when you ran it in the Strategy Tester ? Run it again and look in the Journal tab . . .
unclebigpete
66
unclebigpete  

Ran it just now on audnzd from 17/05 to 22/05, and it opened 3 trades, 2 buys that were stopped out, and one sell that was closed at the end of the test.

Here's the Journal info, top line first.

2012.05.22 21:38:51 QQE-4hr_15min- testing-2205: loaded successfully

2012.05.22 21:38:53 QQE-4hr_15min- testing-2205 inputs: MagicNumber=0; Lots=1; Slippage=3; StopLoss=300; TakeProfit=1000; TrailingStop=300; Nbr_Period=10; Multiplier=3;

2012.05.22 21:38:53 2012.05.17 00:00 c_QQEA AUDNZD,H4: loaded successfully

2012.05.22 21:38:53 2012.05.17 00:00 c_QQEA AUDNZD,M15: loaded successfully

2012.05.22 21:39:13 2012.05.17 16:00 QQE-4hr_15min- testing-2205 AUDNZD,H4: open #1 buy 1.00 AUDNZD at 1.29960 sl: 1.29660 ok

2012.05.22 21:39:13 2012.05.17 16:00 QQE-4hr_15min- testing-2205 AUDNZD,H4: BUY order opened : 1.2996

2012.05.22 21:39:13 2012.05.17 18:32 Tester: stop loss #1 at 1.29660 (1.29660 / 1.29698)

2012.05.22 21:39:15 2012.05.18 20:00 QQE-4hr_15min- testing-2205 AUDNZD,H4: open #2 buy 1.00 AUDNZD at 1.30386 sl: 1.30086 ok

2012.05.22 21:39:15 2012.05.18 20:00 QQE-4hr_15min- testing-2205 AUDNZD,H4: BUY order opened : 1.3039

2012.05.22 21:39:15 2012.05.18 23:09 Tester: stop loss #2 at 1.30086 (1.30083 / 1.30121)

2012.05.22 21:39:16 2012.05.21 16:00 QQE-4hr_15min- testing-2205 AUDNZD,H4: open #3 sell 1.00 AUDNZD at 1.29739 sl: 1.30039 ok

2012.05.22 21:39:16 2012.05.21 16:00 QQE-4hr_15min- testing-2205 AUDNZD,H4: SELL order opened : 1.2974

2012.05.22 21:39:17 2012.05.21 23:59 Tester: order #3 is closed

2012.05.22 21:39:17 2012.05.21 23:59 c_QQEA AUDNZD,M15: removed

onewithzachy
1863
onewithzachy  
Your slippage may be the problem. Backtesting never use slippage. Read Testing features and Limit in MetaTrder4 https://www.mql5.com/en/articles/1512