Using the price level of a teminal implemented Horizontal Line

 

Surely this can be done right? Reading the price level

of a user installed horizontal line. By user installed I mean

placed on to a chart manually.


The following code is something i was playing with trying to learn to do just that.


In the end i want to be able to place 2 Horizontal lines on a chart

and have my indicator calculate their pip difference.

From there i would calculate a number of other items of interest.

SL as a percentage of equity, max number of Units i could trade as a % of equity,

and other risk management concerns.


Problem is I am a very new programmer i cannot get the program to pick

up the NEW price once I move the h-line on the chart. As if the system ran once and was done.

Doesnt it cycle?



The code represents a number of different efforts to get to the data. It is simply a

test program to try to learn how the objects work so there are many extraneous lines.


Your help in any fashion is MOST appreciated.


//--------------------------------------------------------------------
// userindicator.mq4
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
#property indicator_chart_window // Indicator is drawn in the main window
#property indicator_buffers 2 // Number of buffers
#property indicator_color1 Blue // Color of the 1st line
#property indicator_color2 Red // Color of the 2nd line

double Buf_0[],Buf_1[],P1=0, P2=0,P3=0,P4=0, xCoord=0, yCoord=0, Pft=0; // Declaring arrays (for indicator buffers)
int cntX=0;
datetime T1=0,T2=0,T3=0;


datetime drop_time=0;
double drop_price=0 ;



//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll();
// deleting all objects

return(0);
}

//--------------------------------------------------------------------
int init() // Special function init()
{


P1 = ObjectGet("vline", OBJPROP_PRICE1);//Vertical
P2 = ObjectGet("vline", OBJPROP_PRICE2);
T1 = ObjectGet("vline", OBJPROP_TIME1);
T2 = ObjectGet("vline", OBJPROP_TIME2);

T1 = Time[10];
T2 = Time[20];
P1 = 91.25;
P2 = 90.0;


return; // Exit the special funct. init()
}
//--------------------------------------------------------------------
int start() // Special function start()
{

P3 = ObjectGet("Buy-Line", OBJPROP_PRICE1);// B-S difference



ObjectCreate("Sell-Line", OBJ_HLINE, 0, 0,drop_price);
ObjectCreate("Buy-Line", OBJ_HLINE, 0, 0, drop_price);



//P1 = drop_price;


ObjectCreate("vline", OBJ_TREND, 0,0,0); // Creation of an object


// ObjectCreate("Sell-Line", OBJ_HLINE, 0,0,0);
ObjectCreate("Fucn-D", OBJ_LABEL, 0, "Times New Roman",Red);
// ObjectCreate("Buy-Line", OBJ_HLINE, 0,0,0);



// ----------------------------------------------------- end Create

// --------------------------------------------Set Object Properties


ObjectSet("vline",OBJPROP_COLOR,Yellow); //Vertical
ObjectSet("vline",OBJPROP_WIDTH,2);
ObjectSet("vline",OBJPROP_STYLE,STYLE_SOLID);

ObjectSet("Sell-Line",OBJPROP_COLOR,Red); // Sell line
ObjectSet("Sell-Line",OBJPROP_WIDTH,2);
ObjectSet("Sell-Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectSet("Buy-Line",OBJPROP_COLOR,Green); // Buy Line
ObjectSet("Buy-Line",OBJPROP_WIDTH,2);
ObjectSet("Buy-Line",OBJPROP_STYLE,STYLE_SOLID);


P4 = ObjectGet("Sell-Line", OBJPROP_PRICE1);

if (P1 != P4)
{
ObjectSet("Sell-Line", OBJ_HLINE, P1); }
else {
ObjectSet("Sell-Line", OBJ_HLINE, P4);
}


ObjectSet("Fucn-D", OBJPROP_XDISTANCE, 150); // Label Horizontl
ObjectSet("Fucn-D", OBJPROP_YDISTANCE, 100); // Vertical



ObjectSet("Buy-Line", OBJ_HLINE, P2);


// P1 = ObjectGet("Sell-Line", OBJPROP_PRICE1); //Vertical
// P2 = ObjectGet("Buy-Line", OBJPROP_PRICE2);

T1 = ObjectGet("vline", OBJPROP_TIME1);
T2 = ObjectGet("vline", OBJPROP_TIME2);
T1 = Time[150];
T2 = Time[130];



Pft = MathAbs(P4);
ObjectSetText("Fucn-D", DoubleToStr(P1,Digits)+" "+ DoubleToStr(P4,Digits), 0, "Times New Roman",Red);

P3 = ObjectGet("Buy-Line", OBJPROP_PRICE1);// B-S difference
P4 = ObjectGet("Sell-Line", OBJPROP_PRICE1);

ObjectSet("vline", OBJPROP_RAY, 0);
ObjectSet("vline", OBJPROP_PRICE1, P1);
ObjectSet("vline", OBJPROP_PRICE2, P2);
ObjectSet("vline", OBJPROP_TIME1, T1);
ObjectSet("vline", OBJPROP_TIME2, T2);

// ObjectMove("Buy-Line", 2, T2, P3);

// WindowRedraw();

//--------------------------------------------------------------------
return(0); // Exit the special funct. start()
}
//--------------------------------------------------------------------


// bool ObjectCreate( string name, int type, int window, datetime time1, double price1, datetime time2=0, double price2=0, datetime time3=0, double price3=0)
// bool ObjectSet( string name, int index, double value << the new value to set index to)
// index to = OBJPROP_PRICE1

// bool ObjectMove( string name, int point, datetime time1, double price1)

Reason: