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
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, and THEN paste the code in the pop-up window.
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 BUYif (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 SELLif (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);
}
Enable code debugging and test step by step.
Thanks for your response.
I Do debugging and found that incorrect SL due to high spread caused this problem.
Thanks for your response.
I Do debugging and found that incorrect SL due to high spread caused this problem.
The code inside the Expert Advisor is correct - but if at the moment of placing the price makes a strong movement, the POSITION will not be opened.
The code inside the Expert Advisor is correct - but if at the moment of placing the price makes a strong movement, the POSITION will not be opened.
I think this section should modified for crypo:
When I use RISK for deteminig lot I see getpointer error and i have to use fix LOT:
***
When I use RISK for deteminig lot I see getpointer error and i have to use fix LOT:
You see your mistake - think: what value of risk are you setting?
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.
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 ?
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
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
, and THEN paste the code in the pop-up window.
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