#include // include the Trade library for buy and sell functions input int period = 14; // set the period for statistical indicators input int threshold = 70; // set the threshold for generating signals double movingAverage; // variable to store the moving average double relativeStrength; // variable to store the relative strength index (RSI) // initialize the indicator void OnInit() { // set the indicator's properties IndicatorSetString(INDICATOR_SHORTNAME, "Spike Detector"); IndicatorSetInteger(INDICATOR_DIGITS, 2); } // calculate the indicator int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { // check if there is enough data to calculate the indicator if (rates_total < period) return 0; // calculate the moving average and RSI movingAverage = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_CLOSE, 0); relativeStrength = iRSI(NULL, 0, period, PRICE_CLOSE, 0); // iterate through the data for (int i = 0; i < rates_total; i++) { // check if a boom is imminent (RSI above threshold) if (relativeStrength[i] > threshold) { // generate a buy signal and display a green arrow on the chart Alert("Boom imminent! Buy now!"); ObjectCreate("arrow_" + IntegerToString(i), OBJ_ARROW_UP, 0, time[i], high[i]); OrderSend(Symbol(), OP_BUY, 1, Ask, 3, 0, 0, "buy order", 0, 0, Green); } // check if a crash is imminent (RSI below threshold) if (relativeStrength[i] < threshold) { // generate a sell signal and display a red arrow on the chart Alert("Crash imminent! Sell now!"); ObjectCreate("arrow_" + IntegerToString(i), OBJ_ARROW_DOWN, 0, time[i], low[i]); OrderSend(Symbol(), OP_SELL, 1, Bid, 3, 0, 0, "sell order", 0, 0, Red); } } return rates_total; }
- EA RSI Buy and Sell code help
- Can't draw to the window.
- icustom and copybuffer problem
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register