Hello, i am newbie trying to write a EA based on signals given by QQE and I would like to trailstop the oppenned positions.
My EA seems to use iSar correctly when it modify a stop for a long position, but the on a short, the EA doesn't modify the stop (the code is similar !!).
Plus on the journal i got error 1 comming when EA is trying to modify the stops.
I have read all the topics about NormalyzeDouble, iSar, MACD sample and his trailing stop.
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed? if ((RsiMaCurrent < TrLevelSlowCurrent)&&(RsiMaPrevious > TrLevelSlowPrevious)) //////////these lines works doesn't work all the time !!! {
Print("CLOSE Current Signal 1 : ",RsiMaCurrent," Signal 2 : ",TrLevelSlowCurrent," Previous Signal 1 : ",RsiMaPrevious," Signal 2 : ",TrLevelSlowPrevious);
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit }
// Set Parabolic Stop, If Price > StopParabolic, The signal could be erlier than an parabolic signal, parabolic is valid // Already set StopLoss < StopParabolic then modify order, the StopLoss can never go in wrong direction if ((StopParabolic > OrderStopLoss()) && (Low[0] > StopParabolic + 10*Point) && (StopParabolic != OrderStopLoss())) //this one seems to work, but I get error 1
{
Print("(LONG) MODIFY STOP to Valeur Parabolic ", StopParabolic," Bid ",Bid);
OrderModify(OrderTicket(),OrderOpenPrice(),StopParabolic,OrderTakeProfit(),0,Green);
}
}
}
else // go to short position
{
// should it be closed? if ((RsiMaCurrent > TrLevelSlowCurrent)&&(RsiMaPrevious < TrLevelSlowPrevious)) //////////these lines works doesn't work all the time !!! {
Print("CLOSE Current Signal 1 : ",RsiMaCurrent," Signal 2 : ",TrLevelSlowCurrent," Previous Signal 1 : ",RsiMaPrevious," Signal 2 : ",TrLevelSlowPrevious);
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit }
//Parabolic same as long side if ((StopParabolic < OrderStopLoss()) && (High[0] < StopParabolic-10*Point)&& (StopParabolic != OrderStopLoss())) ////this one doesn't work at all
{
Print("(SHORT) MODIFY STOP to Valeur Parabolic ", StopParabolic," Ask ",Ask );
OrderModify(OrderTicket(),OrderOpenPrice(),StopParabolic,OrderTakeProfit(),0,Green);
return(0); }
}
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.
Hello, i am newbie trying to write a EA based on signals given by QQE and I would like to trailstop the oppenned positions.
My EA seems to use iSar correctly when it modify a stop for a long position, but the on a short, the EA doesn't modify the stop (the code is similar !!).
Plus on the journal i got error 1 comming when EA is trying to modify the stops.
I have read all the topics about NormalyzeDouble, iSar, MACD sample and his trailing stop.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
double RsiMaCurrent,TrLevelSlowCurrent,RsiMaPrevious, TrLevelSlowPrevious,StopParabolic;RsiMaCurrent=iCustom(NULL,0,"QQE",SF,0,1);
TrLevelSlowCurrent=iCustom(NULL,0,"QQE",SF,1,1);
RsiMaPrevious=iCustom(NULL,0,"QQE",SF,0,2);
TrLevelSlowPrevious=iCustom(NULL,0,"QQE",SF,1,2);
//StopParabolic = iCustom(NULL,0,"Parabolic Sub",StepPararabolic,MaxParabolic,0,0);
StopParabolic = iSAR(NULL,0,StepPararabolic,MaxParabolic,1);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if ((RsiMaCurrent < TrLevelSlowCurrent)&&(RsiMaPrevious > TrLevelSlowPrevious)) //////////these lines works doesn't work all the time !!!
{
Print("CLOSE Current Signal 1 : ",RsiMaCurrent," Signal 2 : ",TrLevelSlowCurrent," Previous Signal 1 : ",RsiMaPrevious," Signal 2 : ",TrLevelSlowPrevious);
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// Set Parabolic Stop, If Price > StopParabolic, The signal could be erlier than an parabolic signal, parabolic is valid
// Already set StopLoss < StopParabolic then modify order, the StopLoss can never go in wrong direction
if ((StopParabolic > OrderStopLoss()) && (Low[0] > StopParabolic + 10*Point) && (StopParabolic != OrderStopLoss())) //this one seems to work, but I get error 1
{
Print("(LONG) MODIFY STOP to Valeur Parabolic ", StopParabolic," Bid ",Bid);
OrderModify(OrderTicket(),OrderOpenPrice(),StopParabolic,OrderTakeProfit(),0,Green);
}
}
}
else // go to short position
{
// should it be closed?
if ((RsiMaCurrent > TrLevelSlowCurrent)&&(RsiMaPrevious < TrLevelSlowPrevious)) //////////these lines works doesn't work all the time !!!
{
Print("CLOSE Current Signal 1 : ",RsiMaCurrent," Signal 2 : ",TrLevelSlowCurrent," Previous Signal 1 : ",RsiMaPrevious," Signal 2 : ",TrLevelSlowPrevious);
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
//Parabolic same as long side
if ((StopParabolic < OrderStopLoss()) && (High[0] < StopParabolic-10*Point)&& (StopParabolic != OrderStopLoss())) ////this one doesn't work at all
{
Print("(SHORT) MODIFY STOP to Valeur Parabolic ", StopParabolic," Ask ",Ask );
OrderModify(OrderTicket(),OrderOpenPrice(),StopParabolic,OrderTakeProfit(),0,Green);
return(0);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Can someone help me ?