Lines

 

Pivot Lines indicator can be as seen below: 

double   PP,                                                                                             // Pivot Levels

         R1, 

        R2,

         R3,

         S1,

         S2,

         S3,

       Plot(0,"R1"+name,0,time,StylePivots,WidthPivots);  

In ea, how is similar applied to EA. 

Thank you.

 
Mary A Thompson:

Pivot Lines indicator can be as seen below: 

double   PP,                                                                                             // Pivot Levels

         R1, 

        R2,

         R3,

         S1,

         S2,

         S3,

       Plot(0,"R1"+name,0,time,StylePivots,WidthPivots);  

In ea, how is similar applied to EA. 

Thank you.

1. Wrap your code in a code box, please, and format it properly so it's easier to read.

2. Anyway, if you want to call an indicator from an EA:

* If it's a built-in indicator, like RSI or ATR, for example, then you can use iRSI() or iATR()

* If it's a custom indicator, then you can use iCustom().

iCustom - Technical Indicators - MQL4 Reference
iCustom - Technical Indicators - MQL4 Reference
  • docs.mql4.com
iCustom - Technical Indicators - MQL4 Reference
 
Alexander Martinez #:

1. Wrap your code in a code box, please, and format it properly so it's easier to read.

2. Anyway, if you want to call an indicator from an EA:

* If it's a built-in indicator, like RSI or ATR, for example, then you can use iRSI() or iATR()

* If it's a custom indicator, then you can use iCustom().

Not really calling indicator but applying pivot to ea .Is it the same case as in indicator.
 
double high1=iHigh(_Symbol,PERIOD_D1,1);
double close1=iclose(_Symbol,PERIOD_D1,1);
double low1=ilow(_Symbol,PERIOD_D1,1);
Pivot=(high1+ilow1+iclose1)/3
ObjectDelete(0, ObjName);
ObjectCreate(0,objName,OBJ_LINE,0,time,pivot ); // The pivot line is created
ObjectSetInteger(0,ObjName,OBJPROP_Color_WIDTH); //color ........  


 
Mary A Thompson #:
Not really calling indicator but applying pivot to ea .Is it the same case as in ea.
 
double high1=iHigh(_Symbol,PERIOD_D1,1);
double close1=iclose(_Symbol,PERIOD_D1,1);
double low1=ilow(_Symbol,PERIOD_D1,1);
Pivot=(high1+ilow1+iclose1)/3
ObjectDelete(0, ObjName);
ObjectCreate(0,objName,OBJ_LINE,0,time,pivot ); // The pivot line is created
ObjectSetInteger(0,ObjName,OBJPROP_Color_WIDTH); //color ........  

The names aren't the same.  One starts with lowercase, the other two with uppercase.

Similar issue; use iClose and iLow.

OBJ_LINE is not a defined constant in MQL. Did you mean OBJ_HLINE?

Other than that, your code looks fine and your object should be created, even in an EA.

If this doesn't solve your problem, please elaborate and provide more code or pictures describing the issue.

 
Alexander Martinez #:

The names aren't the same.  One starts with lowercase, the other two with uppercase.

Similar issue; use iClose and iLow.

OBJ_LINE is not a defined constant in MQL. Did you mean OBJ_HLINE?

Other than that, your code looks fine and your object should be created, even in an EA.

If this doesn't solve your problem, please elaborate and provide more code or pictures describing the issue.

Sorry for the mix up alphabets but the above ,code is just an example of pivot as indicator.

 
Mary A Thompson #:

Sorry for the mix up alphabets but the above code is meant for indicator. the question is ,in ea, how can this be applied as a pivot lines.

If I'm understanding correctly:

Normally, I (and many people) wouldn't code for others who don't know how to code, but since you provided the code. Also, this is not how I would do it, either, but this is just for you to plug in:

double PP = (enter calculation);
double R1 = (enter calculation);
double R2 = (enter calculation);
double R3 = (enter calculation);
double S1 = (enter calculation);
double S2 = (enter calculation);
double S3 = (enter calculation);



//--- from, here, just call Plot function with the appropriate parameters



void Plot(string prefix, string name, double pivot_price, color pivot_color, ENUM_LINE_STYLE pivot_style, int pivot_width, datetime time=0,  long chart_id=0, int subwindow=0) {
  string objName = prefix + name;
  
  bool wasCreated = ObjectCreate(chart_id, objName, OBJ_HLINE, subwindow, time, pivot_price);
  
  if (wasCreated) {
    ObjectSetInteger(chart_id, objName, OBJPROP_COLOR, pivot_color);
    ObjectSetInteger(chart_id, objName, OBJPROP_STYLE, pivot_style);
    ObjectSetInteger(chart_id, objName, OBJPROP_WIDTH, pivot_width);
  } else {
    //--- probably already exists
    ObjectSetDouble(chart_id, objName, OBJPROP_PRICE1, pivot_price);
  }
}