Need help fixing a code

 

Hi,

Just a quick one, I am trying to develop an EA just to receive alerts when the current candle closes above or bellow the object created.

Here is the code I am using:

 

int LowestCandle=iLowest(_Symbol,_Period,MODE_LOW,100,10);

int HighestCandle=iHighest(_Symbol,_Period,MODE_HIGH,100,10);

ObjectDelete("LLINE");

 ObjectCreate("LLINE",OBJ_HLINE,0,Time[0],Low[LowestCandle]);

 ObjectDelete("HLINE");

 ObjectCreate("HLINE",OBJ_HLINE,0,Time[0],High[HighestCandle]);

 double LineValHigh=NormalizeDouble(ObjectGetValueByShift("HLINE",10),Digits);

 double LineValLow=NormalizeDouble(ObjectGetValueByShift("LLINE",10),Digits);

if(Close[1]<LineValHigh && Close[0]>LineValHigh)

         {

         Comment("Buy");

   }

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

Comment("Sell");}

}


Am I doing something wrong?

It defenitely doesnt work as I expected.

I would appreciate some help.


Thanks in advance.

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.

Thank  you very much.

sorry about that.

 
Wilailak Worabuth:

Hi,

Just a quick one, I am trying to develop an EA just to receive alerts when the current candle closes above or bellow the object created.

Here is the code I am using:

 


Am I doing something wrong?

It defenitely doesnt work as I expected.

I would appreciate some help.


Thanks in advance.

bool NewBar()
  {
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
     {
      lastbar=curbar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
void OnTick()
  {
//---
   int LowestCandle=iLowest(_Symbol,_Period,MODE_LOW,100,10);

int HighestCandle=iHighest(_Symbol,_Period,MODE_HIGH,100,10);

ObjectDelete("LLINE");

 ObjectCreate("LLINE",OBJ_HLINE,0,Time[0],Low[LowestCandle]);

 ObjectDelete("HLINE");

 ObjectCreate("HLINE",OBJ_HLINE,0,Time[0],High[HighestCandle]);

 double LineValHigh=NormalizeDouble(ObjectGetValueByShift("HLINE",10),Digits);

 double LineValLow=NormalizeDouble(ObjectGetValueByShift("LLINE",10),Digits);

if(Close[1]<LineValHigh && Close[0]>LineValHigh && NewBar())

         {

         Comment("Buy");

   }

if(Close[1]>LineValLow && Close[0]<LineValLow && NewBar()){

Comment("Sell");}

}
 
 
Mehmet Bastem

Thanks for your help, but the code still not working I tried one milion ways already.

Do you know a better to code the if statement?


Thanks in advance.

 
Wilailak Worabuth:

Thanks for your help, but the code still not working I tried one milion ways already.

Do you know a better to code the if statement?


Thanks in advance.

double LineValHigh=NormalizeDouble(ObjectGetValueByShift("HLINE",10),Digits);

 double LineValLow=NormalizeDouble(ObjectGetValueByShift("LLINE",10),Digits);

These codes are incorrect. As a result, it generates a zero value.

I made an example like this here.

https://www.mql5.com/en/forum/365846#comment_21553431

Newly edited codes will be like this. Screenshot attached.

ssa
//+------------------------------------------------------------------+
//|                                                           es.mq4 |
//|                                        Copyright 2021, HaskayaFx |
//|                                   https://www.haskayayazilim.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, HaskayaFx"
#property link      "https://www.haskayayazilim.net"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

bool NewBar()
  {
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
     {
      lastbar=curbar;
      return (true);
     }
   else
     {
      return(false);
     }
  }
void OnTick()
  {
//---
   int LowestCandle=iLowest(_Symbol,_Period,MODE_LOW,100,10);

int HighestCandle=iHighest(_Symbol,_Period,MODE_HIGH,100,10);

ObjectDelete("LLINE");

 ObjectCreate("LLINE",OBJ_HLINE,0,Time[0],Low[LowestCandle]);

 ObjectDelete("HLINE");

 ObjectCreate("HLINE",OBJ_HLINE,0,Time[0],High[HighestCandle]);

 double LineValHigh=NormalizeDouble(ObjectGetValueByShift("HLINE",10),Digits);

 double LineValLow=NormalizeDouble(ObjectGetValueByShift("LLINE",10),Digits);

         string obj_name="HLINE"; 
         double obj_Price=NormalizeDouble(ObjectGet(obj_name, OBJPROP_PRICE1),Digits);
        //  Print(obj_Price," High ");
       
        
        if(Ask>obj_Price && Open[1] <obj_Price)
        {
         Alert(Symbol()+" TF:"+string(Period())+" Close Above on Obj_Line SELL AT:"+string(NormalizeDouble(Ask,Digits)));
         Comment("SELL At"+string(NormalizeDouble(Ask,Digits)));
         // Open Buy Orders Code
        // ObjectDelete(obj_name);
        }
        RefreshRates();
          obj_name="LLINE"; 
          obj_Price=NormalizeDouble(ObjectGet(obj_name, OBJPROP_PRICE1),Digits);
         // Print(obj_Price," Low ");
      //  Print(Ask," ",obj_Price," ",Open[1]);
        
        if(Ask<=obj_Price)
        // && Open[0]>=obj_Price)
        {
         Alert(Symbol()+" TF:"+string(Period())+" Close  Below on Obj_Line BUY AT:"+string(NormalizeDouble(Ask,Digits)));
         Comment("BUY AT"+string(NormalizeDouble(Ask,Digits)));
         //OPen Sell Orders
         //ObjectDelete(obj_name);
        }

if(Close[1]<LineValHigh && Close[0]>LineValHigh && NewBar())

         {

         Comment("Buy");

   }

if(Close[1]>LineValLow && Close[0]<LineValLow && NewBar()){

Comment("Sell");}

}
 
//+------------------------------------------------------------------+

mql4 trade in trend line that i draw
mql4 trade in trend line that i draw
  • 2021.03.27
  • www.mql5.com
hi there, im new in mql4 1_i want drew trend lines in deffrent H1 charts manual, and i want set order on trend line( i should find price bellow or...
Reason: