order close when alert line crossed. help me!

 

hello,

im new to mql language and also almost new to programming.

i was found some source of line cross alert.

and i was add keyboard event to source to close my order.

so it should have to working when current candle crossed(Close[0]),it should have to be close order but this time

it just closed order when price line touch Alert line.

//------------------------------------------------------------------
//
//------------------------------------------------------------------
#property indicator_chart_window
#include <WinUser32.mqh>
extern string LineName        = "Line1";
extern color  LineColor       = Blue; 
extern int    LineStyle       = STYLE_DOT;
extern bool   alertsOn        = true;
extern bool   alertsOnCurrent = false;
extern bool   alertsMessage   = true;
extern bool   alertsSound     = false;
extern bool   alertsEmail     = false;

//------------------------------------------------------------------
//
//------------------------------------------------------------------

int init()   { return(0); }
int deinit() { return(0); }
int start()
{
   if (ObjectFind(LineName)==-1)
   {
      ObjectCreate(LineName, OBJ_TREND, 0, Time[100], Close[100], Time[0], Close[0]);
         ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
         ObjectSet(LineName, OBJPROP_COLOR, LineColor);
         ObjectSet(LineName, OBJPROP_WIDTH, 2);
   }
      
   //

      
   if (alertsOn)
   {   
      int testbar = 1; if (alertsOnCurrent) testbar = 0;
      double valc = ObjectGetValueByShift(LineName,testbar);
      double valp = ObjectGetValueByShift(LineName,testbar+1);
         
      //
      //

            
      if (Close[0]>valc && Close[1]<valp) 
      {
      

      //I use Ctrl+E to enable and disable the Expert Advisors, so the code is:

      keybd_event(17,0,0,0); // 17=Ctrl
      Sleep(10);
      keybd_event(69,0,0,0); // 69=E
      keybd_event(69,0,KEYEVENTF_KEYUP,0);
      keybd_event(17,0,KEYEVENTF_KEYUP,0);
      Sleep(30000);
  //    keybd_event(13,0,0,0);// enter
  //    Sleep(20000);
      doAlert(0," trend line crossed up");
      } return(0);
      
      if (Close[0]<valc && Close[1]>valp) 
      {
      keybd_event(17,0,0,0); // 17=Ctrl
      Sleep(10);
      keybd_event(69,0,0,0); // 69=E
      keybd_event(69,0,KEYEVENTF_KEYUP,0);
      keybd_event(17,0,KEYEVENTF_KEYUP,0);
      Sleep(30000);
 //     keybd_event(13,0,0,0);// enter
  //    Sleep(20000);
      
      
      
      
      doAlert(0," trend line crossed down");
      } return(0);
      
   }         
   return(0);
}



void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
   if (previousAlert != doWhat || previousTime != Time[forBar]) {
       previousAlert  = doWhat;
       previousTime   = Time[forBar];

       //


       message =  Symbol()+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" "+LineName+doWhat;
          if (alertsMessage) Alert(message);
          if (alertsEmail)   SendMail(Symbol()+"trendLine alerts",message);
          if (alertsSound)   PlaySound("alert2.wav");
   }
}

i was attached source . please help me!

thanks you!

 

or anyone who give me idea to make when price line crossed and alert?

thanks!

 

how can i check whether price line totally crossed or not?

i want to receive alert message when price line totally crossed

 
james27:

how can i check whether price line totally crossed or not?

i want to receive alert message when price line totally crossed


What do you mean by "totally crossed"?
 

hi!

i want to execute close order command when candle crossed what i drawed trend line. thanks in advance!


 
james27:

hi!

i want to execute close order command when candle crossed what i drawed trend line. thanks in advance!


You can use ObjectGetValueByShift() to get the value of the trend line for bar 1, you can then check the OHLC values of the bar to see if it is fully below the trend line.
 

hello admin!

if you don't mind would you some show me sample code or source?

im much new to mql language and struggle to learn but still much difficult!

anyway..thanks you!

 
james27:

hello admin!

if you don't mind would you some show me sample code or source?

im much new to mql language and struggle to learn but still much difficult!

anyway..thanks you!

I'm not Admin, just a volunteer Moderator . . .

You can find sample code here: ObjectGetValueByShift()

 

sorry but unfortunetly..i couldn't found any sample related with what i want..

i think this method is not using much that is why i couldn't found..if anyone know help pls..

thanks

 
james27:

sorry but unfortunetly..i couldn't found any sample related with what i want..

i think this method is not using much that is why i couldn't found..if anyone know help pls..

So you want someone else to write this code for you ?

Go here: Write mt mlq4 code for me

 
Listen, buddy, do you know that this site has a search capability? Do you also know that this site has a section called Codebase with many indicators sitting there waiting for you to download and start learning the language. Just do a search "trendline alert" and you will find so much interesting stuff for you to start working with. Or do you think it is easier to ask a question and beg for an answer. Ok this problem maybe solved, how about the next, and the next, and the one after that?
Reason: