stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

My shell EA code
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=79
Page 13 of 23
Author:  6y588 [ Sat Sep 28, 2013 5:02 am ]
Post subject:  Re: My shell EA code

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 );
}
Author:  6y588 [ Thu Oct 03, 2013 2:05 am ]
Post subject:  Re: My shell EA code

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.
Author:  SteveHopwood [ Mon Oct 28, 2013 4:00 pm ]
Post subject:  Re: My shell EA code

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
Author:  droland [ Fri Dec 13, 2013 6:29 pm ]
Post subject:  Re: My shell EA code

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:
Author:  SteveHopwood [ Fri Dec 13, 2013 6:51 pm ]
Post subject:  Re: My shell EA code

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
Author:  K-Lander [ Wed Feb 12, 2014 6:16 pm ]
Post subject:  Re: My shell EA code

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
Author:  milanese [ Wed Feb 12, 2014 6:19 pm ]
Post subject:  Re: My shell EA code

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
Author:  SteveHopwood [ Wed Feb 12, 2014 10:59 pm ]
Post subject:  Re: My shell EA code

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:
Author:  SpiderX [ Thu Feb 13, 2014 12:25 am ]
Post subject:  Re: My shell EA code

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
Author:  K-Lander [ Thu Feb 13, 2014 1:11 pm ]
Post subject:  Re: My shell EA code

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

Cheers,

K
All times are UTC Page 13 of 23