object get making a trendline break

 

hi i have been trying to adapt this code to my ea


so I have got it to find a trend line drawn by me on the chart

no it not my code just my adaption of the code


the function works and produces the desired result


however i can figure out how to get the result out of the function

that is i cant get it to where i can use hte information elswhere in the ea

any suggestions would be most appreciated

Thanks

//+------------------------------------------------------------------+
//|                                              trend-line-test.mq4 |
//|                                      Copyright © 2011, Ron Kirby |
//|                                            http://www.blsmur.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Ron Kirby"
#property link      "http://www.blsmur.com"
   // these are all externs so they can be changed when the EA is attached to a chart
// the values set are default values
extern int stoploss=0;
extern int takeprofit=0;
extern double lots = 0.01;
extern int magic_number=12345;

int  iRetTlBreak =0;

extern string trendline_name ="t6";
extern int trendline_type=0;  // 0=upper, 1=lower
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+



int start()
{
   
  
      
   // call the i have used other ideas to  get the functin to work  this gets it work but i cant get an output 
int testsignal = (fnGetTrendLineSignal(trendline_name, trendline_type) );
  
 //  if (fnGetTrendLineSignal(trendline_name, trendline_type) == 1)
 // Print ("value = ",value,"m = ",m,"type = ",type); 
return(0);


}



int fnGetTrendLineSignal(string strName, int type)//string strName, int type
{  int    iRetTlBreak = 0;
   // get the four coordinates
   double x1 = ObjectGet( strName, OBJPROP_TIME1);
   Print ("x1 = ",x1);
   double y1 = ObjectGet( strName, OBJPROP_PRICE1);
   double x2 = ObjectGet( strName, OBJPROP_TIME2);
   double y2 = ObjectGet( strName, OBJPROP_PRICE2);
   Print ("y1 = ",y1);
   // calculate the slope of the line (m)
   double m = (y2-y1)/(x2-x1);
   Print ("m = ",m);
   // calcualte the offset (b)
   double b = y1 -m*x1;
   
   // get the current x value
   double time = TimeCurrent();
   
   // calculate the value (y) of the projected trendline at (x): y = mx + b
   double value = m*time + b;
  //  Print ("value = ",value,"m = ",m,"type = ",type);
   // if type is an upper trend line (line is above price points)
   
   
      if( type == 0 )// Print ("type = ",type);
      if( Bid > value )iRetTlBreak = 2;
        
   if( type == 1 )// Print ("type = ",type);
   
      // price has broken the trendline
      // the ask price is lower than the projected value
      if( Ask < value )iRetTlBreak = 1;
         
   
Print ("iRetTlBreak = ",iRetTlBreak);
   return(iRetTlBreak);
}



//----
 
//+--------------------------------------------------
Files:
 

The value that is returned by the function you are calling is iRetTlBreak . . .

So do this . . .

int testsignal = fnGetTrendLineSignal(trendline_name, trendline_type);

then testsignal will have the value that the function returned, i.e. iRetTlBreak

Add this line after the function call . . .

Print ("testsignal = ",testsignal);

And you will see that iRetTlBreak and testsignal have the same value.

 
RaptorUK:

The value that is returned by the function you are calling is iRetTlBreak . . .

So do this . . .

then testsignal will have the value that the function returned, i.e. iRetTlBreak

Add this line after the function call . . .

And you will see that iRetTlBreak and testsignal have the same value.


hi there Raptor

i have tried that before and no result

here is what I have tried right now and it does not print for me so

you will see that the "testsignal" does not appear in the journal

am I missing something ?

iRetTlBreak is printing fine and is working fine

but nothing from the testsignal print statement

  // call the i have used other ideas to  get the functin to work  this gets it work but i cant get an output 
int testsignal = fnGetTrendLineSignal(trendline_name, trendline_type);
  Print ("testsignal = ",testsignal); 
 //  if (fnGetTrendLineSignal(trendline_name, trendline_type) == 1)
 // 
return(0);
 
Tradingjunky:

am I missing something ?

iRetTlBreak is printing fine and is working fine

but nothing from the testsignal print statement

You did something wrong . . . .

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: testsignal = 0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: iRetTlBreak = 0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: m = -0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: y1 = 161.0374

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: x1 = 1203519600

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: testsignal = 0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: iRetTlBreak = 0

 
RaptorUK:

You did something wrong . . . .

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: testsignal = 0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: iRetTlBreak = 0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: m = -0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: y1 = 161.0374

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: x1 = 1203519600

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: testsignal = 0

2011.12.05 09:10:21 2008.03.03 03:24 trend-line-test EURJPY,H1: iRetTlBreak = 0

 

I got it to print on a live account

but it still not show in the tester ?

 
Tradingjunky:

I got it to print on a live account

but it still not show in the tester ?

Yes it is . . . I ran it in the Strategy Tester
 
RaptorUK:
Yes it is . . . I ran it in the Strategy Tester
 

this is the result from my test jpeg attached

is there anything else you changed besides what you posted

Thanks

 
Tradingjunky:

this is the result from my test jpeg attached

is there anything else you changed besides what you posted

Nope . . . are you sure you are running the modified EA ? add another Print ( Print("Moded EA"); ) just after the Print in the function so you know you are using the modified EA . . .
 

my code works too:


int checkTrendBreak(int type,double bid,double ask)//type 0==downtrend (above candles) and type 1==uptrend (below candles)
{
   datetime date1 =D'12.01.2024 20:00:00'; 
   datetime date2 =D'18.01.2024 16:00:00';
   double price1 = 0.67422;
   double price2 = 0.65190;   
   int    iRetTlBreak = 0;   
   double x1 = (double)date1;
   double y1 = price1;
   double x2 = (double)date2;
   double y2 = price2;
   // calculate the slope of the line (m)
   double m = (y2-y1)/(x2-x1);   
   // calcualte the offset (b)
   double b = y1 -m*x1;   
   // get the current x value
   double time = TimeCurrent();
   // calculate the value (y) of the projected trendline at (x): y = mx + b
   double value = m*time + b;   
    if( type == 0 )// Print ("type = ",type);
      if( bid > value )iRetTlBreak = 2;        
   if( type == 1 )// Print ("type = ",type);     
      if( ask < value )iRetTlBreak = 1;   
return iRetTlBreak;
}