QuestionXU-MA Indicator Buffers (Automating Xard System)

1
Hello fine traders and coders of Forex Station!

I am attempting to create an expert advisor to automate the backtesting and optimization of the XU-MA indicator.
I already have an EA set up with the correct logic for testing indicators the way I like to test them.

The problem comes when I try to use the data returned from the XU-MA buffers. For some strange reason, the trend buffer (#20) only returns 1 (buy) and 0 (wait) but never returns -1 (sell). When the indicator is in either "buy" or "wait" mode, 1 is returned (the correct value for buy, but not for wait). When the indicator flips to the "sell" mode, 0 is returned (which should be wait). -1 is never returned.
I have been working at this for around 6 hours in total and my noob coder brain still can't figure out the problem :D . In the mq4 indicator file it looks like the buffer is correctly being set! I would be in debt to anyone who can help me figure this out!

mq4 file for XU-MA:
app.php/attach/file/3373389

Here is my code for anyone interested:

Code: Select all

const string path = "./All MT4/";
const string name = "XU-20200808/Indicators/XU-MA";
/////////////////////////////////////////////////////
//////////   Indicator methods   //////////////////
/////////////////////////////////////////////////

bool buyEntryCondition(double trend)
{
   if(trend == 1) return true;
   return false;
}
bool sellEntryCondition(double trend)
{
   if(trend == -1) return true;
   return false;
}
bool waitCondition(double trend)
{
   if(trend == 0) return true;
   return false;
}
bool wasPreviouslyWait(double wait)
{
   if(wait == 0) return true;
   return false;
}

/////////////////////////////////////////////////////
//////////////   MAIN   ///////////////////////////
/////////////////////////////////////////////////

void OnTick()
{
   if(isNewCandle())
   {
      //Static vars
      double atr = iATR(Symbol(),0,14,1);
      
      /*
      SET INDICATOR VARS
      */
      double trend = iCustom(Symbol(),0,StringConcatenate(path,name),Indicator,STR01,showCANDLES,cWick,CandleUp,CandleWt,CandleDn,STR02,showT1MA,T1MAper,T1MAmode,T1MAwidth,T1MABGDwidth,STR03,showS1MA,S1MAper,S1MAmode,S1MAwidth,S1MABGDwidth,S1MAclrUP,S1MAclrDN,S1MAclrBGD,STR04,
showBGDzones,CCIPrice,ColorUp,ColorDown,ColorWait,STR05,showBOXtxt,moveTxtLR,moveTxtUD,FontSize,STR06,AlertsOn,AlertsOnCurrent,AlertsMessage,AlertsSound,alertsNotify,AlertsEmail,soundfile,20,1);
double wait = iCustom(Symbol(),0,StringConcatenate(path,name),Indicator,STR01,showCANDLES,cWick,CandleUp,CandleWt,CandleDn,STR02,showT1MA,T1MAper,T1MAmode,T1MAwidth,T1MABGDwidth,STR03,showS1MA,S1MAper,S1MAmode,S1MAwidth,S1MABGDwidth,S1MAclrUP,S1MAclrDN,S1MAclrBGD,STR04,
showBGDzones,CCIPrice,ColorUp,ColorDown,ColorWait,STR05,showBOXtxt,moveTxtLR,moveTxtUD,FontSize,STR06,AlertsOn,AlertsOnCurrent,AlertsMessage,AlertsSound,alertsNotify,AlertsEmail,soundfile,20,2);
      Print("DIRECTION = " + trend);
      if(inBuyTrade())
      {
         if(sellEntryCondition(trend) || waitCondition(trend)) //If flips
         {
            exitBuys();
         }
         if(isTPHit())
         {
            setBreakEven();
            if(trailingStopInitiatedBuy(atr))
            {
               setTrailingStop(atr);
            }
         }
      }
      if(inSellTrade())
      {
         if(buyEntryCondition(trend) || waitCondition(trend))
         {
            exitSells();
         }
         if(isTPHit())
         {
            setBreakEven();
            if(trailingStopInitiatedSell(atr))
            {
               setTrailingStop(atr);
            }
         }
      }
      
      if(!inBuyTrade() && !inSellTrade())
      {
         if(lastInSell() || wasPreviouslyWait(wait))
         {
            if(buyEntryCondition(trend)) //Pass info needed as params
            {
               placeBuy(atr);
            }
         }
         if(lastInBuy() || wasPreviouslyWait(wait))
         {
            if(sellEntryCondition(trend)) //Pass info needed as params
            {
               placeSell(atr);
            }
         }
      }
   }
}




Who is online

Users browsing this forum: DotNetDotCom [Bot] and 24 guests