# Holding İndicator results until the value will reach a specific level

14

Hello,

I wonder that how can I do explained below.
For example, if RSI > 50, MACD cross upward if its value below 0 and lastly CCI just cross over -100 for buy signal. Also, for second trade, all of them should turn to their default levels as the initial period of the first order(RSI should go below 50 and then again take buy signal if it cross 50 upwards, CCI should go below -100 and waiting a new cross)

Actually I wrote the conditions but, I couldn't code the condition they should turn to their default positions for buy signal.

Cheers,
Baris

5394

BarisYalcinkaya: I wonder that how can I do explained below.For example, if RSI > 50, MACD cross upward if its value below 0 and lastly CCI just cross over -100 for buy signal. Also, for second trade, all of them should turn to their default levels as the initial period of the first order(RSI should go below 50 and then again take buy signal if it cross 50 upwards, CCI should go below -100 and waiting a new cross) Actually I wrote the conditions but, I couldn't code the condition they should turn to their default positions for buy signal.

14

```#property copyright "Copyright 2014, BarisYalcinkaya."
#property version   "1.00"
#property strict

extern double StopLoss_Pips = 9;
//extern double TakeProfit_Pips = 36;
extern double RiskPercent = 3;
extern double Reward_Ratio = 1.5;

extern int RSI_Period_W = 14;

extern int SMA_Period_D = 200;
extern int MACD_Fast_D  = 26;
extern int MACD_Slow_D  = 12;
extern int MACD_Shift_D = 9;
extern int CCI_Period_D = 14;
extern int RSI_Period_D = 14;

extern int MACD_Fast_H4  = 26;
extern int MACD_Slow_H4  = 12;
extern int MACD_Shift_H4 = 9;
extern int CCI_Period_H4 = 14;
extern int RSI_Period_H4 = 14;

double pips;

int init()
{
//----
double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
if(ticksize == 0.00001 || ticksize == 0.001)
pips = ticksize*10;
else pips = ticksize;
//----
return(0);
}

int start()
{
double RSI_W;

double SMA_D;

double DIplus_D,DIminus_D;
double CCI_Current_D, CCI_Previous_D;
double RSI_D;
double MACD_CurMain_D, MACD_CurSignal_D, MACD_PrevMain_D, MACD_PrevSignal_D;

double MACD_CurMain_H4, MACD_CurSignal_H4, MACD_PrevMain_H4, MACD_PrevSignal_H4;
double DIplus_H4,DIminus_H4;
double CCI_Current_H4, CCI_Previous_H4;
double RSI_H4;

bool SellRule_W_RSI;
bool SellRule_D_SMA, SellRule_D_MACD, SellRule_D_RSI, SellRule_D_DI, SellRule_D_CCI;
bool SellRule_H4_MACD, SellRule_H4_RSI, SellRule_H4_DI, SellRule_H4_CCI;

// For loop
int cnt, ticket, total;
int MagicNumber=1234;

if(Bars<100)
{
Print("Bars less than 100");
return(0);
}
//------------------------------------------------------
//------RSI Weekly
RSI_W=iRSI(NULL,PERIOD_W1,RSI_Period_W,PRICE_CLOSE,0);

//------SMA Daily
SMA_D=iMA(NULL,PERIOD_D1,SMA_Period_D,0,MODE_SMA,PRICE_CLOSE,0);
//MACD Daily
MACD_CurMain_D=iMACD(NULL,PERIOD_D1,MACD_Fast_D,MACD_Slow_D,MACD_Shift_D,PRICE_CLOSE,MODE_MAIN,0);
MACD_CurSignal_D=iMACD(NULL,PERIOD_D1,MACD_Fast_D,MACD_Slow_D,MACD_Shift_D,PRICE_CLOSE,MODE_SIGNAL,0);
MACD_PrevMain_D=iMACD(NULL,PERIOD_D1,MACD_Fast_D,MACD_Slow_D,MACD_Shift_D,PRICE_CLOSE,MODE_MAIN,1);
MACD_PrevSignal_D=iMACD(NULL,PERIOD_D1,MACD_Fast_D,MACD_Slow_D,MACD_Shift_D,PRICE_CLOSE,MODE_SIGNAL,1);
//DI+ and DI- Daily
//CCI Daily
CCI_Current_D=iCCI(NULL,PERIOD_D1,CCI_Period_D,PRICE_CLOSE,0);
CCI_Previous_D=iCCI(NULL,PERIOD_D1,CCI_Period_D,PRICE_CLOSE,1);
//RSI Daily
RSI_D=iRSI(NULL,PERIOD_D1,RSI_Period_D,PRICE_CLOSE,0);

//-------MACD H4
MACD_CurMain_H4=iMACD(NULL,PERIOD_H4,MACD_Fast_H4,MACD_Slow_H4,MACD_Shift_H4,PRICE_CLOSE,MODE_MAIN,0);
MACD_CurSignal_H4=iMACD(NULL,PERIOD_H4,MACD_Fast_H4,MACD_Slow_H4,MACD_Shift_H4,PRICE_CLOSE,MODE_SIGNAL,0);
MACD_PrevMain_H4=iMACD(NULL,PERIOD_H4,MACD_Fast_H4,MACD_Slow_H4,MACD_Shift_H4,PRICE_CLOSE,MODE_MAIN,1);
MACD_PrevSignal_H4=iMACD(NULL,PERIOD_H4,MACD_Fast_H4,MACD_Slow_H4,MACD_Shift_H4,PRICE_CLOSE,MODE_SIGNAL,1);
//CCI H4
CCI_Current_H4=iCCI(NULL,PERIOD_H4,CCI_Period_H4,PRICE_CLOSE,0);
CCI_Previous_H4=iCCI(NULL,PERIOD_H4,CCI_Period_H4,PRICE_CLOSE,1);
//RSI H4
RSI_H4=iRSI(NULL,PERIOD_H4,RSI_Period_H4,PRICE_CLOSE,0);
//DI+ and DI- H4

//ORDER OPENING-------------------

//Rules Weekly Options

//Rules Daily Options

//Rules H4 Options

//SELL RULES---------------
//Rules Weekly Options
SellRule_W_RSI = (RSI_W<50);
//Rules Daily Options
SellRule_D_SMA = (SMA_D<200);

SellRule_D_MACD = ((MACD_CurMain_D<MACD_CurSignal_D) && (MACD_PrevMain_D>MACD_PrevSignal_D));
SellRule_D_RSI  = (RSI_D<50);
SellRule_D_DI   = (DIplus_D<DIminus_D);
SellRule_D_CCI  = ((CCI_Previous_D>CCI_Current_D)&&(CCI_Current_D>100));

//Rules H4 Options
SellRule_H4_MACD = ((MACD_CurMain_H4<MACD_CurSignal_H4) && (MACD_PrevMain_H4>MACD_PrevSignal_H4));
SellRule_H4_RSI  = (RSI_H4<50);
SellRule_H4_DI   = (DIplus_H4<DIminus_H4);
SellRule_H4_CCI  = ((CCI_Previous_H4>CCI_Current_H4)&&(CCI_Current_H4>100));

//---------------------------------------------------------------

//Order Opening --------

total=OrdersTotal();
if(total<1)
{
if(IsNewCandle())
{
{
{
{*/
{

if(ticket>0)
{
}
else Comment("Error opening BUY order : ",GetLastError());
return(0);

//Checking Sell Posibility

if(SellRule_W_RSI)
{
if(SellRule_D_SMA)
{
if((SellRule_D_MACD && SellRule_D_RSI)||(SellRule_D_MACD && SellRule_D_DI)||(SellRule_D_MACD && SellRule_D_CCI)||
(SellRule_D_RSI  && SellRule_D_DI) ||(SellRule_D_RSI && SellRule_D_CCI)||
(SellRule_D_DI   && SellRule_D_CCI))
{
if((SellRule_H4_MACD && SellRule_H4_RSI)||(SellRule_H4_MACD && SellRule_H4_DI)||(SellRule_H4_MACD && SellRule_H4_CCI)||
(SellRule_H4_RSI  && SellRule_H4_DI) ||(SellRule_H4_RSI && SellRule_H4_CCI)||
(SellRule_H4_DI   && SellRule_H4_CCI))
{
double LotSize_Sell = 0;
double Equity_Sell = AccountEquity();
double RiskedAmount_Sell = Equity_Sell*RiskPercent*0.01;

double SL_Sell = High[1] + StopLoss_Pips*pips;
double SL_Sell_Loss = SL_Sell - Ask;
double TP_Sell = Ask - (SL_Sell_Loss*Reward_Ratio);

LotSize_Sell = (RiskedAmount_Sell/(SL_Sell_Loss/pips))/10;

}    // H4_Indicators Sell
}        // D_Indicators Sell
}            // D_SMA Sell
}               // W_RSI Sell

}                  // IsNewCandle

}                      // total

return(0);
}  // Start()

bool IsNewCandle()
{
static int  BarsOnChart = 0;
if(Bars == BarsOnChart)
return(false);
BarsOnChart = Bars;
return(true);
} ```
14

