EA stop working help please

 

can some one tell me why this EA stopped working

there is still open trades but it will not trail it

extern int TakeProfit=750;
extern int TrailingStop=5;
extern int StopLoss = 100;


// check open possitions and place sl, tp


int start()
{
int cnt, totalOrders;
totalOrders = OrdersTotal();

if (totalOrders>0) // open orders identified
{
for (cnt=0;cnt<totalOrders;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

Print (cnt);

if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
{
if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
}
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if(OrderStopLoss()>(Ask+Point*TrailingStop)+Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
}
}
}
if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
{
if (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
}

if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop-Point)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
}
}
int BuyStop;
BuyStop=OrderStopLoss();Print("Cond-0 = ",BuyStop);
Comment("\n My ticket number is ", OrderTicket(), " and my stop loss setting is ", NormalizeDouble(BuyStop,Digits)); // new code

OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(BuyStop,Digits),OrderTakeProfit(),0,White);
}
return(0);
}
}
}

//+------------------------------------------------------------------+
 

Check your parentheses, { and }. I think return(0) in the wrong place.

 
Roger:

Check your parentheses, { and }. I think return(0) in the wrong place.

Roger


thank you


i have change the parentheses and it is scrolling know the orders

but what i have notice is that is not trailing at all

where did i go wrong

 

try this

extern int TakeProfit=750;
extern int TrailingStop=5;
extern int StopLoss = 100;


// check open possitions and place sl, tp

string str;
int start()
   {
   Comment(str);
   int cnt, totalOrders;
   totalOrders = OrdersTotal();

   if (totalOrders>0) // open orders identified
      {
      for (cnt=0;cnt<totalOrders;cnt++)
         {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

         Print (cnt);

         if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
            {
            if (OrderStopLoss()==0)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
               } 
            if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
               {
               if(OrderStopLoss()>(Ask+Point*TrailingStop)+Point) 
                  {
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
                  Print("Error_Modify - ",GetLastError());
                  else  str=StringConcatenate("\n My ticket number is ", OrderTicket(), " and my stop loss setting is ", DoubleToStr(Ask+Point*TrailingStop,Digits)); // new code                 
                  }
               }
            } 
         if(OrderType()==OP_BUY && OrderSymbol()==Symbol()) 
            { 
            if (OrderStopLoss()==0)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
               }

            if(Bid-OrderOpenPrice()>Point*TrailingStop)
               {
               if(OrderStopLoss()<Bid-Point*TrailingStop-Point) 
                  {
                  if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
                  Print("Error_Modify - ",GetLastError());
                  else  str=StringConcatenate("\n My ticket number is ", OrderTicket(), " and my stop loss setting is ", DoubleToStr(Bid-Point*TrailingStop,Digits)); // new code                 
                  }
               }
            //int BuyStop; 
            //BuyStop=OrderStopLoss();Print("Cond-0 = ",BuyStop);
            //Comment("\n My ticket number is ", OrderTicket(), " and my stop loss setting is ", NormalizeDouble(BuyStop,Digits)); // new code

            //OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(BuyStop,Digits),OrderTakeProfit(),0,White); 
            }
         
         }
      } 
return(0);
}
 
Roger:

try this

thanks Roger

i have place it on my ea but i have found it gives me 130 errors

 
I guess your TrailingStop too short.
 
Roger:
I guess your TrailingStop too short.

Roger

is it possible that it will not trail 5 pip because the broker will not allow it


if that is the case - willl it not be better to move the stop loss 5 pips instead of the trailing stop

 

I don't know your broker, my boker allows.

Replace in sell-modify

Print("Error_Modify - ",GetLastError());

to

Print("Error_Modify - ",GetLastError()," price - ",OrderOpenPrice()," stop - ",Ask+Point*TrailingStop," real stop - ", Ask+Point*MarketInfo(Symbol(),MODE_STOPLEVEL," level - ",MarketInfo(Symbol(),MODE_STOPLEVEL );

and in buy-modify

Print("Error_Modify - ",GetLastError());

to

Print("Error_Modify - ",GetLastError()," price - ",OrderOpenPrice()," stop - ",Bid-Point*TrailingStop," real stop - ", Bid-Point*MarketInfo(Symbol(),MODE_STOPLEVEL," level - ",MarketInfo(Symbol(),MODE_STOPLEVEL );

and then show results.

 
Roger:

I don't know your broker, my boker allows.

Replace in sell-modify

Print("Error_Modify - ",GetLastError());

to

Print("Error_Modify - ",GetLastError()," price - ",OrderOpenPrice()," stop - ",Ask+Point*TrailingStop," real stop - ", Ask+Point*MarketInfo(Symbol(),MODE_STOPLEVEL," level - ",MarketInfo(Symbol(),MODE_STOPLEVEL );

and in buy-modify

Print("Error_Modify - ",GetLastError());

to

Print("Error_Modify - ",GetLastError()," price - ",OrderOpenPrice()," stop - ",Bid-Point*TrailingStop," real stop - ", Bid-Point*MarketInfo(Symbol(),MODE_STOPLEVEL," level - ",MarketInfo(Symbol(),MODE_STOPLEVEL );

and then show results.

thanks Roger

it is trailing only if i change it to 15pips

what other settings can i use to get a tighter trail. how does step work?

 
What currency do you use?
 
Roger:
What currency do you use?

i have tried it on the gbpjpy,eurusd, usdjpy and eurjpy

Reason: