Disliked{quote} The && (AND) and || (OR) separate conditions. The conditions inside have to evaluate to true based on whatever you put in there. So saying open&&close does not add them together, it is two separate conditions.Ignored
ok here is the latest;
I added few more conditions and I checked it, it seems to work fine.
Condition 1 determines if the range is at least twice the body
Condition 2 determines if the body is located either at top 3rd or bottom 3rd of the range.
condition 3 determines if bar 3 and bar 2(pinbar) are opposite directions(e.g. I want to see a decline of at least 1 bar before a bullish pinbar)
condition 4 determines if bar 2(pinbar) and bar 1(last closed bar) are in the same direction.
+----------------------------------------------------------------------------------------------------------------------
//+------------------------------------------------------------------+
//| pinbardetector.mq4 |
//| halil |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "halil"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//Declare variables
double range;
double body;
double range3rd;
bool condition1;
bool condition2;
bool condition3;
bool condition4;
bool bar3;
bool bar1;
//Show Candle values
//-------------------------------------------------------------------------------------------
Alert("");
Alert("");
Alert("Open "+DoubleToStr(Open[2],Digits-1)+" Close "+DoubleToStr(Close[2],Digits-1)+" High "+DoubleToStr(High[2],Digits-1)+" Low "+DoubleToStr(Low[2],Digits-1 ));
//-------------------------------------------------------------------------------------------
//Find the range of the candle
range=High[2]-Low[2];
Alert("Range = " +DoubleToStr(range,Digits-1));
//----------------------------------------------------------------------------------------------
//Find the body of the candle
body=Open[2]>Close[2]?Open[2]-Close[2]:Close[2]-Open[2];
Alert("body = "+DoubleToStr(body,Digits-1));
//--------------------------------------------------------------------------------------------
//Find If Range is greater than or equal to 2 times the body size:THIS DETERMINES CONDITION 1
condition1=range>=2*body?true:false;
Alert("CONDITION1 IS : "+condition1);
//-----------------------------------------------------------------------------------------------
//Find if Body is Located either at top third or bottom third of the range:THIS DETERMINES CONDITION 2
//First determine the value for 1 third of the range
range3rd=range/3;
Alert("One third of the range= "+range3rd);
//Use range3rd value to figure out if body is on top third or bottom third
if(Open[2]>High[2]-range3rd && Close[2]>High[2]-range3rd || Open[2]<Low[2]+range3rd && Close[2]<Low[2]+range3rd)
{
condition2=true;
Alert("CONDITION2 IS : "+condition2);
}
else
{
condition2=false;
Alert("CONDITION2 IS : "+condition2);
}
//---------------------------------------------------------------------------------
//Find if bar 3 and bar 2(pinbar) are opposite direction(for bullish pinbar we need bar 3(previous bar) to be bearish(decline):THIS DETERMINES CONDITION 3
condition3=Open[3]>Close[3] && Open[2]>Close[2] || Open[3]<Close[3] && Open[2]<Close[2]?false:true;
Alert("CONDITION3 IS : "+condition3);
//Find if bar bar 2(pinbar) and bar 1(last closed bar) are in the same direction:THIS DETERMINES CONDITION 4
condition4=Open[2]>Close[2] && Open[1]>Close[1] || Open[2]<Close[2] && Open[1]<Close[1]?true:false;
Alert("CONDITION4 IS : "+condition4);
}