My shell EA code

Post Reply
6y588

Re: My shell EA code

Post by 6y588 »

Take it for what it is worth, as I don't want to hijack this thread, bringing your attention to FIVE (5) minor bugs/enhancements that I made to the shell code that you may want to incorporate (it is up to you):

i) Broker time fixed to TimeCurrent()

Code: Select all

SM("Broker time = " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + ": Local time = " + TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS) + NL );
ii) Use NormalizeDouble() function to work with different digit brokers

Code: Select all

OrderSend(symbol, type, lotsize, NormalizeDouble(price,Digits), slippage, 0, 0, comment, MagicNumber, expiry, col);
iii) Replaced LibCss module at the end of source with v.1.1.3 from v1.1.0 (just cut and paste from LibCss.mq4)
- No changes made to the shell code as it seemed to work correctly with v1.1.3.

iv) Added a function GetNewCSS() that uses pass by reference to get CSS values and also tick volume

Code: Select all

void GetNewCSS(double& css1, double& css2, double& sum, double& vol, double index1, double index2, int shift)
{
   // Initialize
   double myCSS[];
   double myVol[];
   // Call library
   libCSS.getNewCSS( myCSS, myVol, CssTf, VolTf, shift, true );
      
   int currencyIndex1 = NormalizeDouble( index1, 0 );
   int currencyIndex2 = NormalizeDouble( index2, 0 );
   
   css1 = myCSS[currencyIndex1];
   css2 = myCSS[currencyIndex2];
   
   sum = 0;
   for(int i=0; i<ArraySize(CurrNames); i++)
      sum = sum + MathAbs(myCSS[i]);
   
   vol = 0;
   for(i=0; i<ArraySize(CurrNames); i++)
      vol = vol + myVol[i];
}
v) Baluda's LibCss.getCSS() function does not return tick volume, so I added a function LibCss.getNewCss()

Code: Select all

void libCSS.getNewCSS( double& css[], double& vol[], int tf, int volTf, int shift, bool flushCache = false )
{
   static double volume;
   if ( flushCache || volume != iVolume(libCSS.cacheSymbol, libCSS.cacheTimeframe, 0) )
   {
      int i;
      
      ArrayInitialize(libCSS.currencyValues, 0.0);

      ArrayResize( vol, libCSS.CURRENCYCOUNT );
      // Get Slope for all symbols and totalize for all currencies   
      for ( i = 0; i < libCSS.symbolCount; i++ )
      {
         double slope = libCSS.getSlope(libCSS.symbolNames[i], tf, shift);
         libCSS.currencyValues[libCSS.getCurrencyIndex(StringSubstr(libCSS.symbolNames[i], 0, 3))] += slope;
         libCSS.currencyValues[libCSS.getCurrencyIndex(StringSubstr(libCSS.symbolNames[i], 3, 3))] -= slope;
         
         vol[i] = iVolume( libCSS.symbolNames[i], volTf, shift + 1);
      }
      ArrayResize( css, libCSS.CURRENCYCOUNT );
      for ( i = 0; i < libCSS.CURRENCYCOUNT; i++ )
      {
         // average
         if ( libCSS.currencyOccurrences[i] > 0 ) libCSS.currencyValues[i] /= libCSS.currencyOccurrences[i]; else libCSS.currencyValues[i] = 0;
      }
   }
   for ( i = 0; i < libCSS.CURRENCYCOUNT; i++ )
   {
      css[i] = libCSS.currencyValues[i];
   }
   volume = iVolume( libCSS.cacheSymbol, libCSS.cacheTimeframe, 0 );
}
6y588

Re: My shell EA code

Post by 6y588 »

Found this code on MQL4.com that generates a random magic number based on symbol and tf.

Code: Select all

int SymbolTfConst2Val(string sym, int tf)
{
   int MNSymbol,MNSymbolCalc;
   for(int a=0;a<6;a++)//turn the Symbol() into an ASCII string and add each character into MNSymbol
   {
      MNSymbolCalc=StringGetChar(sym, a);
      MNSymbolCalc=((MNSymbolCalc-64)*(MathPow(10,(a))));//subtract 64 b/c ASCII characters start at 65, multiply result by the a-th power for neatness (unnecessary though)
      MNSymbol = MNSymbol+MNSymbolCalc;
   }
   return( MNSymbol+tf );
}
In the init() function, place the following line:

Code: Select all

   if(MagicNumber<=0)
      MagicNumber = MagicSeed + SymbolTfConst2Val(Symbol(),Period());
MagicSeed is a unique number for the EA, i.e. EA1 and EA2 should have different Magic Seed.

