Possible to use an indicator in my own EA ?

 

Hi,


I'm trying to make my own EA that just warn me (or do somthing else) when Ichimoku tells me to buy or to sell.

Do you if it's possible to incorporate an already existing indicator in a EA script ?


cheers


Aymeric

 

Of course, you can get the values that you need with

iIchimoku()

and calculate what you need from the results

 
Thanks a lot for you quick answer, it's was not in my book on MQL4, and how do you call the Tenkan value of Ichi for instance ?
 
AYMERIC:
Thanks a lot for you quick answer, it's was not in my book on MQL4, and how do you call the Tenkan value of Ichi for instance ?

 
I don't know if this is useful to you or not. It's some code I did for an indicator for a thread in Forex Factory
//+------------------------------------------------------------------+
//|                                                     FXX_Ichi.mq4 |
//|                                                           GumRai |
//|                                                             none |
//+------------------------------------------------------------------+
/*The alert should be triggered when there is a break out of price on the 9,26,52 Kumo Cloud. When this happens, the
indy should check if the chickou-spans for the other two higher ichis are also above or below their respective clouds
( even though not kept visisble on the charts.)
So ideally, a buy trigger alert should happen, when the last closed candle bar has closed above the cloud, the
tenken-sen crosses the kijun-sen from below ( and both above the cloud after the cross) for ( 9/26/52 setting) and 
the chickou-spans for 78 chickou ( in case of 27/78/156 ) and 156 chickou ( in case of 54/156/312) are also above the
kumo cloud and current price for their respective ichis .
So ideally, a sell trigger alert should happen, when the last closed candle bar has closed below the cloud, the
tenken-sen crosses the kijun-sen from above ( and below the cloud) for ( 9/26/52 setting) and the chickou-spans
for 78 chickou ( in case of 27/78/156 ) and 156 chickou ( in case of 54/156/312) are also below the kumo cloud and
current price for their respective ichis.

3. Alert trigger should be only after the last candle bar has closed and above conditions are met.

The point is ideally the point where a buy alert should be triggered, after the close of that bar after the tenken-sen
has crossed the kijun-sen for def ichi setting of ( 9/26/52) Similarly sell alert for reverse.*/

#property copyright "GumRai"
#property link      "none"
#property version   "1.00"
#property strict
#property indicator_chart_window
//--- input parameters
input int      Tenkan_Sen1=9;
input int      Kijun_Sen1=26;
input int      Senkou_Span_B1=52;
input int      Tenkan_Sen2=27;
input int      Kijun_Sen2=78;
input int      Senkou_Span_B2=156;
input int      Tenkan_Sen3=54;
input int      Kijun_Sen3=156;
input int      Senkou_Span_B3=312;
input color    ArrowColour=clrBlack;
input int      ArrowSize=3;

double ZeroBars;
string Signal;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {

   ZeroBars = MathMax(Tenkan_Sen1,Kijun_Sen1);
   ZeroBars = MathMax(ZeroBars,Senkou_Span_B1);
   ZeroBars = MathMax(ZeroBars,Tenkan_Sen2);
   ZeroBars = MathMax(ZeroBars,Kijun_Sen2);
   ZeroBars = MathMax(ZeroBars,Senkou_Span_B2);
   ZeroBars = MathMax(ZeroBars,Tenkan_Sen3);
   ZeroBars = MathMax(ZeroBars,Kijun_Sen3);
   ZeroBars = MathMax(ZeroBars,Senkou_Span_B3);
   ZeroBars=ZeroBars*2;

//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   for(int i=ObjectsTotal()-1;i>=0;i--)
     {
      string ObName=ObjectName(i);
      Print(ObName);
      if(StringFind(ObName,"FXX_Ichi",0)!=-1)
         ObjectDelete(ObName);
     }

  }
