ECN SL & TP Code errors 4051,4062in Modified MACD Sample

 

I have been trying my best to get this right. Can't quite seem to get er. I decided to put the StopLoss and Target Price in the

MACD Sample for now to make things simpler. Not worried about the ECN Pips2double adjustment code right now. I have it in

some other EA'S and I think it is Ok. Just would like to see this MACD or one of these EA'S actually make trades on the Demo

or for real. With Stops and Targets that is.

JimTrader1

Files:
 

If your Broker is an ECN Broker you MUST Send the order, if it is a Market order, with SL & TP set to 0 . . .

Please read the Documentation . . . OrderSend

This cannot work . . .

OrderSend(Symbol(),OP_BUY,Lots, Ask, 3, 0, "macd sample",16384,0,Green);           
          
OrderSelect(16384,SELECT_BY_TICKET);

The syntax for OrderSend is as follows . .

OrderSend(string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

You have, Price = Ask OK, Slippage = 3 OK, stoploss = 0 OK, takeprofit = "macd sample" NOT OK, comment = 16384 is this meant to be the Magic Number ?

Then you try to select the order using what you meant to use for the Magic Number . . . please read the Documentation . . . OrderSelect OrderSend will return the ticket number, store the ticket number and use it in the OrderSelect. Please check your return values, if OrderSend returns -1 it has failed . . you should print this information so that you know about it . .

 
RaptorUK:

If your Broker is an ECN Broker you MUST Send the order, if it is a Market order, with SL & TP set to 0 . . .

Please read the Documentation . . . OrderSend

This cannot work . . .

The syntax for OrderSend is as follows . .

OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

You have, Price = Ask OK, Slippage = 3 OK, stoploss = 0 OK, takeprofit = "macd sample" NOT OK, comment = 16384 is this meant to be the Magic Number ?

Then you try to select the order using what you meant to use for the Magic Number . . . please read the Documentation . . . OrderSelect OrderSend will return the ticket number, store the ticket number and use it in the OrderSelect. Please check your return values, if OrderSend returns -1 it has failed . . you should print this information so that you know about it . .


Raptor, I have been reading the OrderSelect, OrderSend,OrderTicket and made changes. Looks like I have the OrderModify Ok.Just getting lot's of Ticket errors.

You said the OrderSend creates a ticket number. You say it will be used in OrderSelect. HELP says pool parameter is ignored if the order is selected by the ticket

number. This all seems to make sense to me. In the example I am sending, I have ticket instead of OrderTicket() for all statements. I have tried both and keep getting ticket errors on close. 4108,4051, Also have had invalid parameter errors.

JimTrader1

 
jimtrader1:

In the example I am sending, I have ticket instead of OrderTicket() for all statements. I have tried both and keep getting ticket errors on close. 4108,4051, Also have had invalid parameter errors.

JimTrader1

When you are trying to Close an order what order are you trying to close ? and where do you get this 'ticket' number from ? when you do a Modify you get it from the OrderSend, (ticket = OrderSend( . . ..) )

At the point when you are trying to close the order you have already selected the Order . . . so why not simply use OrderTicket() ?

 
RaptorUK:

When you are trying to Close an order what order are you trying to close ? and where do you get this 'ticket' number from ? when you do a Modify you get it from the OrderSend, (ticket = OrderSend( . . ..) )

At the point when you are trying to close the order you have already selected the Order . . . so why not simply use OrderTicket() ?


I've Got It,I've Got It! I just wanted to tell you what happened. Might be of some interest to you also. I was able to get this problem with

the ECN Order execution ONLY after I modified an EA off of the code base. It is one called "Daytrading "near the end of the base. I saw that

they did more cross references like SL and TP for the stop loss etc. Also I just liked it. It first made a trade on the Demo acct. I went crazy.

Then it didn't make any for real on my acct. I started thinking about the fact that, you can't have a stoploss and Trailing stop on at the same

time with the MetaTrader platform. I was about to take the StopLoss out of the code and just have the Trailing stop.This is when it popped

a trade right in Front of me.Was a very good trade also and it closed it out quickly using a 5min chart on the EURUSD. That is when I knew

that it must be Ok. Now I am trying to figure out why this one works and the last one I sent you does not. I'll send the new Daytrade one that

has the ECN OrderModify. If you get a chance, NO hurry because I have things working now and smoother. Take a look and see what you

think is goiing on here. It would be good for me to know why this one does work and mine does not. Also Raptor, is it somewhat normal to

get a few errors because of mismatched chart errors? Some currencys are doing this in the test. How many before we have to worry about

losing too many trades?

JimTrader1

Files:
 

In the code you posted today . . .

for(cnt = 0; cnt < totalOrders; cnt++)   //  <-- loop through the open Orders,  you MUST count down not up if closing Orders
     {        
       // the next line will check for ONLY market trades, not entry orders
       OrderSelect(cnt, SELECT_BY_POS);    //  <--  select the Order at position  cnt
       // only look for this symbol, and only orders from this EA        
       if(OrderSymbol() == Symbol() && OrderType() <= OP_SELL && OrderComment() == nameEA) //  <  -- check for a match to Symbol, BUY/SELL and comment(bad idea)
         {   
           numPos++;
           // Check for close signal for bought trade
           if(OrderType() == OP_BUY)    //  <---  is it a BUY order ?
             {           
               if(isSelling || isClosing) 
                 {
                   // Close bought trade
                   OrderClose(OrderTicket(),OrderLots(),Bid,slippage,Violet);   // <--- close trade,  ticket number comes from OrderTicket()
                   prtAlert("Day Trading: Closing BUY order");

In the code you posted 2 days ago . . .

total=OrdersTotal();

   for(cnt=0;cnt<total;cnt++)   //  <-- loop through the open Orders,  you MUST count down not up if closing Orders

     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);  // select Order at position  cnt
      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 ((sto>80 && rsi>70) || (adxc<5) || (Open[0]>=StopLoss || Open[0]>=TakeProfit))
                {
                 OrderClose(ticket,OrderLots(),Bid,3,Violet); // close position      <---- where does ticket come from ? ? ? ?

See the difference ?

 

I can see the difference in the ticket. I am having trouble with the count. That's why I am going to send this simple EA with

NO stops or targets. It works fine and shows the cnt++ under the void CheckForClose(). I get No errors with this one and

it Opens and Closes trades fine. (If I can only get one with stops and targets to work). Yeah the ECN Daytrade one was working

but nothing with stops or takeprofits seem to be working right now. I notice once and awhile OrderModify errors with different ticket

number errors. Something not right with the OrderModify, ticket or both.

JimTrader1

Reason: