You are on page 1of 3

//+------------------------------------------------------------------+

//| Ascend+Descen RSI.mq4 |


//| Mr.H .Aung |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Mr.H .Aung"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+

input int InpTakeProfitPts = 100; // Take profit


points
input int InpStopLossPts = 300; // Stop
loss points not 0 & 1

//
// Standard inputs
//
input double InpOrderSize = 2; // Order
size
input string InpTradeComment = "HHA RSI Ascending"; // Trade
comment
input int InpMagicNumber = 199309; // Magic
number
input double InpLessThanRsi = 30 ; // Low Rsi Defaul
input double InpGreaterThanRsi = 70 ; // High Rsi Defaul
// Use these to store the point values of sl and tp converted to double
//
double TakeProfitSell;
double StopLossSell;
double TakeProfitBuy;
double StopLossBuy;
bool CloseOpposite;

int order;

double currentOpen = Open[0];


double lastOpen = Open[1];
double lastHigh = High[1];
double lastLow = Low[1];
double lastClose = Close[1];
double aveLastOP = ((lastOpen+lastClose)/2);

int OnInit() {

//
// Convert the input point sl tp to double
//

double point = SymbolInfoDouble(Symbol(), SYMBOL_POINT);


TakeProfitSell = Bid -(InpTakeProfitPts * point);
StopLossSell = Bid +(InpStopLossPts * point);
TakeProfitBuy = Ask +(InpTakeProfitPts * point);
StopLossBuy = Ask -(InpStopLossPts * point);
CloseOpposite = false;

return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+

//+----------------------------+

void OnDeinit(const int reason)


{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+

void OnTick()
{

double rsiIndex = iRSI(NULL,PERIOD_CURRENT,14,PRICE_CLOSE,0);

if (rsiIndex >= InpGreaterThanRsi && Bid > lastHigh ){


//Buy
if (order <=0){
order =
OrderSend(NULL,OP_BUY,InpOrderSize,Ask,1,StopLossBuy,TakeProfitBuy,NULL,InpTradeCom
ment,0,clrGreen);}
}
else if (rsiIndex <= InpLessThanRsi && Ask < lastLow ){
//Sell
if (order <=0){

order =
OrderSend(NULL,OP_SELL,InpOrderSize,Bid,1,StopLossSell,TakeProfitSell,NULL,InpTrade
Comment,0,clrGreen);}
}
else if (rsiIndex >= InpGreaterThanRsi && Ask < aveLastOP ){
//Sell
if (order <=0){
order =
OrderSend(NULL,OP_SELL,InpOrderSize,Bid,1,StopLossSell,TakeProfitSell,NULL,InpTrade
Comment,0,clrGreen);}
}
else if (rsiIndex <= InpLessThanRsi && Bid > aveLastOP ){
//Buy
if (order <=0){

order =
OrderSend(NULL,OP_BUY,InpOrderSize,Ask,1,StopLossBuy,TakeProfitBuy,NULL,InpTradeCom
ment,0,clrGreen);}
}
}

void closeOrder(){

if (Bid > aveLastOP ){


{for (int i=0;i<OrdersTotal();i++)

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType() == OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Bid,2,clrBlue);}
}

if ( Ask < aveLastOP){


{for (int i=0;i<OrdersTotal();i++)

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType() == OP_BUY )
OrderClose(OrderTicket(),OrderLots(),Ask,2,clrBlue);}}

You might also like