//+------------------------------------------------------------------+
//| 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+1;
   if(prev_calculated==0)
      limit=rates_total-ZeroBars;

   double cloud_1a,cloud_1b,cloud_2a,cloud_2b,cloud_3a,cloud_3b,tenkan,tenkan_prev,kijun,kijun_prev,cloud_high1,cloud_low1
      ,cloud_high2,cloud_low2,cloud_high3,cloud_low3;
   for(int index=limit;index>0;index--)
     {
      cloud_1a = iIchimoku(Symbol(),0,Tenkan_Sen1,Kijun_Sen1,Senkou_Span_B1,MODE_SENKOUSPANA,index);
      cloud_1b = iIchimoku(Symbol(),0,Tenkan_Sen1,Kijun_Sen1,Senkou_Span_B1,MODE_SENKOUSPANB,index);
      cloud_2a = iIchimoku(Symbol(),0,Tenkan_Sen2,Kijun_Sen2,Senkou_Span_B2,MODE_SENKOUSPANA,index+Kijun_Sen2);
      cloud_2b = iIchimoku(Symbol(),0,Tenkan_Sen2,Kijun_Sen2,Senkou_Span_B2,MODE_SENKOUSPANB,index+Kijun_Sen2);
      cloud_3a = iIchimoku(Symbol(),0,Tenkan_Sen3,Kijun_Sen3,Senkou_Span_B3,MODE_SENKOUSPANA,index+Kijun_Sen3);
      cloud_3b = iIchimoku(Symbol(),0,Tenkan_Sen3,Kijun_Sen3,Senkou_Span_B3,MODE_SENKOUSPANB,index+Kijun_Sen3);
      tenkan= iIchimoku(Symbol(),0,Tenkan_Sen1,Kijun_Sen1,Senkou_Span_B1,MODE_TENKANSEN,index);
      kijun = iIchimoku(Symbol(),0,Tenkan_Sen1,Kijun_Sen1,Senkou_Span_B1,MODE_KIJUNSEN,index);
      tenkan_prev= iIchimoku(Symbol(),0,Tenkan_Sen1,Kijun_Sen1,Senkou_Span_B1,MODE_TENKANSEN,index+1);
      kijun_prev = iIchimoku(Symbol(),0,Tenkan_Sen1,Kijun_Sen1,Senkou_Span_B1,MODE_KIJUNSEN,index+1);
      cloud_high1= MathMax(cloud_1a,cloud_1b);
      cloud_low1=MathMin(cloud_1a,cloud_1b);
      cloud_high2=MathMax(cloud_2a,cloud_2b);
      cloud_low2=MathMin(cloud_2a,cloud_2b);
      cloud_high3=MathMax(cloud_3a,cloud_3b);
      cloud_low3=MathMin(cloud_3a,cloud_3b);

      //Buy Condition 1 tenken-sen crosses the kijun-sen from below ( and both above the cloud after the cross)
      //Bar closed above cloud
      if(tenkan>kijun && tenkan_prev<kijun_prev && kijun>cloud_high1 && Close[index]>cloud_high1)
        {
         //Check Chikou is above its cloud and price
         if(Close[index]>cloud_high1 && Close[index]>cloud_high2 && Close[index]>cloud_high3
            && Close[index]>Close[index+Kijun_Sen1] && Close[index]>Close[index+Kijun_Sen2]
            && Close[index]>Close[index+Kijun_Sen3])
           {
            Signal="Buy";
            string name="FXX_IchiupArrow"+(string)Time[index];
            if(ObjectFind(0,name)!=0)
              {
               ObjectCreate(name,OBJ_ARROW_UP,0,Time[index],Low[index]-(Period()*Point*2));
               ObjectSet(name,OBJPROP_COLOR,ArrowColour);
               ObjectSet(name,OBJPROP_WIDTH,ArrowSize);
               ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_TOP);
              }
            name="FXX_IchiupArrowCloud"+(string)Time[index];
            if(ObjectFind(0,name)!=0)
              {
               ObjectCreate(name,OBJ_ARROW_UP,0,Time[index],cloud_low1);
               ObjectSet(name,OBJPROP_COLOR,ArrowColour);
               ObjectSet(name,OBJPROP_WIDTH,ArrowSize);
               ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_TOP);
              }

           }

        }
      //Sell Condition
      if(tenkan<kijun && tenkan_prev>kijun_prev && kijun<cloud_low1 && Close[index]<cloud_low1)
        {
         //Check Chikou is below its cloud and price
         if(Close[index]<cloud_low1 && Close[index]<cloud_low2 && Close[index]<cloud_low3
            && Close[index]<Close[index+Kijun_Sen1] && Close[index]<Close[index+Kijun_Sen2]
            && Close[index]<Close[index+Kijun_Sen3])
           {
            Signal="Sell";
            string name="FXX_IchidownArrow"+(string)Time[index];
            if(ObjectFind(0,name)!=0)
              {
               ObjectCreate(name,OBJ_ARROW_DOWN,0,Time[index],High[index]+(Period()*Point*2));
               ObjectSet(name,OBJPROP_COLOR,ArrowColour);
               ObjectSet(name,OBJPROP_WIDTH,ArrowSize);
               ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
              }
            name="FXX_IchidownArrowCloud"+(string)Time[index];
            if(ObjectFind(0,name)!=0)
              {
               ObjectCreate(name,OBJ_ARROW_DOWN,0,Time[index],cloud_high1);
               ObjectSet(name,OBJPROP_COLOR,ArrowColour);
               ObjectSet(name,OBJPROP_WIDTH,ArrowSize);
               ObjectSetInteger(0,name,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
              }

           }

        }
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

The example here should help... https://docs.mql4.com/indicators/iichimoku

Oh after page update i see someone has already pointed you in the right direction... good job....

 
Thanks a lot
Reason: