Problem to Open orders

 

Hi guys

I have problem to open order with my  expert to open order, what I am trying to do is to check if in the last 20 candle price was under the Resistance Level 1 (calculate by Pivot Points RL1).

After checking the candles I want to see the last candle high was above the RL1 and then close Below RL1, if this happen I want to open short order the TP should be the main Pivot Point and SL should be the same size of PIPS between the open price and the take profit.

Here is my code, Just start to write it and cannot understand why is not open order.

Thanks in advance.

E.

 

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

   // Calculating Pivot Points
   PivotPoint = (LastHigh + LastLow + LastClose)/3;
   RL1 = (2*PivotPoint)- LastLow;
   SL1 = (2*PivotPoint)- LastHigh;
   RL2 = (PivotPoint - SL1) + RL1;
   SL2 = PivotPoint - (RL1 - SL1);
   RL3 = (PivotPoint - SL2) + RL2;
   SL3 = PivotPoint - (RL2 - SL2);
   
   
   for (int i=1; i<=20; i++)
      {
         if(Close[i] < RL1)
            {
               if(High[1] > RL1 && Close[1] < RL1)
                  {
                     int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,5,0,PivotPoint,NULL,1111111,0,clrNONE);
                     ModifySL();
                  }
            }
      }                   
   return(0);
  }


int ModifySL()
   {
      double PIPs;
      double SL;
      int TickSLModify;
      
      for(int i=1; i<=OrdersTotal(); i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
               {
                  if (OrderSymbol() == Symbol())
                     {
                        if(OrderType() == OP_SELL)
                           {
                              PIPs = OrderOpenPrice() - OrderTakeProfit();
                              SL = OrderOpenPrice() + PIPs;
                              TickSLModify = OrderModify(i,OrderOpenPrice(),SL,OrderTakeProfit(),0,clrNONE);
                           }
                        if(OrderType() == OP_BUY)
                           {
                              PIPs = OrderTakeProfit() - OrderOpenPrice();
                              SL = OrderOpenPrice() - PIPs;
                              TickSLModify = OrderModify(i,OrderOpenPrice(),SL,OrderTakeProfit(),0,clrNONE);
                           }
                      }
                }
          }
   return(0);
   }  
 
vaknineyal: cannot understand why is not open order
  1. Run in under the debugger, or print out your variable values before and inside if statments and you will find out why.
  2. And had you checked your return codes, you would have found out. What are Function return values ? How do I use them ? - MQL4 forum
 

OK Thanks,

I saw all my value was 0 and I fix them that because I didn't setup the high low and close, but still not open position.

I think my problem is with  for loop is that loop looks OK  ? 

   for (int i=1; i<=20; i++)
      {
         if(Close[i] < RL1)
            {
               if(High[1] > RL1 && Close[1] < RL1)
                  {
                     int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,5,0,PivotPoint,NULL,1111111,0,clrNONE);
                     ModifySL();
                  }
            }
      }

 Is that OK to check the last 20 candles was under the pivot(RL1) and last one was high above and close below the pivot ?

   for (int i=1; i<=20; i++)
      {
         if(Close[i] < RL1)
            {
               if(High[1] > RL1 && Close[1] < RL1)
                  {
 
vaknineyal:

OK Thanks,

I saw all my value was 0 and I fix them that because I didn't setup the high low and close, but still not open position.

I think my problem is with  for loop is that loop looks OK  ? 

 Is that OK to check the last 20 candles was under the pivot(RL1) and last one was high above and close below the pivot ?

 


   for (int i=1; i<=20; i++)
      {
         if(Close[i] < RL1)
            {
               if(High[1] > RL1 && Close[1] < RL1)
                  {
                     int ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,5,0,PivotPoint,NULL,1111111,0,clrNONE);
                     ModifySL();
                  }
            }
      }

Check through you loop and you will see that it does NOT check that the last 20 bars were below the level

It checks the last 20 bars, 1 at a time and if that bar is below the level and the last closed bar meets the condition, the ordersend is called.

This single for loop, could possibly open 20 trades 

 
Thanks, so how should I check the last 20 bars ? 
 
vaknineyal: Thanks, so how should I check the last 20 bars ? 
Check all the bars then decide
bool isAllBelow = true
   for (int i=1; i<=20; i++)
      {
         if(Close[i] > RL1) isAllBelow = false
      }
if(isAllBelow 
 
Thanks A lot I will try it :)
Reason: