SendOrder sl and tp advise

 
Hi gurus,

Regarding the sl and tp, and taking into accoun this is altered for 3 or 5 digit brokers

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Ask-StopLoss*pips2dbl,Ask+TakeProfit*pips2dbl,"Unfinished_POS_agent_1min",MagicNumber,0,Green);

Would I simply use A and D variables ? is it that simple

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Ask-A*pips2dbl,Ask+D*pips2dbl,"Unfinished_POS_agent_1min",MagicNumber,0,Green)

I guess I'm wondering if I can refer to the actual stop loss level or value and not the actual pips or point

Can I simply us A*pips2dble and forget about the reference to Ask ? basically referring to actual price for a stop instead of points or pips ? is this OK ?

Please advise
 

First command Ask-StopLoss is not the same as Ask-A where A=Ask. Unless Stoploss=Ask. And I don't think thats what you want. Ask-A will equal 0 and that will probably generate error 130.

Can I simply us A*pips2dble and forget about the reference to Ask ? Yes, it just have to be a valid price.

Basically referring to actual price for a stop instead of points or pips ? is this OK ? Yes. That'll be ok.

 
ubzen:

First command Ask-StopLoss is not the same as Ask-A where A=Ask. Unless Stoploss=Ask. And I don't think thats what you want. Ask-A will equal 0 and that will probably generate error 130.

Can I simply us A*pips2dble and forget about the reference to Ask ? Yes, it just have to be a valid price.

Basically referring to actual price for a stop instead of points or pips ? is this OK ? Yes. That'll be ok.


Great thanks
 
Agent86:
Would I simply use A and D variables ? is it that simple


I guess I'm wondering if I can refer to the actual stop loss level or value and not the actual pips or point

Can I simply us A*pips2dble and forget about the reference to Ask ? basically referring to actual price for a stop instead of points or pips ? is this OK ?

Please advise

I suspect that the answer is no . . . but you don't say what are typical values for A and D ? are they 30 pips, 100 pips ? or are they actual price values, 1.5922 (GBPUSD) ?
 
Agent86:
I guess I'm wondering if I can refer to the actual stop loss level or value and not the actual pips or point

Can I simply us A*pips2dble and forget about the reference to Ask ? basically referring to actual price for a stop instead of points or pips ? is this OK ?

The call requires a price, thus you need aPrice +/- difference. A*pips2dbl is not a price. If A is 30 A*pips2dbl is 0.0030, a difference.

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,Ask-StopLoss*pips2dbl,Ask+TakeProfit...

On a buy you open at the ASK, but your stops are relative to the Bid so the above is wrong.

On ECN brokers you must open first and THEN set stops

    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
 
ubzen:

First command Ask-StopLoss is not the same as Ask-A where A=Ask. Unless Stoploss=Ask. And I don't think thats what you want. Ask-A will equal 0 and that will probably generate error 130.

Can I simply us A*pips2dble and forget about the reference to Ask ? Yes, it just have to be a valid price.

Basically referring to actual price for a stop instead of points or pips ? is this OK ? Yes. That'll be ok.

I've been off the computer for a while, which really hurts as a newbie coder, what I've learned I'll start to forget if I don't get back on this

Anyhow thanks I'll review my print statements some more
 
RaptorUK:
I suspect that the answer is no . . . but you don't say what are typical values for A and D ? are they 30 pips, 100 pips ? or are they actual price values, 1.5922 (GBPUSD) ?
Sorry for the delay I've been tending to my business a bit.

Ok back to coding, Yes A and D are calculated actual prices. These calculations are based on my attempt at an ABCD scheme which I have a base code working now

So once price gets to 50% fibonacci retrace, which in this case is my C level and thus OrderSend.
The A is the low and which this to be my Stop, while the D is the fibonacci extension which should be an actual price if my calculations are correct

As long as my A and D are actual prices and are valid price selections, this should be OK ?

Please advise
Thanks again everyone for the help
 
Agent86:

As long as my A and D are actual prices and are valid price selections, this should be OK ?

Correct.
 
Agent86:

Ok back to coding, Yes A and D are calculated actual prices. These calculations are based on my attempt at an ABCD scheme which I have a base code working now
As long as my A and D are actual prices and are valid price selections, this should be OK ?

Close but not quite. Mql4 charts are bid charts so the values you get from ABCD are Bid values. These need to be adjusted depending on the direction of the trade.

if (op == OP_BUY){
        DIR         = +1.;              bid.to.open = Ask-Bid;  // Open at Ask.
        op.text     = "Buy";            bid.to.stop = 0;        // Stop at Bid.
    } else {
        DIR         = -1.;              bid.to.open = 0;        // Open at Bid.
        op.text     = "Sell";           bid.to.stop = Ask-Bid;  // Stop at Ask.
    }
