Entry is RSI(14) crossover of (EMA(RSI)50)), in other words the 50 EMA of RSI. Exit is close below 20 EMA.
Please help...
- Code: Select all
// Registered to: enter email address
#include <stdlib.mqh>
#define MAX_ECN7464 16
int ecn_count560 = 0;
int ecn_ticket6003[MAX_ECN7464];
double ecn_sl7797[MAX_ECN7464];
double ecn_tp2286[MAX_ECN7464];
extern double Lots=1.0;
extern int StopLoss=200;
extern int TakeProfit=200;
extern int Slippage=3;
extern int MagicNumber=99999;
extern int MaxTrades=1;
extern int MaxSells=1;
extern int MaxBuys=1;
extern bool ECN=False;
extern double MaxLots=1.0;
extern bool ShowTick=True;
datetime lastsignaltimebuy7871=0;
datetime lastsignaltimesell6162=0;
bool nextsignalstate9096=false;
string chartcomment6274;
int lasttradecount9714;
string eaname3418="RSIMAma";
int tick6879 = 0;
bool everopened9599= false;
// Function variables defintions
bool _CloseBuyTrade;
double _iMA3;
double _iClose1;
bool _fnCloseBuy1;
bool _OpenBuyTrade;
double _iRSI1;
double _iMA1;
int _fnOpenBuy1;
bool _OpenSellTrade;
double _iRSI2;
double _iMA2;
int _fnOpenSell1;
bool _CloseSellTrade;
double _iMA4;
double _iClose2;
bool _fnCloseSell1;
void fnComment9704()
{
Comment( chartcomment6274 );
}
void fnModifyEcn7794()
{
if( ECN == true )
{
if( ecn_count560 > 0 )
{
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS)==false) continue;
for( int k=0; k<ecn_count560; k++ )
{
if( OrderTicket() == ecn_ticket6003[k] )
{
if( (OrderStopLoss() == 0) || (OrderTakeProfit() == 0) )
{
if( OrderModify(ecn_ticket6003[k], OrderOpenPrice(), ecn_sl7797[k], ecn_tp2286[k], 0) == true )
{
ecn_ticket6003[k] = 0;
}
else
{
Print("ECN order modify failed: ", ErrorDescription(GetLastError()) );
}
}
else
{
ecn_ticket6003[k] = 0;
}
}
}
}
}
}
int count=0;
for( int j=0; j<ecn_count560; j++ )
{
if( ecn_ticket6003[j] != 0 )
count++;
}
if( count == 0 )
ecn_count560 = 0;
}
bool fnOkToOpen4663(int type)
{
int timeok4492=0;
bool signalok1133=false;
// check max values
int total2777 = 0;
int buys6753 = 0;
int sells6641 = 0;
double lots5556 = 0;
for(int i769=0;i769<OrdersTotal();i769++)
{
if(OrderSelect(i769,SELECT_BY_POS)==false) continue;
if( OrderMagicNumber() == MagicNumber )
{
total2777++;
if( OrderType() == OP_BUY ) buys6753++;
if( OrderType() == OP_SELL ) sells6641++;
lots5556+= OrderLots();
}
}
if( total2777 > 0 ) everopened9599 = true;
if( total2777 >= MaxTrades )
{
chartcomment6274 = StringConcatenate(chartcomment6274,"Trade Open Disabled: MaxTrades reached");
return(false);
}
if( lots5556 >= MaxLots )
{
chartcomment6274 = StringConcatenate(chartcomment6274,"Trade Open Disabled: MaxLots reached");
return(false);
}
if( (type == OP_BUY) && (buys6753 >= MaxBuys) )
{
chartcomment6274 = StringConcatenate(chartcomment6274,"Trade Open Disabled: MaxBuys reached");
return(false);
}
if( (type == OP_SELL) && (sells6641 >= MaxSells) )
{
chartcomment6274 = StringConcatenate(chartcomment6274,"Trade Open Disabled: MaxSells reached");
return(false);
}
return(true);
}
double fnFixLots(double lots)
{
double price=0;
if( lots < 0 )
{
return(lots);
}
double newlots = lots;
// fix newlots
double min, max, step, fixedlots;
int lotdigits = 1;
step = MarketInfo(Symbol(), MODE_LOTSTEP);
if( step == 0.01 )
lotdigits = 2;
if( step == 0.1 )
lotdigits = 1;
fixedlots = StrToDouble(DoubleToStr(newlots, lotdigits));
min = MarketInfo(Symbol(), MODE_MINLOT);
if( lots < min )
fixedlots = min;
max = MarketInfo(Symbol(), MODE_MAXLOT);
if( lots > max )
fixedlots = max;
return(fixedlots);
}
bool CloseSellTrade ()
{
// Calculates the Moving average indicator and returns its value. // Sample// AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
_iMA4 = iMA( Symbol(), 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0 );
// Returns Close value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.// For the current chart, the information about close prices is in the predefined array named Close[]. // Sample// Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ",// iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ",// iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));
_iClose2 = iClose( Symbol(), 0, 0 );
// add notes here ...
// Logic condition Inline-function declaration for iClose
_iClose2 = iClose( Symbol(), 0, 0 );
// Logic condition Inline-function declaration for iMA
_iMA4 = iMA( Symbol(), 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0 );
double _iClose22;
_iClose22=iClose( Symbol(), 0, 0+1 );
double _iMA42;
_iMA42=iMA( Symbol(), 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0+1 );
if ( (( ( _iClose2 > _iMA4 ) && ( _iClose22 < _iMA42) )))
{
// add notes here ...
for( int pos1664=0;pos1664<OrdersTotal();pos1664++)
{
if(OrderSelect(pos1664,SELECT_BY_POS)==false) continue;
if( ( OrderType() == OP_SELL) )
{
double price7217=0;
price7217 = MarketInfo(OrderSymbol(), MODE_ASK);
_fnCloseSell1 = OrderClose( OrderTicket(), OrderLots(), price7217, Slippage, Blue );
if( _fnCloseSell1 == false )
Print("OrderClose error=", GetLastError());
}
}
return( true );
}
else
{
return( false );
}
} // end elements\user\functions\RSIMAma\CloseSellTrade.fe
bool CloseBuyTrade ()
{
// Calculates the Moving average indicator and returns its value. // Sample// AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
_iMA3 = iMA( Symbol(), 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0 );
// Returns Close value for the bar of indicated symbol with timeframe and shift. If local history is empty (not loaded), function returns 0.// For the current chart, the information about close prices is in the predefined array named Close[]. // Sample// Print("Current bar for USDCHF H1: ",iTime("USDCHF",PERIOD_H1,i),", ", iOpen("USDCHF",PERIOD_H1,i),", ",// iHigh("USDCHF",PERIOD_H1,i),", ", iLow("USDCHF",PERIOD_H1,i),", ",// iClose("USDCHF",PERIOD_H1,i),", ", iVolume("USDCHF",PERIOD_H1,i));
_iClose1 = iClose( Symbol(), 0, 0 );
// add notes here ...
// Logic condition Inline-function declaration for iClose
_iClose1 = iClose( Symbol(), 0, 0 );
// Logic condition Inline-function declaration for iMA
_iMA3 = iMA( Symbol(), 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0 );
double _iClose12;
_iClose12=iClose( Symbol(), 0, 0+1 );
double _iMA32;
_iMA32=iMA( Symbol(), 0, 20, 0, MODE_EMA, PRICE_CLOSE, 0+1 );
if ( (( ( _iClose1 < _iMA3 ) && ( _iClose12 > _iMA32) )))
{
// add notes here ...
for( int pos8673=0;pos8673<OrdersTotal();pos8673++)
{
if(OrderSelect(pos8673,SELECT_BY_POS)==false) continue;
if( ( OrderType() == OP_BUY) )
{
double price5962=0;
price5962 = MarketInfo(OrderSymbol(), MODE_BID);
_fnCloseBuy1 = OrderClose( OrderTicket(), OrderLots(), price5962, Slippage, Blue );
if( _fnCloseBuy1 == false )
Print("OrderClose error=", GetLastError());
}
}
return( true );
}
else
{
return( false );
}
} // end elements\user\functions\RSIMAma\CloseBuyTrade.fe
bool OpenSellTrade ()
{
// Calculates the Relative strength index and returns its value. // Sample// if(iRSI(NULL,0,14,PRICE_CLOSE,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0);
_iRSI2 = iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 );
// Calculates the Moving average indicator and returns its value. // Sample// AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
_iMA2 = iMA( Symbol(), 0, 50, 0, MODE_EMA, _iRSI2, 0 );
// add notes here ...
// Logic condition Inline-function declaration for iRSI
_iRSI2 = iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 );
// Logic condition Inline-function declaration for iMA
_iMA2 = iMA( Symbol(), 0, 50, 0, MODE_EMA, _iRSI2, 0 );
double _iRSI22;
_iRSI22=iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0+1 );
double _iMA22;
_iMA22=iMA( Symbol(), 0, 50, 0, MODE_EMA, _iRSI2, 0+1 );
// Logic condition Inline-function declaration for iRSI
_iRSI2 = iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 );
if ( (( ( _iRSI2 < _iMA2 ) && ( _iRSI22 > _iMA22) )) && ( _iRSI2 > 50 ))
{
lastsignaltimesell6162 = TimeCurrent();
// add notes here ...
double slzero7037;
slzero7037=MarketInfo(Symbol(), MODE_BID)+StopLoss* MarketInfo(Symbol(), MODE_POINT);
if( StopLoss == 0 ) slzero7037=0;
if( fnOkToOpen4663(OP_SELL) == true )
{
if( ECN == false )
{
_fnOpenSell1 = OrderSend( Symbol() , OP_SELL , fnFixLots(Lots) , MarketInfo(Symbol(), MODE_BID) , Slippage , slzero7037 , TakeProfit , StringConcatenate(eaname3418,":", MagicNumber) , MagicNumber , 0 , Red );
}
else
{
_fnOpenSell1 = OrderSend( Symbol(), OP_SELL, fnFixLots(Lots), MarketInfo(Symbol(), MODE_BID), Slippage, 0, 0, StringConcatenate(eaname3418,":", MagicNumber), MagicNumber, 0, Red );
if( _fnOpenSell1 > 0 )
{
if( ecn_count560 < MAX_ECN7464 )
{
ecn_ticket6003[ecn_count560] = _fnOpenSell1;
ecn_sl7797[ecn_count560] = slzero7037;
ecn_tp2286[ecn_count560] = TakeProfit;
ecn_count560++;
}
else
{
Print("Error: MAX ECN orders already open. MAX_ECN7464=", MAX_ECN7464);
}
}
}
}
return( true );
}
else
{
return( false );
}
} // end elements\user\functions\RSIMAma\OpenSellTrade.fe
bool OpenBuyTrade ()
{
// Calculates the Relative strength index and returns its value. // Sample// if(iRSI(NULL,0,14,PRICE_CLOSE,0)>iRSI(NULL,0,14,PRICE_CLOSE,1)) return(0);
_iRSI1 = iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 );
// Calculates the Moving average indicator and returns its value. // Sample// AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
_iMA1 = iMA( Symbol(), 0, 50, 0, MODE_EMA, _iRSI1, 0 );
// add notes here ...
// Logic condition Inline-function declaration for iRSI
_iRSI1 = iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 );
// Logic condition Inline-function declaration for iMA
_iMA1 = iMA( Symbol(), 0, 50, 0, MODE_EMA, _iRSI1, 0 );
double _iRSI12;
_iRSI12=iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0+1 );
double _iMA12;
_iMA12=iMA( Symbol(), 0, 50, 0, MODE_EMA, _iRSI1, 0+1 );
// Logic condition Inline-function declaration for iRSI
_iRSI1 = iRSI( Symbol(), 0, 14, PRICE_CLOSE, 0 );
if ( (( ( _iRSI1 > _iMA1 ) && ( _iRSI12 < _iMA12) )) && ( _iRSI1 < 50 ))
{
lastsignaltimebuy7871 = TimeCurrent();
// add notes here ...
double slzero3076;
slzero3076=MarketInfo(Symbol(), MODE_ASK)-StopLoss* MarketInfo(Symbol(), MODE_POINT);
if( StopLoss == 0 ) slzero3076=0;
if( fnOkToOpen4663(OP_BUY) == true )
{
if( ECN == false )
{
_fnOpenBuy1 = OrderSend( Symbol() , OP_BUY , fnFixLots(Lots) , MarketInfo(Symbol(), MODE_ASK) , Slippage , slzero3076 , TakeProfit , StringConcatenate(eaname3418,":", MagicNumber) , MagicNumber , 0 , Green );
}
else
{
_fnOpenBuy1 = OrderSend( Symbol(), OP_BUY, fnFixLots(Lots), MarketInfo(Symbol(), MODE_ASK), Slippage, 0, 0, StringConcatenate(eaname3418,":", MagicNumber), MagicNumber, 0, Green );
if( _fnOpenBuy1 > 0 )
{
if( ecn_count560 < MAX_ECN7464 )
{
ecn_ticket6003[ecn_count560] = _fnOpenBuy1;
ecn_sl7797[ecn_count560] = slzero3076;
ecn_tp2286[ecn_count560] = TakeProfit;
ecn_count560++;
}
else
{
Print("Error: MAX ECN orders already open. MAX_ECN7464=", MAX_ECN7464);
}
}
}
}
return( true );
}
else
{
return( false );
}
} // end elements\user\functions\RSIMAma\OpenBuyTrade.fe
int start()
{
tick6879++;
chartcomment6274="";
if (ShowTick == true ) chartcomment6274="Build # 2, 2020-07-2 14:43:13 (VTS 4.0.0.92) MAGIC: "+MagicNumber+"\nTICK:"+tick6879+ "\n" ;
fnModifyEcn7794();
_OpenBuyTrade = OpenBuyTrade();
_OpenSellTrade = OpenSellTrade();
_CloseBuyTrade = CloseBuyTrade();
_CloseSellTrade = CloseSellTrade();
fnComment9704();
return( 0 );
} // end elements\user\systems\RSIMAma\RSIMAma.se
int init( )
{
return(0);
}
int deinit( )
{
return(0);
}
void OnTimer()
{
}
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);
ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, true);
ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true);
}