User can manually overwrite a random MagicNumber by setting it to > 0.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: My shell EA code

Post by SteveHopwood »

Latest version of my shell is in post 1.

I add the fix to my shell every time a bug emerges in a bot that I coded from the shell, so the code gradually becomes more and more robust.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
droland
Trader
Posts: 52
Joined: Tue Nov 15, 2011 9:40 pm
Location: Vancouver, BC, Canada

Re: My shell EA code

Post by droland »

Steve. I have been working on an EA using your Shell from abut 5 months ago. I just did a compare doc using MS word comparing your older shell to this new shell and see a large number of changes and additions. The original shell code seems to be working for me but obviously you made these changes for a reason so I assume you would recommend I strip out my code in your older version and add it to this version.

dr

Actually, I think I will do that anyway, just for the practice. It took a while to learn the flow of your code logic stepping through the subroutines. :shock:
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: My shell EA code

Post by SteveHopwood »

droland wrote:Steve. I have been working on an EA using your Shell from abut 5 months ago. I just did a compare doc using MS word comparing your older shell to this new shell and see a large number of changes and additions. The original shell code seems to be working for me but obviously you made these changes for a reason so I assume you would recommend I strip out my code in your older version and add it to this version.

dr

Actually, I think I will do that anyway, just for the practice. It took a while to learn the flow of your code logic stepping through the subroutines. :shock:
Learning to code by stepping through someone else's code is a monumental achievement, Dave. :clap: You always come across as pretty bright in your posts, but this is amazing. You must have a brain the size of Mars. It probably felt a bit scrambled at times, so welcome to my world. :xm:

Yes, I do recommend making the changes. Refining my shell code has been a process of:
  • using it to create an EA.
  • fixing the bugs in the shell that then manifested in the EA.
  • transferring the fixes back to the shell.
So the shell is now much more robust than it was a few months ago.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
K-Lander
Trader
Posts: 35
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

Re: My shell EA code

Post by K-Lander »

Hello Steve and all,
Just a quick question to any of you... Does the Shell works fine with the new changes made on the new Empty4 build?

Thanks a bunch,

K-Lander
User avatar
milanese
TechAdmin
Posts: 3293
Joined: Wed Jan 09, 2013 9:02 am
Location: btr rdx, r8 +

Re: My shell EA code

Post by milanese »

K-Lander » Wed Feb 12, 2014 6:16 pm wrote:Hello Steve and all,
Just a quick question to any of you... Does the Shell works fine with the new changes made on the new Empty4 build?

Thanks a bunch,

K-Lander
there are some minor fixes needed, you can look here http://www.stevehopwoodforex.com/phpBB3 ... 103#p86103
and here http://www.stevehopwoodforex.com/phpBB3 ... 214#p86214

Cheers :)

Tommaso
Global Prime is the official SHF broker :yahoo:
Searching for Servers and Workstations with individual configuration?
Just PM
:smile: Click here to go to the BoardKnowledgeBase
NOTE: Cookies and JavaScript are required for the using the board, with full functionality
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: My shell EA code

Post by SteveHopwood »

K-Lander » Wed Feb 12, 2014 6:16 pm wrote:Hello Steve and all,
Just a quick question to any of you... Does the Shell works fine with the new changes made on the new Empty4 build?

Thanks a bunch,

K-Lander
I have been unable to play my full part here lately for personal reasons. There may be a few issues to sort out. I believe there are a few xxx.xxx variable that need replacing because CrapWhateverTheBloodyThingIs is supposed to be OOP. I hope to start looking at all this soon.

:xm:
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
SpiderX
Trader
Posts: 554
Joined: Thu Aug 22, 2013 4:50 pm

Re: My shell EA code

Post by SpiderX »

Hi Steve

Have to honest that modifying the ea for build 600 was not as painful as I thought it would be.
Most changes , errors , warnings are fairly easy to correct as mentioned in the other discussion.
Some of the changes I am not too certain as you are the owner of the code.
However if the code is converted correctly for v600 it should not run in 509 any further.

Cheers
"Love is patient, love is kind. It does not envy, it does not boast, it is not proud. It does not dishonor others, it is not self-seeking, it is not easily angered, it keeps no record of wrongs.Love does not delight in evil but rejoices with the truth. It always protects, always trusts, always hopes, always perseveres."
-Corinthians 13:4-8
K-Lander
Trader
Posts: 35
Joined: Thu Nov 17, 2011 9:03 pm
Location: Buenos Aires, Argentina

Re: My shell EA code

Post by K-Lander »

Thank you all people... I´ll post here any issues I may stumble upon.

Cheers,

K
Post Reply

Return to “Coders Hangout”