Script / Function - Last Candle = buy candle or sell candle .

 

Hi everyone.


I don't know how to express my problem.


I managed to get the value of the last candle called LastCandleNb.


if it is >0 then bullish candle.

if <0 then bearish candle.

I can do it live.

if(LastCandleNb>0)

      Comment("Buy Candle");

   else

      Comment("Sell Candle");


But I would like to improve the function. to call it in the code more easily. like. (and make it a .mqh, if possible)


LastCandle = bullish candle or bearish candle


of course, depending on LastCandleNb < or > 0.


I just have to do

comment(LastCandle);

But impossible to find a formulation without error.


Thanks a lot.

 
NickoR:

Hi everyone.


I don't know how to express my problem.


I managed to get the value of the last candle called LastCandleNb.


if it is >0 then bullish candle.

if <0 then bearish candle.

I can do it live.


But I would like to improve the function. to call it in the code more easily. like. (and make it a .mqh, if possible)


LastCandle = bullish candle or bearish candle


of course, depending on LastCandleNb < or > 0.


I just have to do

But impossible to find a formulation without error.


Thanks a lot.


Before you get any answer, you have to inform us about the  LastCandleNb ?

what you mean by that " LastCandleNb "? is it a fixed variable, runtime value or a function which return a number... ?

otherwise, no one can understand what you want!

Adding screenshot(s) could help reader to give a good answer

 
Mohammed Abdulwadud Soubra #:


Before you get any answer, you have to inform us about the  LastCandleNb ?

what you mean by that " LastCandleNb "? is it a fixed variable, runtime value or a function which return a number... ?

otherwise, no one can understand what you want!

Adding screenshot(s) could help reader to give a good answer


Hello,

thank you Mohammed for your answer!

Yes of course, sorry, I hadn't thought about it

i use:

#define LastCandleNb iClose(_Symbol,PERIOD_CURRENT,1)-iOpen(_Symbol,PERIOD_CURRENT,1)
so I get a positive or negative value.


but this is probably not the right method, or the simplest one
 
NickoR #:


Hello,

thank you Mohammed for your answer!

Yes of course, sorry, I hadn't thought about it

i use:

so I get a positive or negative value.


but this is probably not the right method, or the simplest one

Hello you can define the candle number in the definition as well :

#define LastCandleNB(int) ((iClose(_Symbol,_Period,int)-iOpen(_Symbol,_Period,int))/_Point)>0.0?1:-1
/*
explanation
if the Close minus the Open at int location is bigger than 0 then return 1 otherwise -1
*/

Ternary Operator ?: - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:
Documentation on MQL5: Language Basics / Operators / Ternary Operator ?:
  • www.mql5.com
Ternary Operator ?: - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
NickoR #:


Hello,

thank you Mohammed for your answer!

Yes of course, sorry, I hadn't thought about it

i use:

so I get a positive or negative value.


but this is probably not the right method, or the simplest one
double  LastCandleNb= iClose(_Symbol,PERIOD_CURRENT,1)-iOpen(_Symbol,PERIOD_CURRENT,1);
 

Hello Lorentzos,

thank for your answers.

I didn't really understand why, but it's a great update! more clear..


Now, i have :

LastCandleNb = 1 or -1


But, can you direct me to,

I would like to have

LastCandle = BuyCandle / or / SellCandle.


in fact I want to call directly in my ea.

Comment(LastCandle)

and that it shows me

BuyCandle or SellCandle

 but I don't see how to have LastCandle with 2 possibilities.



thank you all for your help


 
Ahmet Metin Yilmaz #:
double  LastCandleNb= iClose(_Symbol,PERIOD_CURRENT,1)-iOpen(_Symbol,PERIOD_CURRENT,1);

Hello Ahmet.


thank you,

I tried, but I couldn't find it.

 
NickoR #:

Hello Lorentzos,

thank for your answers.

I didn't really understand why, but it's a great update! more clear..


Now, i have :


But, can you direct me to,

I would like to have

LastCandle = BuyCandle / or / SellCandle.


in fact I want to call directly in my ea.

and that it shows me

 but I don't see how to have LastCandle with 2 possibilities.



thank you all for your help


You can return a string in the ternary operator too , like this : 

#define LastCandleNB(int) (iClose(_Symbol,_Period,int)>=iOpen(_Symbol,_Period,int))?"BuyCandle":"SellCandle"

It checks is the Close >= Open ? if yes return BuyCandle if not return SellCandle

 
Lorentzos Roussos #:

You can return a string in the ternary operator too , like this : 

It checks is the Close >= Open ? if yes return BuyCandle if not return SellCandle

ohh yeah !


thank you, i will try this !!

 
NickoR #:

ohh yeah !


thank you, i will try this !!

Great !!!


all of a sudden, I was able to make good progress. thank you for everything

Reason: