Help for a script..

 

Hi guys,

I have some trouble with this script :


extern double a1         =0.85;

extern double amin       =1;

double pos;

if ((OrderProfit()*a1>=amax) && (OrderLots()*a1>=amin) && (sens==1))
    {
       ok=OrderSelect(0,SELECT_BY_POS);
       pos=OrderLots()*(1-a1);
       ok=OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);

       ticket=OrderSend(Symbol(),OP_BUY,pos,Ask,3,Ask-pstop,Ask+gtg,"essai",16384,0,Red);} 

    }

The OrderClose is not done, the "pos" variable apparently take value of "-1" and message says " invalid lots amount for OrderSend function"


Please help

 
Volcanbleu:

Hi guys,

I have some trouble with this script :

[code removed]

Please help

Please don't just raw paste your source code.

Use the SRC button, and put it in the source box next time. Thank you.


You have to select a ticket before you can reference the associated information with it.

https://www.mql5.com/en/docs/trading/orderselect

Documentation on MQL5: Trade Functions / OrderSelect
Documentation on MQL5: Trade Functions / OrderSelect
  • www.mql5.com
Trade Functions / OrderSelect - Reference on algorithmic/automated trading language for MetaTrader 5
 
Jack Thomas:

Please don't just raw paste your source code.

Use the SRC button, and put it in the source box next time. Thank you.


You have to select a ticket before you can reference the associated information with it.

https://www.mql5.com/en/docs/trading/orderselect

High Jack,

Ok for using SRC button,

extern double a1         =0.85;

extern double amin       =1;

double pos;

if ((OrderProfit()*a1>=amax) && (OrderLots()*a1>=amin) && (sens==1))
    {
       ok=OrderSelect(0,SELECT_BY_POS);
       pos=OrderLots()*(1-a1);
       ok=OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);

       ticket=OrderSend(Symbol(),OP_BUY,pos,Ask,3,Ask-pstop,Ask+gtg,"essai",16384,0,Red);} 

    }

This is just a simplifyed code resuming the pb of this line :

       pos=OrderLots()*(1-a1);
were "pos" should return positive value when an order is selected, which is actually the case
 

You should NEVER call any of the OrderXXX() functions before you call OrderSelect()

Values that you get can be undefined or related to a different order.


Your code is wrong, incomplete, can't be compiled and tested. For all we know, besides OrderSelect(), you might have a number of other bugs.

Also, if you want help, the best way is to attach code that can be compiled and which demonstrates your problem.

 
Drazen Penic:

You should NEVER call any of the OrderXXX() functions before you call OrderSelect()

Values that you get can be undefined or related to a different order.


Your code is wrong, incomplete, can't be compiled and tested. For all we know, besides OrderSelect(), you might have a number of other bugs.

Also, if you want help, the best way is to attach code that can be compiled and which demonstrates your problem.

Hi Drazen,


Thanks for the advice. You are quite right. I was not sure about the line :

pos=OrderLots()*(1-a1);

and In fact, The  PB was from another part.. its coming... aha

Reason: