Candlestick close crossover Senkan Span B

Created at 05 Dec 2017, 01:04
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
VI

Vince

Joined 04.12.2017

Candlestick close crossover Senkan Span B
05 Dec 2017, 01:04


Dear community,

I am trying to build an alert involving Ichimoku Kinko Hyo and the simple moving average, but as this is completely new to me I am totally lost on what to write at each section of the script.

If anyone could give me pointers that would be very appreciated!

The idea is to create an alert when the close of a candlestick has crossed above the Senkou Span B with default setting of 52, while also the open of a candlestick is above the Simple Moving Average with period 200. When this happens an "up" arrow should be displayed on the chart below the candle that fits the criteria, or if that is not possible below the next forming candle. The arrow should be placed at the candlestick low, minus the Average True Range with settings to 14 periods. Also an email would be sent as a notification of the occurrence.

The indicator would do everything opposit when the close of the candlestick has crossed below the Senkou Span B with default setting of 52, while also the open of a candlestick is below the Simple Moving Average with period 200.

For MT4 I had this indicator which looks like:

//+------------------------------------------------------------------+
#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 "Buy"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x0000FF
#property indicator_label2 "Sell"

//--- indicator buffers
double Buffer1[];
double Buffer2[];

datetime time_alert; //used when sending alert
bool Send_Email = true;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Ichimoku Alert @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Send_Email) SendMail("Ichimoku Alert", type+" | Ichimoku Alert @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 241);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 242);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(50000-1, rates_total-1-500)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(Close[1+i] > iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANB, i)
      && Close[1+i+1] < iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANB, i+1) //Candlestick Close crosses above Ichimoku Kinko Hyo
      && Open[1+i] > iMA(NULL, PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i) //Candlestick Open > Moving Average
      )
        {
         Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Buy"); //Alert on next bar open
         time_alert = Time[1];
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(Close[1+i] < iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANB, i)
      && Close[1+i+1] > iIchimoku(NULL, PERIOD_CURRENT, 9, 26, 52, MODE_SENKOUSPANB, i+1) //Candlestick Close crosses below Ichimoku Kinko Hyo
      && Open[1+i] < iMA(NULL, PERIOD_CURRENT, 200, 0, MODE_SMA, PRICE_CLOSE, i) //Candlestick Open < Moving Average
      )
        {
         Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Sell"); //Alert on next bar open
         time_alert = Time[1];
        }
      else
        {
         Buffer2[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

If anyone could help me out, it would be very much appreciated!

Vincietrader


@Vince