Coding Help Needed Buy when all Blue exit and sell when all Red.

 

I have been trying to make this code work but due to very limited experience can't see where I am going wrong ( Can't see the wood for the trees) type of thing I have been trying various things but very little change. Could someone please point me in the right direction.

double TML=iCustom(NULL,0,"TrendManager",TM_Period,TM_Shift,0,shift);
double TMS=iCustom(NULL,0,"TrendManager",TM_Period, TM_Shift, 1, shift);
double hasOpen = iCustom(NULL,0,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod, MaPeriod2,1,shift) ;
double hasClose = iCustom(NULL,0,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod, MaPeriod2,0,shift) ;
double SDLL=iCustom(NULL,0,"Slope Direction Line", period, method, price, 1,shift);
double SDLS=iCustom(NULL,0,"Slope Direction Line", period, method, price, 2,shift);

buysig=false;
sellsig=false;
closebuy=false;
closesell=false;


bool Long = TML && SDLL && hasOpen < hasClose;
bool Short = TMS && SDLS && hasOpen > hasClose;

buysig = Long;
sellsig = Short;

closebuy=sellsig;
closesell=buysig;

 

Do I need to create 4 variables for the Heiken_Ashi_Smoothed 2 for up and 2 for down as in below or am i off track

double hasOpenLong=iCustom(NULL,0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaPeriod2,1,shift) ;
double hasCloseLong=iCustom(NULL,0,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod, MaPeriod2,3,shift) ;
double hasOpenShort=iCustom(NULL,0,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod, MaPeriod2,0,shift) ;
double hasCloseShort=iCustom(NULL,0,"Heiken_Ashi_Smoothed", MaMetod, MaPeriod,MaPeriod2,2,shift) ;

Files: