When ClosePrice comes within 400 points of 648200.00 place order, but it needs to place a order when it comes close to 638200, 648200, 658200 etc.
I don't need someone to code it for me, but just point me in the right direction please.
:-) dont judge my coding.
// import Trade Library#include<Trade\Trade.mqh>
//Create an instance of the Ctrade called trade
CTrade trade;
voidOnTick()
{
double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //get Ask pricedouble Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //get Bid pricedouble Balance=AccountInfoDouble(ACCOUNT_BALANCE); //get account balancedouble Equity=AccountInfoDouble(ACCOUNT_EQUITY); //get account equitydouble ClosePrice = iClose(_Symbol,PERIOD_CURRENT,1); //last candle close pricedouble LS = 8500;double LE = 1298200;
double BuyDif = (LS - ClosePrice); //get the var in price for last candle close vs lines double SellDif = (ClosePrice - LS); //get the var in price for last candle close vs linfor(LS;ClosePrice<=LE;LS=LS+10000)
{
Print("Price is ",LS);
Print("BuyDiff :",BuyDif);
if (PositionsTotal()==0) //no open positionsif (BuyDif >= 0 && BuyDif <= 400.00)
trade.Buy(0.002,NULL,Ask,(Ask-1000),0,NULL);
if (PositionsTotal()==0) //no open positionsif (SellDif >= 0 && SellDif <= 400.00)
trade.Sell(0.002,NULL,Bid,(Bid+1000),0,NULL);
break;
// set a trailing stop
CheckBuyTrailingStop(Ask);
}
}
///////////////////////////////////////////////////////////////////////////////////Buy Trailing Stopvoid CheckBuyTrailingStop(double Ask)
{
//set the stoploss to 150 pointsdouble SL=NormalizeDouble(Ask-1000,_Digits);
//go through all positionsfor(int i=PositionsTotal()-1; i>=0; i--)
{
string symbol=PositionGetSymbol(i); //get the symbol of the positionif (_Symbol==symbol) //if currency pair is equalif (PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_BUY) //if its a Buy Order
{
//get the ticket numberulong PositionTicket=PositionGetInteger(POSITION_TICKET);
//calculate the current stoplossdouble CurrentBuyStopLoss=PositionGetDouble(POSITION_SL);
if (CurrentBuyStopLoss<SL)
{
//move the stoploss
trade.PositionModify(PositionTicket,(CurrentBuyStopLoss+50),0);
}
} //end if loop
} //end for loopdouble Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //get Bid price// set a trailing stop
CheckSellTrailingStop(Bid);
}
///////////////////////////////////////////////////////////////////////////////////Sell Trailing Stopvoid CheckSellTrailingStop(double Bid)
{
//set the stoploss to 150 pointsdouble SL=NormalizeDouble(Bid+1000,_Digits);
//go through all positionsfor(int i=PositionsTotal()-1; i>=0; i--)
{
string symbol=PositionGetSymbol(i); //get the symbol of the positionif (_Symbol==symbol) //if currency pair is equalif (PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_SELL) //if its a Sell Order
{
//get the ticket numberulong PositionTicket=PositionGetInteger(POSITION_TICKET);
//calculate the current stoplossdouble CurrentSellStopLoss=PositionGetDouble(POSITION_SL);
if (CurrentSellStopLoss>SL)
{
//move the stoploss
trade.PositionModify(PositionTicket,(CurrentSellStopLoss-50),0);
}
} //end if loop
} //end for loop
} //end
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi
I'm stuck. I want my EA to place a order at a certain price level ( when price is close to multiple price points )
Example
double ClosePrice = iClose(_Symbol,PERIOD_CURRENT,1);
ClosePrice is curretly at 642882.51
When ClosePrice comes within 400 points of 648200.00 place order, but it needs to place a order when it comes close to 638200, 648200, 658200 etc.
I don't need someone to code it for me, but just point me in the right direction please.
:-) dont judge my coding.