Help needed with my Grid EA,
Results 1 to 8 of 8

Thread: Help needed with my Grid EA,

  1. #1
    Hey Guys,

    As a novice programmer, starting out, Ive been playing with this grid EA for a few weeks, trying to clear out some of the features in it which I find are'nt significant.

    However, Ive currently encounted an error message once I attempt to Compile it.

    And that I can't for the life span of me work out how to fix it,
    Its telling me I've unbalanced Parethisis,

    I was just wondering whether some Coding Gurus, might have a sec to have a fast look at it for me. ?


    Many thanks in advance to anyone who can shed some light on what Ive done.

    Marty.
    https://www.forexforum.co.za/attachm...1082926739.mq4

  2. #2
    It seems like a code is missing
    illustration below.... if ( ((traderate . . . Where's the remainder?
    Sorry, not sure I will help...I looked in the majority of the mounts.



    If (( IsPosition(traderate,stage *GridSize,true) == false ) (doit == true)) // test if we've got no open orders close to my price: if yes, place one on

    double myStopLoss = 0;
    if ( StopLoss gt; 0 )
    myStopLoss = traderate-point*StopLoss;
    if ( traderate gt; Ask )
    entermode = OP_BUYSTOP;
    else
    entermode = OP_BUYLIMIT;
    if ( ((traderate



    }
    }

  3. #3
    Hi martaroony,

    What I am going to say might come across as rude, or condesending, but I'm honestly just trying to help. From looking at your code which you are a self taught programmer I'm guessing. That is great, it is better to see you getting out and having a go. It's fantastic to find you have put lots of opinions in, heaps of experience developers (me included) are guilty of not doing this, but there are a few things on your style which make it really hard to read, and this would be why you are struggling to debug it. I started to try and neaten it up for you, but it was too much of a mess and could take me a very long time... and I thought, give a man a fish... and all that. I will try and teach you how you can fish.

    By the way, I'm not an MQ4 specialist, but I was a programmer for a few years coding in VB, C and C , and also the fantastic design is universal across languages. Everything I will go through now is just suggestions on how best to make your code easier to read and upgrade later on (and debug). It's not a comment on the system, or even the coding.

    1) The very first thing I'd say is declare all your variables at the peak of the relevant function, rather than as you need them. As with everything I will mention here, it is going to work either way, but in the top makes for more readable code.

    Two ) I'm going to paste a chunck of code you'd below, then comment on it...
    for(int I=totalorders-1;igt;# 1;m --)
    OrderSelect(I, SELECT_BY_POS, MODE_TRADES);
    // we utilize iTime so that it functions in backtesting


    if (( MathAbs(iTime(Symbol(),5,0)-OrderOpenTime()) gt;= xHours*60*60 ) (iTime(Symbol(),5,0)gt;0))
    bool result = false;
    //Close opened long position
    if ( OrderType() == OP_BUY ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
    //Close opened short position
    if ( OrderType() == OP_SELL ) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
    //Close pending order
    if ( OrderType() gt; 1 ) result = OrderDelete( OrderTicket() );


    ------------------------------------------------
    Ok, where do I begin.

    3) First of all, since you don't have a open ribbon right after the for loop, the one thing that will be at the loop at the OrderSelect announcement. I'm guessing that this isn't what you planned (since there is not any point in this). As a rule you write a for statement, put a curly brace onto the very next line. Lineup when you only wish to loop 1. Same goes for while and if statements.

    4) Your indentation is all wrong. The way it ought to be is... everything goes directly under everything else unless you've got an if/while/for/case statement. Open curly braces must be inline with THEIR CORRESPONDING final brace. After the case statement, on the next We will use a open curly brace in line. The line will be indented 1 tab. If we are completed with the for/while/if/case, we shut the curly brace consistent with the open one (that was inline with the for/while/if/case statement). If we have nested statements, simply follow the same proceedure. Oh, and do not be scared to put some blank lines in where logical. Below is a copy of I think the code should appear. Have a look and tell me if you do not think it's easier to trace...

    if (( MathAbs(iTime(Symbol(),5,0)-OrderOpenTime()) gt;= xHours*60*60 ) (iTime(Symbol(),5,0)gt;0))

    result = false;

    //Close opened long position
    if ( OrderType() == OP_BUY )

    result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );


    //shut opened short position
    if ( OrderType() == OP_SELL )

    result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );


    //Close pending order
    if ( OrderType() gt; 1 )

    result = OrderDelete( OrderTicket() );


    } // proc DeleteAfter()

    In doing this, I Believe I just found one of your problems... You're missing a close curly brace at the DeleteAfter function. I think you will discover that as soon as you fix that issue, a raft longer will look. Then the code simply will not do exactly what you want it to do, if not complile errors. If you do not go through and neaten it up like this, you will have a nightmare debugging, and most individuals will be fairly reluctant to look over your code to assist you (simply because it requires an infinite amount more attempt to look at messy code).

    I trust this helps. Should you clean up it, and still can't locate the issue, post , or PM me, and I'll have another look. As soon as you get it working please note the results of the EA, I'd love to see how it goes.

  4. #4
    Oops, for whatever reason, the indending did not work in my last article, and this was a significant part of my point. I shall try again now, but when it does not work again, you will just have to read the description...

    for(int I=totalorders-1;igt;=0;I--)

    OrderSelect(I, SELECT_BY_POS, MODE_TRADES);
    // we use iTime so it functions in backtesting
    if (( MathAbs(iTime(Symbol(),5,0)-OrderOpenTime()) gt;= xHours*60*60 ) (iTime(Symbol(),5,0)gt;0))

    result = false;
    //Close opened long position
    if ( OrderType() == OP_BUY )

    result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );


    //shut opened short position
    if ( OrderType() == OP_SELL )

    result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );


    //Close pending order
    if ( OrderType() gt; 1 )

    result = OrderDelete( OrderTicket() );



    }

  5. #5
    Ok, one more time. I've used dots instead of spaces.

    for(int i=totalorders-1;igt;=0;i--)

    . . .OrderSelect(I, SELECT_BY_POS, MODE_TRADES);
    ...// we utilize iTime so it functions in backtesting
    . . .if (( MathAbs(iTime(Symbol(),5,0)-OrderOpenTime()) gt;= xHours*60*60 ) (iTime(Symbol(),5,0)gt;0))
    ...
    ....result = false;
    ...//Close opened long position
    ....if ( OrderType() == OP_BUY )
    ...
    ....result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
    ...

    ...//Close opened short position
    ....if ( OrderType() == OP_SELL )
    ...
    ....result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
    ...

    ...//shut pending order
    ....if ( OrderType() gt; 1 )
    ...
    ....result = OrderDelete( OrderTicket() );
    ...
    ...

  6. #6
    Hey Mate Thanks for this Info,

    This has been a huge information that has just made me realise something.

    I should have said, that I took a Grid EA written by somebody else and Butchered it, believing I could alter it to suit myself.

    Thus all of the coding you saw was really written by someone else, I needed to clear that up, as I wouldnt like to accept any credit for any of it.

    The one thing I could take credit for is entirely stuffing a perfectly good,( be it slightly over complied), but still functioning EA.

    I most probley out smarted myself, thinking I could just Cut out all the pieces I didnt desire, Not realising there was more to it than just that.

    So I guess im back to square one. .

    Thanks cre8iveq, I appreciate you helping me realise some of the complexity of communicating.

    Thanks Mate, Regards Marty.

  7. #7
    No worries. Should you spend some decent time back testing, and can reveal some results that are great, I will help you code what you want to do. If you desire PM me.

  8. #8
    I just sent you a PM, outlining what Im tring to do.

    This time Ive started again with a new shell Grid EA, its a lot simpler.

    I've attached it incase you wish to have a look.

    The next EA is a hedge EA with the particular,

    ( close all open positions if proft = X % account balance) coding

    That Im attempting to incorporate into my grid EA.

    If you had time, and or could offer some advise it would be great.


    Thanks Mate , Marty.
    https://www.forexforum.co.za/attachm...9072082104.mq4
    https://www.forexforum.co.za/attachm...1066632476.mq4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.