Simple code needed for EA (modify two open orders) - page 5

 
deVries:


Do you wanna have it modifying StopLoss for both Buy and Sell trades with same pip ??

Think again if that is what you want and you can figure out why it is not moddifying that way....

Also don't modify trades with every new point in right direction choose a trailingstep to allow modifying (xx Points can choose 10 or more to avoid a lot of tradecontext too busy errors)

"!" is something like not in coding

At the moment I only want the TakeProfit modified on both trades, the StopLoss is the same throughout the whole trade (for the current testing anyway).
 

OK, found the problem . . . Spread is returned as the number of points . . .

So, change these lines . . .

if(OrderTakeProfit() > Candle23Open - ((TakeProfitModified - 1) * Point) + Spread )      //  check if TakeProfit has already been modified
                  if(!OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), Candle23Open - (TakeProfitModified * Point) + Spread, 0, Blue))

to this . . .

if(OrderTakeProfit() > Candle23Open + ((Spread - TakeProfitModified + 1 ) * Point)  )      //  check if TakeProfit has already been modified
                  if(!OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), Candle23Open + ((Spread - TakeProfitModified) * Point) , 0, Blue))
 
RaptorUK:

OK, found the problem . . . Spread is returned as the number of points . . .

So, change these lines . . .

to this . . .

That makes it work, thanks! Both the buy and sell trades get modified now, however, for some reasons they get modified a few times throughout the trades and the take profit seems to sometimes go further than what the inputs require it to. This seems to happen at whole times like 2:00 or 7:00, I'm not quite sure why this is happening, does it by any chance have something to do with the spread changing all the time? This happens with both buy and sell trades so I figure it can't be the spread. The only way I could think of is that the candle at 23:00 appears to change although that wouldn't make sense and I'm not sure how I could test that.

 
Add a few Print statements here and there to show you what the variables are doing, then you can figure out what is going wrong and fix it.
 

I'm trying to use this:

Print(Open [iBarShift(NULL, 0, StrToTime("23:00") )]);

To see if the open price of the bar changes but it seems to be printing random times each time.

Also on one of the days I noticed the trades don't follow the close all rule to close trades at 22:59 regardless of what's happening, I think this has stopped working.

I'm using this

   if (TimeDayOfWeek(TimeCurrent())==5 && TimeCurrent()>=StrToTime("22:59")) { CloseAll(); return(0); }

and this

void CloseAll()
   {
   for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if (OrderMagicNumber()!=MagicNumber) continue;
         
      //
      //
      //
      //
      //
         
      if (OrderType()==OP_BUY || OrderType()==OP_SELL)
         {
         for(int c=0; c<3; c++)
            {
            RefreshRates();
            if (OrderType()==OP_BUY)
                  { double cp = Bid;}  
            else  {        cp = Ask;}
               
            OrderClose(OrderTicket(),OrderLots(),cp,0,Yellow);
            int err=GetLastError();
            if(err==4 || err==136 || err==137 || err==138 || err==146)
               {
               Sleep(5000); continue;
               }  
               break;                     
            }
            break;

To close the trades at the specified time.

 

A post all in capital letters has been removed.

Please do not make excessive use of capital letters when posting.It is considered shouting and very rude.