Thank you very much.
sorry about that.
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");} }
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.
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.
//+------------------------------------------------------------------+ //| 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");} } //+------------------------------------------------------------------+
- 2021.03.27
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.