Download MetaTrader 5
To add comments, please log in or register
Do you have a trading signal? Publish it in your blog as well!
trader3000
227
trader3000 2016.06.04 12:14 

Hi Everyone

 

I've been struggling to modify an indicator so that it alerts me when the price crosses the upper or lower CCI level (rather than when the CCI indicator line crosses a level).  In other words when Ask>Upper_indicator_level (100) -----> Alert Sell

But it does not get the price at that level.  My understanding is that the best way (and perhaps the only way) that this can be done is to create an object at that line and then get the price of the object.  So if I print the indicator_level1 it is 100.  Objectcreate is looking for a price hee and I am saying the price is 100.  This is obviouly not correct.  So I do not know how to enter the price for a certain level, because if I know what the price is at that level, I would not need ObjectGet().  With the code I have, it does not draw an object and when I print the value of ObjectGet, it actually prints the value of the indicator, namely 100.  Can someone please help me with this?  Thank you


//+------------------------------------------------------------------+
//|                                                  CCI_Woodies.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
#property indicator_level1 100
#property indicator_level2 0
#property indicator_level3 -100
#property indicator_levelcolor Yellow
#property indicator_levelstyle STYLE_DOT

//---- input parameters
extern int CCIPeriod1=14;

extern string LineName="MyLine1";
extern color LineColor=AliceBlue; 
extern int LineStyle=STYLE_SOLID;
//---- buffers
double CCIBuffer1[];
 
//---- Bar number the alert to be searched by
#define SIGNAL_BAR 1
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,White);
   SetIndexBuffer(0,CCIBuffer1);
//----
   SetIndexDrawBegin(0,CCIPeriod1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| CCI_Woodies                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
//----
   if(Bars<=CCIPeriod1) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=CCIPeriod1;i++) CCIBuffer1[Bars-i]=0.0;
//----
   i=Bars-CCIPeriod1-1;
   if(counted_bars>=CCIPeriod1) i=Bars-counted_bars-1;
   while(i>=0)
     {
      CCIBuffer1[i]=iCCI(NULL,0,CCIPeriod1,PRICE_TYPICAL,i);
      i--;
     }
   int a=1; //just something that will always be true
    if(a==a)
      {
      ObjectCreate(LineName, OBJ_HLINE, 0, 0, indicator_level1);
      ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
     }   
      double topval =  ObjectGet( LineName, OBJPROP_PRICE1);
      if (Ask>topval){
      Alert("CCI (", Symbol(), ", ", Period(), ")  -  SELL!!!");
      PlaySound("Alert.wav");
      Print("topval ",topval);
      }
      
  //---- Completely the same for the SELL alert
    if(a==a)
      {
      ObjectCreate(LineName, OBJ_HLINE, 0, 0, indicator_level3);
      ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
     }   
      double lowval =  ObjectGet( LineName, OBJPROP_PRICE2);
      if (Bid<lowval){
      Alert("CCI (", Symbol(), ", ", Period(), ")  -  BUY!!!");
      PlaySound("Alert.wav");
      Print("lowval ",lowval);
      } 
         
   return(0);
  }
//+------------------------------------------------------------------+
trader3000
227
trader3000 2016.06.06 11:10  

I've been working on this over the weekend, and I don't think it's possible to create an object at the CCI horizontal level line, because ObjectCreate requires me to enter a price, which I don't know since the level is dynamic.  I'm thinking that I should rather use ObjectGetDouble, but this does not work either, supposedly because I'm not creating an object.  I have seen a few indy's that display the price at the different Fibonacci levels, but I also cannot get that to work.  So, I'm at the point where it seems impossible to set this alert.

double _price=ObjectGetDouble(0,indicator_level1,OBJPROP_LEVELVALUE);
   Print("price ",_price);  //Prints 0.0 (incorrect)
   Print("level ",indicator_level1);  //Prints 100 (correct)
   Print("OBJPROP ",OBJPROP_LEVELVALUE); //Prints 204 (incorrect)
