0
votes

I'm new to mql4 and am confused with the basics. I want to prepare an exit strategy. Here are the conditions. If it's a buy trade and we have to sell for closing the order:

  1. The candle should give a close below the Supertrend.
  2. Next candle should cut the low of the previous candle.

Below is the part of the code I've prepared.

i=1;
if (Close[i]<st)
{
    low=close[1];
    a=checkt1();
    if (a==True)
    {
        OrderClose()
     }
}
else if(Close[i]>st)
    {
    return(EMPTY_VALUE);
    }

bool check1t()
{
    if (Ask<a && Bid<a)
        {
        CloseOrder();
        }
return True
}

Here the value of close keeps changing as I have set it to close[1]. Is there any function or any way that can store the value of close of the candle that had cut supertrend only? And not take up any other values?

1

1 Answers

0
votes

so you need to check that previous candle is below the one before, and that candle before closed below the indicator.

`void Check4closeBuy(){
   double low1 = iLow(_Symbol,0,1), low2 = iLow(_Symbol,0,2), 
   close2 = iClose(_Symbol,0,2), ind2 = iCustom(_Symbol,0,ind_name,***,buffer,2);

   if (ind2>close2 && low2>low1){
      //close here
   }
}`

about comparing doubles - since they are doubles not integers it is better to compare the difference below half-tick or something like that, but need to be careful with that. so in basic case: double1>double2 -> double1-double2>Point/2 but it depends on your indicator, it can have _Digits or more (like different MA may have more digits after dot then just 5).