Um den Chat zu nutzen, melden Sie sich bitte an.

Need some coding advise

Aug 24, 2015 at 17:04
608 Angesehen
10 Replies
Mitglied seit May 02, 2012   14 Posts
Aug 24, 2015 at 17:04
Hi everybody,

I wanted to modify some of the codes from my existing EA.

I'm wondering if there's any Angels out there who is willing to help :)


1st : I need the EA to memorize/store the pair symbol(s) for further analysis
-------------------------------------------------------------------------------------------------------
{
if (abc > xyz)
    {
       string rberPair=MarketInfo(Symbol); // I need a code to remember the pair symbol(s) for other execution out from this loop. There'll be up to 28 symbols to memorize if condition met.
    } IS THIS CORRECT? If not, anyone care to provide some guidance? Thanks
}
===============================================================================

2nd : After getting the Symbols,
--------------------------------------------
// this is the outer loop for further analysis and execution
if rberPair >1; // I need to check that if there's symbol exist, then proceed with the below analysis
   {
      if def>ghi
          {buy(rberPair)
              since buy order has been placed, I need to erase this symbol from the (rberPair) slot


Appreciate if anyone could draft me the coding.

Thanking you in advance for your time and kindness.

Have a nice day.

Mitglied seit Nov 21, 2011   1718 Posts
Aug 25, 2015 at 09:16
If you want to store values, you simply create global variables.
Mitglied seit Sep 06, 2011   31 Posts
Aug 25, 2015 at 09:30
I agree with CrazyTrader. use a global variable.
forex_trader_25447
Mitglied seit Dec 21, 2010   131 Posts
Aug 25, 2015 at 10:02
All your writing is full of errors !!!
You define rberPair as string , then compare rberPair to Integer.
MarketInfo have 2 parameters , one is _Symbol (or Symbol()) , you not enter second.

Mine idea is :

1.1 You have to define a list of Symbol, you are going to use, alike :
string MySymbol[28] = {Simbol00,...,Symbol27} // SymbolIndex= from 0 to 27

1.2 Then You can select Symbol this way :
string rberPair=MySymbol[SymbolIndex]; // SymbolIndex= from 0 to 27

2.1 Where you want to search Symbol :
- in selected (MySymbol) // on of 28
- or in Market Watch // did you know what is this

2.2 or the easy way : Your program lines must be like this :
{ string rberPair=''; // main program varible
  ...
  rberPair=''; // OnInit section : no selected Symbol ;
  ...
 // Main program
  { if (abc > xyz) string rberPair=MySymbol[SymbolIndex]; // here select Symbol by SymbolIndex
    ....
    if ( rberPair!='' )
      if ( def>ghi ) { buy(rberPair); rberPair='';} // deselect Symbol when order BUY placed
  }
}
forex_trader_25447
Mitglied seit Dec 21, 2010   131 Posts
Aug 25, 2015 at 10:08 (bearbeitet Aug 25, 2015 at 10:09)
GlobalVariable in Terminal are used to store information when Terminal restarted. (computer is off)
.... that is not what he need.
He simply need to select Symbol in one part (function) of the program,
and use it in other part (function)
Mitglied seit Sep 20, 2014   365 Posts
Aug 26, 2015 at 22:13
I agree with Ivan.

You want to use a list of pairs, and lists are arrays. So lets say I want to go through a list of 2 pairs and do something, say print if the condition is met, it be something like this in Metatrader:

string Symbols[2]={'EURUSD','GBPUSD'};

for (int j = 0; j < ArraySize(Symbols); j++){
      if (Symbol() == Symbols[j]){
        Print ('Symbol is ', Symbols[j]);
    }
}

So in this example if you ran your code on a chart and Symbol() returns either EURUSD or GBPUSD it will print it. Viola. Working with a list. Expand at will....



Mitglied seit Nov 21, 2011   1718 Posts
Aug 26, 2015 at 22:30
I think he wants to compare past data with live data.

Let's say 10 min ago or 1 hour ago... what was the price at specific time?

Using global var is still the easiest way to perform this requirement...

Global var can be updated whenever condiions are met at some point... Later on, To open trade or not, he probably wants to identify the speed of Price action...
Mitglied seit Sep 20, 2014   365 Posts
Aug 27, 2015 at 06:16 (bearbeitet Aug 27, 2015 at 06:41)
Still don't see why you'd need a global variable.

Do the array of pairs, then do the arrays of data. The data is already stored, no need to send it to a global variable. Just call it with functions. iClose or iOpen or any of those will call historic data points.

Only time I've ever had to use a global variable is if more than one EA is referencing data or I'm running more than 1 EA on an account.

Obviously coding is like painting. It's a very individual thing and all methods are correct. Some might be prettier than others, but at the end of the day its still a painting.

All my work runs on arrays as outlined above. So easy to dump or add pairs. Can have 1000 lines of code I simply add the pair to the array and even better, on my API I simply added an array of account numbers. So if I trade 1 account or 1000, 1 pair or 100, makes almost no difference.
Mitglied seit May 02, 2012   14 Posts
Aug 28, 2015 at 12:12
Wow amazing, after reading all of the above replies and coding samples I'm getting the idea of how to do it.

Thanks Ivan & theHand for the draft samples of coding and not forgetting CrazyTrader & Crazy Coder too.

Have a nice day guys.

Warmest regards.
Mitglied seit May 02, 2012   14 Posts
Sep 23, 2015 at 09:55
Hi guys,

I need to bug you all again for another help, hope you guys don't mind 😁,

My intention is to get the bpat or spat >=2 but somehow, it's still executing trade even with 1. I noticed that the previous programmer is not utilizing the 'lastbardpt', is this the reason?

                      if(UsePatternCheck)
                      {
                         bpatternM5=false;
                         spatternM5=false;
                         find=0;
                         bpat=0;
                         spat=0;
                         lastbardpt=0;
                         for(d=1;d<=100;d++)
                         {
                            if(CheckLongM5(pair,5,d))
                            {
                               bpat++;
                               find++;
                            }
                            if(CheckShortM5(pair,5,d))
                            {
                               spat++;
                               find++;
                            }
                            if(find==2) break;
                         }
                         if(bpat>=2) bpatternM5=true;
                         if(spat>=2) spatternM5=true;
                      }

Thanking you in advance for your time and kind assistance.

Warmest regards.
Mitglied seit Sep 20, 2014   365 Posts
Sep 23, 2015 at 10:54
I think you're missing 'else'...

if(CheckLongM5(pair,5,d))
  {
       bpat++;
        find++;
  } else {
      if(CheckShortM5(pair,5,d))
     {
         spat++;
         find++;
  }

The way you have it both conditions can be true at the same time. With the else you can have only one condition true at a time.

Print your values everywhere. See what they return after each action.





Anmelden / Registrieren to comment
You must be connected to Myfxbook in order to leave a comment
*Kommerzielle Nutzung und Spam werden nicht toleriert und können zur Kündigung des Kontos führen.
Tipp: Wenn Sie ein Bild/eine Youtube-Url posten, wird diese automatisch in Ihren Beitrag eingebettet!
Tipp: Tippen Sie das @-Zeichen ein, um einen an dieser Diskussion teilnehmenden Benutzernamen automatisch zu vervollständigen.