EA custom indicator problem beginner

 

My custom indicator looks similar to this it has 3 bands, and i am trying to code EA to set long position if bar close price crosses middle band up or is above middle band, but below upper band

I tried different logic in my if statement with no luck. closest results i got is with current code where i get signal if price close is above middle line, but i also get signal if price close is above upper line, which is not good.Can you please help me?

Custom indicator

// the input variables of the EA
input ENUM_TIMEFRAMES    TimeFrame       = PERIOD_CURRENT;
input int                AMAPeriod       = 10;
input ENUM_APPLIED_PRICE AMAPrice        = PRICE_CLOSE;
input int                Nfast           = 2;
input int                Nslow           = 30;
input double             GCoeff          = 2;
input int                PriceFilter     = 5;
input maTypes            PriceFilterMode = ma_smoo;
input bool               Interpolate     = true;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   double band_middle = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter, PriceFilterMode,Interpolate, 0,0 );
   double band_1 = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode,Interpolate, 1,0 );
   double band_2 = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode,Interpolate, 2,0 );
   double band_3 = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 3,0 );
   double band_up = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 4,0 );
   double band_down = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 5,0 );
   
   
   //strategy
   double band_middle_curr = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter, PriceFilterMode,Interpolate, 0,0 );
   double band_middle_prev = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter, PriceFilterMode,Interpolate, 0,1 );
   double band_up_prev = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 4,1 );
   double band_up_curr = iCustom(_Symbol,_Period,"kaufman_ama_averages_filtered_ATR bands",TimeFrame, AMAPeriod, AMAPrice,Nfast, Nslow, GCoeff, PriceFilter,PriceFilterMode, Interpolate, 4,0 );
   Comment(band_up_prev);
   
   
   if(Close[0] <  band_middle_curr && Close[0] < band_up_curr)
      {
      
         Print("open a buy order");
      
      }
   
  }
//+------------------------------------------------------------------+
 
Please attach your file using the button Attach file
 
Vladimir Karputov:
Please attach your file using the button
Sorry i am new here... i just did, hope it's fine now...
 
Josip Marić:

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

Ok, thank you!
 
Josip Marić:

My custom indicator looks similar to this it has 3 bands, and i am trying to code EA to set long position if bar close price crosses middle band up or is above middle band, but below upper band

I tried different logic in my if statement with no luck. closest results i got is with current code where i get signal if price close is above middle line, but i also get signal if price close is above upper line, which is not good.Can you please help me?


if(Close[0] >  band_middle_curr && Close[0] < band_up_curr)

Try something like that,

Use close[1] instead of close[0]

 
ffoorr:

Try something like that,

Use close[1] instead of close[0]

Hi, i have tried, but no... it triggers long signal when the bar close is above upper line, and it sould trigger only if the bar close is below the upper line
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Indicators Lines - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Josip Marić:

I have deleted your new topic which is about the same EA but with additions.

Get this issue correct before expanding the code.

 
Josip Marić:
Hi, i have tried, but no... it triggers long signal when the bar close is above upper line, and it sould trigger only if the bar close is below the upper line

Show your modified code.

 
Keith Watford:

Show your modified code.

this is my modified EA with aditional indicators
 
Anyone?
Reason: