Experts: Expert Ichimoku - page 2

 

Remark: if you are using instruments with a HUGE spread, you must set an appropriate Stop Loss.

Always remember - there are TWO prices: Ask and Bid.

 
Vladimir Karputov #:

You see your mistake - think: what value of risk are you setting?

Thanks for your response. every thing is correct in expert. problems are due to insufficient balance and incorrect SL due to hug spread.

  I set 1% risk for 500$ Balance. leverage set to 100. these errors apears:

OpenBuy, ERROR: method CheckOpenLong 

OpenSell, ERROR: method CheckOpenShort

it means this balance is not sufficient for opening position with minimum lot size in BTC?

is it true ?

 
amin ghanbari # :

Thanks for your response. every thing is correct in expert. problems are due to insufficient balance and  incorrect SL due to hug spread .

  I set 1% risk for 500$ Balance. leverage set to 100. these errors apears:

OpenBuy, ERROR: method CheckOpenLong  

OpenSell, ERROR: method CheckOpenShort

it means this balance is not sufficient for opening position with minimum lot size in BTC?

is it true ?

You found your mistake. Now think about how you can correct your mistake.

 

Hello, Vladimir

Thank you for sharing the expert, I am trying to add a condition for closing the position when the bar close pass the cloud , that is the code I added, can you help me out, please,  I am very new to mql5


 
Mahmoud Ahmed Mahmoud Fahmy # :

Hello, Vladimir

Thank you for sharing the expert, I am trying to add a condition for closing the position when the bar close pass the cloud , that is the code I added, can you help me out, please,  I am very new to mql5


Please insert the code correctly:  FIRST press the button  Code, and THEN paste the code in the pop-up window.

 
Vladimir Karputov #:

Please insert the code correctly:  FIRST press the button  , and THEN paste the code in the pop-up window.

Hello, again 

Thank you very much for responding , and I am very sorry for the mess I did , I changed the code a little from my last post , and It still does not close position , and I set stoploss = 0

   double Kij2=iIchimokuGet(KIJUNSEN_LINE,3);
   double SpanA2=iIchimokuGet(SENKOUSPANA_LINE,3);
   double SpanB2=iIchimokuGet(SENKOUSPANB_LINE,3);
   double Chinkou2=iIchimokuGet(CHIKOUSPAN_LINE,3);
   
   
   //closing  orders
   
  
   
   
  // m_trade.PositionClose(m_symbol.Name());
   //buy orders
  // {
      
     // if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY )
     // {
        // if(iClose(_Symbol,Period(),1) < SpanB)
       //  {
            //m_trade.PositionClose(_Symbol);
          //  }
            
     // }    
     // }
      
      //SELL ORDERS
      
     // if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
     // {
         
       // if(iClose(_Symbol,Period(),1) > SpanB)
        // {
         //   m_trade.PositionClose(_Symbol);
         //}
      // }
            
          //  if(m_trade.ResultRetcode()==10008 || m_trade.ResultRetcode()==10009) //Request is completed or order placed
             //  {
             //  Print("Exit rules: A close order has been successfully placed with Ticket#: ",m_trade.ResultOrder());
             //  }
            //else
              // {
              // Print("Exit rules: The close order request could not be completed.Error: ",GetLastError());
             //  ResetLastError();
               //return;
              // }
            
        // }
    //  }
  // }
   
   
//--- check BUY
      if (iClose(_Symbol,PERIOD_D1,1) < iClose(_Symbol,PERIOD_D1,2) && iHigh(_Symbol,PERIOD_H4,2) - iLow(_Symbol,PERIOD_H4,2) > iHigh(_Symbol,PERIOD_H4,1)- iLow(_Symbol,PERIOD_H4,2) )
      {  

      if (iOpen(m_symbol.Name(),Period(),0) > Kij && iOpen(m_symbol.Name(),Period(),0) > SpanA)
  // if(Ten1<=Kij1 && Ten>Kij &&
   //&& m_symbol.Ask()>SpanA1 
   //&& m_symbol.Ask()>SpanB1 && 
     // iOpen(m_symbol.Name(),Period(),1)<iClose(m_symbol.Name(),Period(),1)) //|| 
      //(Chinkou1<=iClose(m_symbol.Name(),Period(),11) && Chinkou>iClose(m_symbol.Name(),Period(),10) && 
     // m_symbol.Ask()>SpanA1 && m_symbol.Ask()>SpanB1 && 
     // iOpen(m_symbol.Name(),Period(),1)<iClose(m_symbol.Name(),Period(),1))
     {
      double sl=(InpStopLoss==0)?0.0:m_symbol.Ask()-ExtStopLoss;
      if(sl>=m_symbol.Bid()) // incident: the position isn't opened yet, and has to be already closed
        {
         PrevBars=0;
         return;
        }
      double tp=(InpTakeProfit==0)?0.0:m_symbol.Ask()+ExtTakeProfit;
           if(iClose(_Symbol,Period(),1) < SpanB)
   {
      if(m_position.Select(_Symbol))                     //if the position for this symbol already exists
        {
         if(m_position.PositionType()==POSITION_TYPE_BUY) m_trade.PositionClose(_Symbol);   //and this is a Buy position, then close it
        // if(m_Position.PositionType()==POSITION_TYPE_SELL) return;
         }
   }
      
      OpenBuy(sl,tp);
     }
     }
     
//--- check SELL
         
     if (iClose(_Symbol,PERIOD_D1,1) > iClose(_Symbol,PERIOD_D1,2) && iHigh(_Symbol,PERIOD_D1,2) - iLow(_Symbol,PERIOD_H4,2) > iHigh(_Symbol,PERIOD_H4,1)- iLow(_Symbol,PERIOD_H4,2) )
      {
 
      if(iOpen(m_symbol.Name(),Period(),0) < Kij && iOpen(m_symbol.Name(),Period(),0) < SpanB)
        
         
        
  // if(Ten1>Kij1 && Ten<Kij &&
   //&& m_symbol.Bid()<SpanA1 && m_symbol.Bid()<SpanB1 && 
     // iOpen(m_symbol.Name(),Period(),1)>iClose(m_symbol.Name(),Period(),1)) //|| 
      //(Chinkou1>=iOpen(m_symbol.Name(),Period(),11) && Chinkou<iOpen(m_symbol.Name(),Period(),10) && 
      //m_symbol.Bid()<SpanA1 && m_symbol.Bid()<SpanB1 && 
      //iOpen(m_symbol.Name(),Period(),1)>iClose(m_symbol.Name(),Period(),1)))
     {
      double sl=(InpStopLoss==0)?0.0:m_symbol.Bid()+ExtStopLoss;
      if(sl<=m_symbol.Ask()) // incident: the position isn't opened yet, and has to be already closed
        {
         PrevBars=0;
         return;
        }
      double tp=(InpTakeProfit==0)?0.0:m_symbol.Bid()-ExtTakeProfit;
      
         if(iClose(_Symbol,Period(),1) > SpanB)
         {
            if(m_position.Select(_Symbol))                     //if the position for this symbol already exists
            {
               if(m_position.PositionType()==POSITION_TYPE_SELL) m_trade.PositionClose(_Symbol);   //and this is a Buy position, then close it
        // if(m_Position.PositionType()==POSITION_TYPE_SELL) return;
            }
         }
      
      OpenSell(sl,tp);
     }
    } 
    // m_trade.PositionClose(_Symbol);
  }
  
 

Hello, Vladimir

I finally figured out why it was not closing the positions and it was in the max position return, thank you for sharing the expert, and I hope that you help out if I needed your help in coding in the future

and let me tell the outcome of the change was not impressive