Is there any Funtion that tell me when a candle close if it was bearish or bullish?
Thank you very much for the Mql's functions
Now I have coded an EA, but it seems that it gets stuck or probably there is something not coded right. Those are the rules that the price have to comply before opening:
1) the breaking candle has to be bearish.
2)the closing price of the breaking candle has to be less than the support price.
3) Finally, before opening the selling order make sure that the new candle starts with a price less than the supporting price.
//+------------------------------------------------------------------+ //| aldus_DownTrend.mq4 | //| By Aldus | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "By Aldus" #property link "http://www.metaquotes.net" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ //-------------------------------------------------------------------- extern double Breakout = 1.3000; // External variable this is the support price level extern int SL = 3000; // External variable Stop loss extern int TP = 150; // External variable TP extern double Lot= 0.07; // External variable bool Fact_1 = false; // Global variable bool Fact_3 = false; int Magic_aldus=99992; // Global variable string comment= "ordine short"; // Global variable //-------------------------------------------------------------------- int init() { Comment("Downtrend aldus"); return(0); } //-------------------------------------------------------------------- int start() { double Price = Ask; // Local variable static int FirstBar, SecondBar, ThirdBar; // Local variables for checking the change of candles if (Fact_3==true) // If there was an Alert.. return(0); //..exit if (NormalizeDouble(Price,Digits) <= NormalizeDouble(Breakout,Digits)) {Fact_1 = true; // Event 1 happened RefreshRates(); FirstBar=Bars; Comment("Breakout occurred at n Bar "+FirstBar); } if (Fact_1 == true && Bars>FirstBar) { SecondBar=Bars; RefreshRates(); Comment("Opened new candle :"+SecondBar); if(Close[FirstBar]<Open[FirstBar]&& NormalizeDouble(Breakout,Digits)>Close[FirstBar]) { Comment("closing price "+Close[FirstBar]+"open price "+Open[FirstBar]+" first candle "+FirstBar); if(NormalizeDouble(Price,Digits) <= NormalizeDouble(Breakout,Digits)) { My_Alert(SecondBar); // User-defined function call open transaction } } } return(0); // Exit start() } //+------------------------------------------------------------------+ //-------------------------------------------------------------------- void My_Alert(int numbars) // User-defined function { OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, Bid+SL*Point, Bid-TP*Point, comment,Magic_aldus, 0, Red); Comment("Confirmation occurred, a Short order should be opened at Bar n "+numbars, (GetLastError())); // Alert SendMail("downtrend","order sell placed"); Fact_3 = true; // Event 2 happened return(0); // Exit user-defined function } //-------------------------------------------------------------------- int deinit() { return(0); }
Ok thank you.
So for instance let's make the downtrending case: What I want it's when the price break out a support price , before opening a sell order:
1) the candle has to be bearish.
2)the closing price of the breaking candle has to be less than the support price.
3) Finally, before opening the selling order make sure that the new candle starts with price less than the supportig price.
Here there is an expet, but I am not able to make it work with whole conditions:
<CODE DELETED>
Please read some other posts before posting . . .
Please edit your post . . . . please use the SRC button to post code: How to use the SRC button.
Sorry for not using SRC, I hope to find an answer into the previose posts, unfortunatelly I am not so good in programming MQL4
Why didn't you?He asked you nicely to: Please edit your post
- What are Function return values ? How do I use them ? - MQL4 forum
- Not adjusting for ECN brokers or 4/5 digit (slippage)
- I am not able to make it work with whole conditionsNo mind readers here. Put print statements in your code, including variable values, so you find out why!
Fact_1 = true; // Event 1 happened
Do you ever set it to false?
Sorry for not using SRC, I hope to find an answer into the previose posts, unfortunatelly I am not so good in programming MQL4
Why didn't you?He asked you nicely to: Please edit your post
- What are Function return values ? How do I use them ? - MQL4 forum
- Not adjusting for ECN brokers or 4/5 digit (slippage)
- I am not able to make it work with whole conditionsNo mind readers here. Put print statements in your code, including variable values, so you find out why!
- Do you ever set it to false?
1) Sorry I do connect through a mobile to internet and quite often the line drops while I am writing.
5) At the beginning when the variable are declared:
extern double Lot= 0.07; // External variable bool Fact_1 = false; // Global variable
bool Fact_1 = false; // Global variableThat means what once you set Fact_1 = true, it NEVER CHANGES AGAIN.
That means what once you set Fact_1 = true, it NEVER CHANGES AGAIN.
Yes, Fact_1=true, stores the information that the support line has been broken by the price.
Hi all,
I have changed my code and now is working, it opens the selling orders.
After many attempts I made it, but I had to change one important condition that I would like to implement again :-( the reason is it
assures me that the bearish candle when closes, the closing price is less than my fixed broken support line.
That condition assures me that the the break of the support is not a fake ( I want that the candle not only has to be bearish by creating a shadow but also has to be a full
and clear break of the support.)
below I copied my EA , under the code I highlited the condition that I commented and replaced with a simple one
//+------------------------------------------------------------------+ //| aldus_DownTrend.mq4 | //| By Aldus | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "By Aldus" #property link "http://www.metaquotes.net" //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ //-------------------------------------------------------------------- extern double Breakout = 1.3000; // External variable extern int SL = 3000; // External variable Stop loss extern int TP = 150; // External variable TP extern double Lot= 0.07; // External variable bool Fact_1 = false; // Global variable bool Fact_2 = false; bool Fact_3 = false; int Magic_aldus=99992; // Global variable string comment= "ordine short"; // Global variable //-------------------------------------------------------------------- int init() { Comment("Downtrend aldus"); return(0); } //-------------------------------------------------------------------- int start() { double Price = Ask; double Apertura, Chiusura; // Local variable static int FirstBar, SecondBar, ThirdBar; // Local variables for checking the change of candles if (Fact_3==true) // If there was an Alert.. return(0); //..exit if (NormalizeDouble(Price,Digits) <= NormalizeDouble(Breakout,Digits)) {Fact_1 = true; // Event 1 happened //RefreshRates(); FirstBar=Bars; Print("Breakout occurred at n Bar "+FirstBar); } if (Fact_1 == true && Bars>FirstBar) { SecondBar=Bars; // RefreshRates(); Apertura=Open[FirstBar]; Chiusura=Close[FirstBar]; Comment("Opened new candle :"+SecondBar+ " Close "+Chiusura+" open "+Apertura+" Fact_1 "+Fact_1); // if(Chiusura<Apertura && NormalizeDouble(Breakout,Digits)>Chiusura) if(Chiusura<Apertura) { Fact_2=true; Comment("cand prima "+FirstBar+" cand dopo "+SecondBar+"fact_2 "+Fact_2); } else { // Fact_1=false; Comment(" fact_2 "+Fact_2); } } if(Fact_2 == true && NormalizeDouble(Price,Digits) <= NormalizeDouble(Breakout,Digits)) { My_Alert(SecondBar); // User-defined function call open transaction } // } it's positioned a bit upward return(0); // Exit start() } //+------------------------------------------------------------------+ //-------------------------------------------------------------------- void My_Alert(int numbars) // User-defined function { OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, Bid+SL*Point, Bid-TP*Point, comment,Magic_aldus, 0, Red); Comment("Confirmation occurred, a Short order should be opened at Bar n "+numbars, (GetLastError())); // Alert // Comment("prezzo di chiusura "+Close[FirstBar]+" prezzo apertura "+Open[FirstBar]+" cand prima "+FirstBar,(GetLastError())); SendMail("downtrend","order sell placed"); Fact_3 = true; // Event 2 happened return(0); // Exit user-defined function } //-------------------------------------------------------------------- int deinit() { //GlobalVariableDel(Fact_1); //GlobalVariableDel(Fact_2); //GlobalVariableDel(Magic_aldus); //GlobalVariableDel(comment); return(0); }
I wold like to ask you why is not working the commented condition I thought maybe is too long and needs to be managed into another inner If condition or because the variable called " ChiusIura" is used twice into the If statement
// if(Chiusura<Apertura && NormalizeDouble(Breakout,Digits)>Chiusura) // it assures that the bearish candle is not an hammer but a clear bearish candle if(Chiusura<Apertura)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there any Funtion that tell me when a candle close if it was bearish or bullish?
Thank you in advance
Aldo