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

Crude trend ID code and the order counter...
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4439
Page 1 of 1
Author:  Jexodus [ Mon Oct 05, 2015 12:40 pm ]
Post subject:  Crude trend ID code and the order counter...

Ok, I've searched around for how to effectively code to identify trend and haven't found anything that i went "Yes! I understand that!". I even looked through the code for trend based systems (like Pipmasher) to try and extract how it was done.

Not finding my answer, i resorted to MSU (Making Sh!t Up) and coded a really crude version of trend ID. Funnily enough, it seems to be working pretty well (although no perfect).

Basically, I took a 240MA (user adjustable), took three samples of it and compared the values. Code looks like this (please hold the laughter...):

Code: Select all

string trendMA(int shift)
{
   double oldMA, olderMA, newMA;
   string MATrend = "No trend";
   
   newMA = iMA(NULL, TradingTimeFrame, MAPeriod, shift, MODE_LWMA, PRICE_OPEN, shift);
   oldMA = iMA(NULL, TradingTimeFrame, MAPeriod, shift, MODE_LWMA, PRICE_OPEN, 10);
   olderMA = iMA(NULL, TradingTimeFrame, MAPeriod, shift, MODE_LWMA, PRICE_OPEN, 24);
   
   if(newMA < oldMA)
   {
   if (oldMA < olderMA) MATrend = "Down";
   }
   
   if(newMA > oldMA)
   {
   if (oldMA > olderMA) MATrend = "Up";
   }
   
   return(MATrend);
  }
Because this is so primative, is there a more effective way to do this?

The other issue I have is that I've put in a max order limit for my EA which simply gets OrdersTotal() which is assigned to a variable, and compares it to a user input. This is one of two (one for long, one for short):

Code: Select all

         if (currentOrders >= maxTrades)
         {
         Alert("sell signal received, max trades in place... trade skipped!");
         SendShort = false;
         }  
When testing this running multiple instances of the EA and max trades set to one, I had two trades fire. I am assuming that it would be because both EAs are firing a the same time and submit orders concurrently, therefore when the check of total orders open was done, both saw zero. Is best practice to delay EAs to fire in turn or is there an easier way to achieve this.

Thanks in advance to the coding gurus for any help provided.
All times are UTC Page 1 of 1