It' looking 3 different timeframes.

First rule is: Weekly=RSI > 50,
Second rule is: if (
Daily Price > MVA 200) check the other conditions.
If any of the following 2 triggers happened(Daily):

a)Daily=RSI > 50
b)Daily=MACD ShortEMA Cross over Long EMA (below the 0 level)

c)Daily=DMI DI+>DI-

d)Daily=CCI JustCrossOver -100

Then,

If any of the following 2 triggers happened(4Hour):

a)4Hour=RSI > 50

b)4Hour=MACD ShortEMA Cross over Long EMA (below the 0 level)

c)4Hour=DMI DI+>DI-

d)4Hour=CCI > -100

I defined all of them however I can't create a condition for the second trade which should be opened. For example, if RSI firstly go down to 50 and then waiting a upward cross, MACD should go below 0 and then waiting another signal which is based on crossing main line and its signal line, and lastly DI+ should go back below the DI- and then cross it upwards second time.

I add a picture which maybe explain it better.

Baris

3243

Trading functions of OrderSend(), OrderClose(), OrderCloseBy(), OrderDelete(), and OrderModify() cannot be called from custom indicators

```bool StatusRsi, RsiCrossed, StatusMACD, CrossingMainTheSignal, DIPlusBelowDIMinus, DIPlusAboveDIMinus, ConditionToOpenTrade;

if (RSI < 50)
StatusRsi = true;

if (StatusRsi && RSI > 50)
RsiCrossed = true;

if (MACD < 0)
StatusMACD = true;

if (StatusMACD && MACD > 0)
CrossingMainTheSignal == true;

if (DI+ < DI-)
DIPlusBelowDIMinus == true;

if (DIPlusBelowDIMinus && DI+ > DI-)
DIPlusAboveDIMinus == true

if (RsiCrossed && CrossingMainTheSignal && DIPlusAboveDIMinus)