:
if (!OrderModify(OrderTicket(), OrderOpenPrice(), SLbid+bid.to.stop, TPbid+bid.to.stop, 0) Alert(...
:
if (!OrderModify(OrderTicket(), OrderOpenPrice(), Bid-DIR*TSL*atr ...
 
WHRoeder:

The call requires a price, thus you need aPrice +/- difference. A*pips2dbl is not a price. If A is 30 A*pips2dbl is 0.0030, a difference.

On a buy you open at the ASK, but your stops are relative to the Bid so the above is wrong.

On ECN brokers you must open first and THEN set stops

I see, thanks

I don't think Oanda is ECN I'm not really sure but haven't experienced a problem opening a trade with sl and tp included. At least not that I know of.
My previous codes are working with a set sl and tp, so I only speculate they are not an ECN broker but I really don't know for sure

Thanks for the info, if I get multiple errors I'll be sure to double check that part

I do see the stop is relative to the Bid I must have been toying around and forgot to fix thanks for the correction.

As far as A not being a price, my print statements are printing prices but I may have to rework this some because I'm not getting a correct OrderSend result when using A for sl etc.

I'll post my my base code so far for this project.
And I really need to learn how to use print statements for an OrderSend or perhaps a simulated OrderSend.

Thanks


 
Here is my base code so far, I don't see any problem with using simply A and D for sl and tp

I needed to remove the *pips2dbl since it's already an actual price and needs no conversion
Anyhow here is the base code I have been working on and I have a lot of ideas for this and hope to make something useful for people

//+------------------------------------------------------------------+
//|                                          Unfinished_POS_slate.mq4 |
//|                                                    Unfinished POS |
//|                                           ABCD scheme based slate |  
//+------------------------------------------------------------------+
#property copyright "Unfinished POS slate by Agent86"


//---- input parameters
extern double    TakeProfit=20.0; //optional use later
extern double    Lots=0.1;
extern double    StopLoss=10.0; //optional use later
extern int MagicNumber=123486;

//+++++ user can change retrace and/or extension:
extern double fibo_retrace=0.500; // C retracement level desired
extern double fibo_extension=0.618;  // D extention level desired


double val1;
double val2;
bool traded = false;


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
   
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   
        
   int i=0;
   int ticket,total,result;
   total = OrdersTotal();                 
   val1=iFractals(NULL, 0, MODE_UPPER,3);
   val2=iFractals(NULL, 0, MODE_LOWER,3); 

// buying code -----------------------   
     if(val1 > 0 && val2 == 0 && traded == false)
      { 
      double B = val1;
      Print(B, " B high");
      if(val2==0)
         {
         for (i=0; val2==0; i++)
            {
            val2=iFractals(NULL, 0, MODE_LOWER, i);
            double A = val2;
            if(A!=0)
              {
              Print(A, " A low");
              }
            }
          }
       double C = B-(B-A)*fibo_retrace; // C retrace
       Print(C, " UP ABC C Retrace calc");
       if(Bid <= C)
         {
         Print (Bid, " UP ABC C Retrace Hit");
         double D = B+(B-A)*fibo_extension; //D extension calcs seem ok may need to recheck
         Print (D, " UP D extention calc");
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3*pips2points,A,D,"Unfinished_POS_slate",MagicNumber,0,Green);
         if(ticket<0) Alert("OrderSend Failed: ", GetLastError());  
         }  
      
      
      traded=true;
      }
// end buying code ---------------------
     
     //val1=iFractals(NULL, 0, MODE_UPPER,3); been suggested I might need to reset these here
     //val2=iFractals(NULL, 0, MODE_LOWER,3); I'll investigate this some more later 
     //seems ok for now
     
// selling code ------------------    
     if(val2 > 0 && val1 == 0 && traded == true)//selling
      {
      B = val2;
      Print(B, " B low");
      if(val1==0)
        {
        for (i=0; val1==0; i++)
           {
           val1=iFractals(NULL, 0, MODE_UPPER, i);
           A = val1;
           if(A!=0)
             {
              Print(A, " A high");
             }
           }
        }        
             
        C = B+(A-B)*fibo_retrace; //C retrace
        Print(C, " DOWN ABC C retrace calc");
        if(Bid <= C)
           {
           Print (Bid, " DOWN ABC C Retrace Hit");
           D = B-(A-B)*fibo_extension; // D extention calcs seem ok, may need checking
           Print (D, " Down D extention calc");
           } 
                 
      traded=false;
      }

// end selling code ---------------------     
                    
                
   return(0);
  }    

//+------------------------------------------------------------------+
Reason: