Problem In Ichimiko on long trade with Chikou filter.

 

I can not enter a long trade when using the chikou filter however short trades work fine.

Can someone review my code and let me know if they can spot the bug?

Appreciated

#property link      "https://www.NEW.com"
#property version   "1.00"
#property strict
#include <stderror.mqh>
#include <stdlib.mqh>
//---
enum TrailType {Regular,CandleTrail};
// Input variables
enum RiskBased {Balance,Equity };
input bool UseMoneyManagement=true;
input double RiskPercent=1.00;
input RiskBased Risk_Based=Balance;

//--- input parameters
extern double StopLoss=50;
extern double TakeProfit=50;
input double   LotSize=0.01;
extern int MaxAmountOfTrades=4;
extern bool HedgingAllowed=true;
extern bool CloseOnOppositeSignal=false;

extern string rm1;//Risk Management Settings.
//Breakeven Settings
extern bool UseMoveToBE=false;//Using Move to Breakeven.
extern int WhenToMoveToBE=55;//How many pips before you move?
extern int PipsToLockIn=25;//How many pips do you want to lock in?

//Trailing Stop settings
extern bool UseTrailingStop=false;
extern TrailType Trailing_Type=Regular;

extern string t1;//Regular Trail Settings.
extern int  WhenToTrail=80;
extern int  TrailAmount=60;

extern string t2;//Candle Stop Settings
extern int  CandlesBack=6;//How many candles back to Look
extern int  PadAmount=34;//How much beyond candle to put stop.
//---
extern int Slippage=30;
extern int MagicSeed=2929;

double pips;
int magic=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   magic=MagicNumberGenerator();
   Print("MagicNumber is ",magic);
   HideTestIndicators(false);
// Determine what a pip is.
   pips=Point; //.00001 or .0001. .001 .01.
   if(Digits==3 || Digits==5)
      pips*=10;
   Comment("Expert Loaded Successfully");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment(" ");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(UseTrailingStop)
      AdjustTrail();
   if(UseMoveToBE)
      MovetoBreakeven();
   CheckForSignal();
  }
//+------------------------------------------------------------------+
//|       TRIGGER FUNCTION                                           |
//+------------------------------------------------------------------+
void CheckForSignal()
  {
   static datetime candletime=0;
   if(candletime!=Time[0])
     {

      double Tenkan=iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,1);
      double TenkanBack=iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,2);
      double Kijun=iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,1);
      double KijunBack=iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,2);
      double Senkou_a=iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,1);
      double Senkou_b=iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,1);
      double Chikou=iIchimoku(NULL,0,9,26,52,MODE_CHIKOUSPAN,1);

      double Price=(High[1]+Low[1])/2;
      double PriceBack=(High[2]+Low[2])/2;
      double PriceHigh=(High[1]);
      double PriceHighBack=(High[2]);
      double PriceHighBack2=(High[3]);
      double PriceLow=(Low[1]);
      double PriceLowBack=(Low[2]);
      double PriceLowBack2=(Low[3]);

      double PriceBack1=(High[3]+Low[3])/2;
      double PriceBack2=(High[4]+Low[4])/2;

      //---Best Code Up Arrow
      if(Tenkan>Kijun && Tenkan>Senkou_a && Chikou>Price)
         //if(PriceBack2>PriceBack1  && PriceBack1>PriceBack && Price>PriceBack)
            //if(TenkanBack<KijunBack && Tenkan>Kijun && Tenkan>Senkou_a && PriceHigh<Chikou)

           {
            if(CloseOnOppositeSignal)
               exitsells();
            if(TotalOpenOrders()<MaxAmountOfTrades)
               if((HedgingAllowed) || (!HedgingAllowed && OpenOrders(OP_SELL)==0))
                  EnterTrade(OP_BUY);
               else
                  Print("Hedging did not allow this trade.");
           }

      //---Best Code Down Arrow
      if(Tenkan<Kijun && Tenkan<Senkou_b && Chikou<Price)
         //if(PriceBack2<PriceBack1  && PriceBack1<PriceBack && Price<PriceBack)
            //if(TenkanBack>KijunBack && Tenkan<Kijun && Tenkan<Senkou_b && PriceLow<Chikou)

           {
            if(CloseOnOppositeSignal)
               exitbuys();
            if(TotalOpenOrders()<MaxAmountOfTrades)
               if((HedgingAllowed) || (!HedgingAllowed && OpenOrders(OP_BUY)==0))
                  EnterTrade(OP_SELL);
               else
                  Print("Hedging did not allow this trade.");
           }
      candletime=Time[0];
     }
  }


thanks !

 
I can send the full EA if needed ?
 
      double Chikou=iIchimoku(NULL,0,9,26,52,MODE_CHIKOUSPAN,1);

There is no Chikou at bar index 1, look at the chart.

I will move this topic to the MQL4 and MT4 section.

In future please put your posts in the correct section.