Not logged in
Viewing 11 posts - 1 through 11 (of 11 total)

Forums>StrategyQuant>General Discussion>Lets make an Automatic Unique MagicNumber for each strategy in our portfolio!

  • #195927|
    Karish
    Customer
    480 Posts

    So…,
    As you all already know when you do have a portfolio SQ3 does not give you the option to create some kind of file with all the rules of the strategies that are inside the portfolio so that MT4 could read from that file and we wont need to have 100 windows opened inside MT4 with EAs..

    So.. until SQ4 will be ready with some kind of feature like that,
    we can make our life better by cutting off some part of our manual work while we are ready to trade our portfolio,

    This topic will be focusing on how to make our work more efficient and less manual and more automatic,

    i would like to get some help for you guys that have some coding knowledge,

    i think the first thing we have to do is an Automatic Unique MagicNumber,
    i am not that of an expert and i would like to get some help with building this,
    my idea is to get the name of the EA file which is for example: “Strategy 4.222.”
    take off the string “Strategy” + the string “.” so we would have only an Integer of “4222”,
    thats it :), i just dont know how to do it and i would like to have some help and it would be publicly shared with the members :),

    later on we can continue to improve and cut off parts of our “exporting & trading the portfolio” workflow.
    thank you for your participation and help :)

    #195946
    Customer
    484 Posts

    Play with this:

    public static String getOnlyNumerics(String str) {
    if (str == null) {
    return null;
    }
    StringBuffer strBuff = new StringBuffer();
    char c;
    for (int i = 0; i < str.length() ; i++) {
    c = str.charAt(i);
    if (Character.isDigit(c) || c == ‘.’) {
    strBuff.append(c);
    }
    }
    return strBuff.toString();
    }

    #195978
    Karish
    Customer
    480 Posts

    NVM already solved it thanks @notch,
    my share to you guys:

    string Numerics_only(string numstring){int iPos=0;while(iPos < StringLen(numstring)){string c = StringSubstr(numstring, iPos, 1);if(c < “0” || c > “9”) StringReplace(numstring, c, “”);else ++iPos;}return Numerics_only;}
    string EAName=WindowExpertName();
    int MagicNumber = Numerics_only(EAName);
    string CustomComment = EAName+”_”+MagicNumber;

    #196025
    Customer
    484 Posts

    Cheers Karish, have you managed to get the code you posted to compile in MT4?

    #196026
    Karish
    Customer
    480 Posts

    Shit… cant edit in that new forum design.., damn should have keep the option to use the older forum, they had so many simple options there..

    here is the full code, Forget about changing MagicNumbers ever again!:

    string Numerics_only(string stringtonum){
    int iPos=0;
    while(iPos < StringLen(stringtonum)){
    string c = StringSubstr(stringtonum, iPos, 1);
    if(c < “0” || c > “9”) StringReplace(stringtonum, c, “”);
    else ++iPos;
    }
    return stringtonum;
    }
    string EAName=WindowExpertName();
    int MagicNumber = Numerics_only(EAName);

    *** REPLACE THE OLDER “MagicNumber” PARAMETER THAT ALREADY EXIST WITH THIS WHOLE FUNCTION.
    HAVE FUN!

    #196053
    Customer
    484 Posts

    Perfect. Cheers

    #197223
    Customer
    4 Posts

    Hi Karish, where I must replace the older magicnumber parameter with this new one? In which file?

    #197231
    Karish
    Customer
    480 Posts

    Hi Karish, where I must replace the older magicnumber parameter with this new one? In which file?

    find “extern int MagicNumber=” and replace it,
    all code related files are inside the “Code” folder.

    #197242
    Customer
    4 Posts

    I done it, but thinked, that I’m doing it wrong. Nevertheless thanks.

    #197455
    Customer
    4 Posts

    Hi Karish, where I must replace the older magicnumber parameter with this new one? In which file?

    find “extern int MagicNumber=” and replace it,
    all code related files are inside the “Code” folder.

    Hi Karish, it does not work for me. First it does not compile, because of these quotes “ in: if(c < “0” || c > “9”) StringReplace(stringtonum, c, “”);, so I replaced all of them with this ones “. But it does not work, strategies open orders with magic num. 0. Can you help me? I also tried other changes of this line of code, but without success. Thanks.

    #197459
    Karish
    Customer
    480 Posts

    string Numerics_only(string stringtonum){
    int iPos=0;
    while(iPos < StringLen(stringtonum)){
    string c = StringSubstr(stringtonum, iPos, 1);
    if(c < “0” || c > “9”) StringReplace(stringtonum, c, “”);
    else ++iPos;
    }
    return stringtonum;
    }
    string EAName=WindowExpertName();
    int MagicNumber = Numerics_only(EAName);
    string CustomComment = EAName+”_”+MagicNumber;

    try this one, working fine for me.

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

You must be logged in to reply to this topic.