whroeder1
13627
whroeder1 2016.06.06 13:08  
Trader3000: I've been struggling to modify an indicator so that it alerts me when the price crosses the upper or lower CCI level (rather than when the CCI indicator line crosses a level).  In other words when Ask>Upper_indicator_level (100) -----> Alert Sell

Your question makes no sense. CCI is in a separate window. Price doesn't exist in the separate window.

Wait for CCI to read above 100, When it does, the current price is the price you want.

trader3000
227
trader3000 2016.06.06 16:07  
WHRoeder:

Your question makes no sense. CCI is in a separate window. Price doesn't exist in the separate window.

Wait for CCI to read above 100, When it does, the current price is the price you want.

Thank you for your reply.  I probably should have mentioned this, but I have a workaround to get the CCI indi on the main chart window as per the screenshot (link at bottom of this tread).  The CCI value is not equal to the price.  So this is why I was wondering if the price of the 100 and the -100 level can be captured.  I would like to have some code e.g. if Ask>price at level 100, create sell alert.  I have a Fibo indy which capture the price at the various fibo levels, but I am unable to modify this for the CCI levels.  Here is the fibo code

int fibHigh = iHighest(Symbol(),Period(),MODE_HIGH,WindowFirstVisibleBar()-1,1);
     int fibLow  = iLowest(Symbol(),Period(),MODE_LOW,WindowFirstVisibleBar()-1,1);
     
     datetime highTime = Time[fibHigh];
     datetime lowTime  = Time[fibLow];
     
      if(fibHigh>fibLow){
      WindowRedraw();
      ObjectCreate("XIT_FIBO",OBJ_FIBO,0,highTime,High[fibHigh],lowTime,Low[fibLow]);
      color levelColor = Red;
      }
      else{
      WindowRedraw();
      ObjectCreate("XIT_FIBO",OBJ_FIBO,0,lowTime,Low[fibLow],highTime,High[fibHigh]);
      levelColor = Gold;
      }
      
      double fiboPrice1=ObjectGet("XIT_FIBO",OBJPROP_PRICE1);
      double fiboPrice2=ObjectGet("XIT_FIBO",OBJPROP_PRICE2);
      
      double fiboPriceDiff = fiboPrice2-fiboPrice1;
      string fiboValue0 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.0,Digits);
      string fiboValue23 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.236,Digits);
      string fiboValue38 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.382,Digits);
      string fiboValue50 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.50,Digits);
      string fiboValue61 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.618,Digits);
      string fiboValue100 = DoubleToStr(fiboPrice2-fiboPriceDiff*1.0,Digits);
    
     ObjectSet("XIT_FIBO",OBJPROP_FIBOLEVELS,6);
     ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+0,0.0);
     ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+1,0.236);
     ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+2,0.382);
     ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+3,0.50);
     ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+4,0.618);
     ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+5,1.0);
     
     
     ObjectSet("XIT_FIBO",OBJPROP_LEVELCOLOR,levelColor);
     ObjectSet("XIT_FIBO",OBJPROP_LEVELWIDTH,1);
     ObjectSet("XIT_FIBO",OBJPROP_LEVELSTYLE,STYLE_DASHDOTDOT);
     ObjectSetFiboDescription( "XIT_FIBO", 0,fiboValue0+" --> 0.0%"); 
     ObjectSetFiboDescription( "XIT_FIBO", 1,fiboValue23+" --> 23.6%"); 
     ObjectSetFiboDescription( "XIT_FIBO", 2,fiboValue38+" --> 38.2%"); 
     ObjectSetFiboDescription( "XIT_FIBO", 3,fiboValue50+" --> 50.0%");
     ObjectSetFiboDescription( "XIT_FIBO", 4,fiboValue61+" --> 61.8%");
     ObjectSetFiboDescription( "XIT_FIBO", 5,fiboValue100+" --> 100.0%");

 https://www.mql5.com/en/charts/5264417/eurusd-m1-ironfx-financial-services

/
To add comments, please log in or register