Author: eurweb@gmail.com copyright 2024
Profit factor:
0.00
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open orders
Indicators Used
Relative strength index
Miscellaneous
It issuies visual alerts to the screen
1 Views
0 Downloads
0 Favorites
RSIsimpl
ÿþ//+------------------------------------------------------------------+

//|                               Copyright © 2024, Yepifanov Yuriy  |

//|                                                eurweb@gmail.com  |

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



#property copyright "eurweb@gmail.com copyright 2024"

#property link      "mailto:eurweb@gmail.com"

#property version   "1.01"

#property description "EA based on RSI"

#property description   "WARNING: Use this software at your own risk."

#property description   " "

#property strict

 



///sinput string        titleparams = " Settings ";// -----------------   



input double         lot = 0.01;

input int            ext_profit_ptk = 100; // profit 

input int            ext_loss_ptk   = 100; // stop los

input int            ext_slip       = 10;    // slip

input int            ext_maxspred   = 30; // max spred

input int            Magic = 243545;

 

int            RSI_Period = 14;          // RSI period



///int            MA_Period  = 200;         // MA period

//ENUM_MA_METHOD MA_Method  = MODE_SMA;    // MA method





int            rsi_min_level  = 23;  // rsi < level -  buy 

int            rsi_max_level  = 77;  // rsi > level -  sell 





//--- 8=48:0B>@K

double RSI;



// system vars



double STOPLEVEL;



string error_msg = "";

 

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

//| Expert initialization function                                   |

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



int OnInit()

{

   return(INIT_SUCCEEDED);

}







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

//| Expert tick function                                             |

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

void OnTick()

  {



   if (!IsTradeAllowed()) 

   {

      Alert("Trade not Allowed");

      return;

   }







   if (IsNewBar() == false)

     return;



   if (MarketInfo(Symbol(),MODE_SPREAD) >=  ext_maxspred)

      return;





   if(TotalOpenOrders())

     return;

    

   InitIndicators();

   if(BuySignal())

   {

      myOrderSend(OP_BUY);

   }

   if(SellSignal())

   {

      myOrderSend(OP_SELL);

   }

  }

 

 

// 

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

//| Initializing indicators                                          |

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

void InitIndicators()

{

   // RSI

   RSI = iRSI(_Symbol,PERIOD_CURRENT,RSI_Period,PRICE_CLOSE,1);

}

 

 

bool BuySignal()

{

   return (rsi_min_level > RSI);

} 





bool SellSignal()

{

   return (rsi_max_level < RSI);

} 

 



int myOrderSend(int ordertype)

{

   double sl = 0;

   double tp = 0;

   double  price = 0;



   STOPLEVEL = MarketInfo(Symbol(),MODE_STOPLEVEL);



   if (ext_loss_ptk < STOPLEVEL)

   {

      Print("Error OrderSend wrong StopLoss: ", ext_loss_ptk, " STOPLEVEL ", STOPLEVEL);

   }



   if (ext_profit_ptk < STOPLEVEL)

   {

      Print("Error OrderSend wrong TakeProfit: ", ext_profit_ptk, " STOPLEVEL ", STOPLEVEL);

   }



   if (!checkLotVolume(lot, error_msg))

   {

      Print("Error ",error_msg);

      return -2;

   }



   if(!isNewOrderAllowed()) 

   {

      Print("Error OrderSend: New Order not allowed");

      return -3;

   }





   if (AccountFreeMarginCheck(Symbol(),ordertype,lot)<0)

   {

      Print("Error OrderSend: AccountFreeMarginCheck");

      return -4;

   }

   

  if (ordertype == OP_SELL)

  {

    price = Bid;

    tp = Bid - ext_profit_ptk * _Point;

    sl = Ask + ext_loss_ptk * _Point;

  }

  if (ordertype == OP_BUY)

  {

    price = Ask;

    tp = Ask + ext_profit_ptk * _Point;

    sl = Bid - ext_loss_ptk * _Point;

  }



   sl = NormalizeDouble(sl,_Digits);

   tp = NormalizeDouble(tp,_Digits);

   int ticket = OrderSend(_Symbol, ordertype, lot, price, ext_slip, sl, tp, "open Order", Magic);

 

   if(ticket<0)

   {

      Print("Error OrderSend: ",GetLastError());

   }

   else

   {

      Print("Order price ", price, " tp ",  tp, " sl ", sl , " lot ", lot );

   }

      

   return ticket;

}









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

bool isNewOrderAllowed()

{

   int max_allowed_orders=(int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS);

   if(max_allowed_orders==0) return(true);

   if(OrdersTotal()<max_allowed_orders) return(true);

   return(false);

}





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

//|  Checks the order volume                                         |

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

bool checkLotVolume(double volume,string &description)

{

//--- minimum acceptable volume for trading operations

   double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);

   if(volume<min_volume)

     {

      description=StringFormat("Lot volume is less than the minimum allowable SYMBOL_VOLUME_MIN=%.2f",min_volume);

      return(false);

     }



//--- maximum allowed volume for trading operations

   double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);

   if(volume>max_volume)

     {

      description=StringFormat("Lot volume exceeds maximum permissibleSYMBOL_VOLUME_MAX=%.2f",max_volume);

      return(false);

     }



//--- we get the minimum volume gradation

   double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);



   int ratio=(int)MathRound(volume/volume_step);

   if(MathAbs(ratio*volume_step-volume)>0.0000001)

   {

      description=StringFormat("The volume is not a multiple of the minimum gradation SYMBOL_VOLUME_STEP=%.2f, nearest correct volume %.2f",

                               volume_step,ratio*volume_step);

      return(false);

   }



   return(true);

}

 

 

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

//|  new bar opened ?                                                |

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

bool IsNewBar()   

{        

   static datetime RegBarTime=0;

   datetime ThisBarTime = Time[0];

 

   if (ThisBarTime == RegBarTime)

   {

      return(false);

   }

   else

   {

      RegBarTime = ThisBarTime;

      return(true);

   }

}   

 

 

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

//|  Returning the number of open orders                             |

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

int TotalOpenOrders()

{

   int total_orders = 0;

 

   for(int order = 0; order < OrdersTotal(); order++) 

   {

      if(OrderSelect(order,SELECT_BY_POS,MODE_TRADES)==false) continue;

      

      if(OrderSymbol() != _Symbol) continue;

 

      if(OrderMagicNumber() == Magic)

      {

            total_orders++;

      }

   }

 

   return(total_orders);

}





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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

{

}

Comments