TrailingStop checking with my EA

 

Hi,

I want to programm my own trailing stop. I mean, I don't want to send the trailing stop to my broker but I want to check it with my EA and close it with my EA.

Can I do it in that way?

if(OrderType()==OP_BUY && Bid-OrderOpenPrice()>=Start_TrailingStop*Point())
 {
    if(Bid<  High[iHigh(NULL,0, iBarShift(NULL,0,OrderOpenTime())]  -Point()*TrailingStop)
      {
       OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);
       return;
      }
  }   
 

you can do it with a function called MaxLoss which I will attach here.

the disadvantage of not sending a stop loss to your broker is that in a volatile market, the tick information may skip a few points or more on price and therefor you do not get the precise stop loss price that you would with a broker.

#property copyright "Copyright © 2006, Taylor Stockwell"
#property link      "stockwet@yahoo.com"

extern bool Use_Max_Loss = true;
extern int Max_Loss = 50;

if(Use_Max_Loss && Max_Loss > 0) killTrade(val,OrderTicket());

double getPipValue(double ord,int dir)
{
   double val;
   RefreshRates();
   if(dir == 1) val=(NormalizeDouble(ord,Digits) - NormalizeDouble(Ask,Digits));
   else val=(NormalizeDouble(Bid,Digits) - NormalizeDouble(ord,Digits));
   val = val/Point;
   return(val);   
}

int getMaxLoss()
{
   int calcMaxLoss;
   calcMaxLoss = Max_Loss;
   return(calcMaxLoss);
}

void killTrade(int pips, int ticket)
{
   if(OrderSelect(ticket, SELECT_BY_TICKET)==true)
   {
      if(pips <= -1*getMaxLoss())
      {
         if(OrderType()==1) OrderClose(ticket,OrderLots(),Ask,3,Red);     
         else OrderClose(ticket,OrderLots(),Bid,3,Red); 
      }      
   }
}

I think that is mainly it - add that to your ea it wont work on its own

 
  1. val = val/Point;
    
    EA's should auto-adjust for 5 digit brokers (pips, and points) (TP, SL, and slippage)
    //++++ These are adjusted for 5 digit brokers.
    double  pips2points,    // slippage  3 pips    3=points    30=points
            pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    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
    

  2.          if(OrderType()==1) OrderClose(ticket,OrderLots(),Ask,3,Red);     
             else OrderClose(ticket,OrderLots(),Bid,3,Red); 
    
    Simply and always test return values
    if (!OrderClose(ticket,OrderLots(),OrderClosePrice(),3*pips2points,Red))
       Alert("OrderClose(",ticket,"...) failed: ",GetLastError());
    

 

Thank you very much WHRoeder, but I can't understand how "Digits.pips" or "Slippage.Pips" in you code works.

What does x.Pips mean or do with my slippage?


+++

To my other question:

I want to programm my Trailing Stopp by hand because for Oil I only can set my Trailing Stopp to 15 Pips and that is too much.

For using a Trailing Stopp I have to know the highest/lowest price from the OrderOpenTime.

So is

High[iHigh(NULL,0, iBarShift(NULL,0,OrderOpenTime())]

this right or do I have to subtract "1" from the result of iBarShift(NULL,0,OrderOpenTime()) ??

 

can someone help me edit sar ohlc to use heiken ashi ohlc

Hi, I have an MTF indicator that uses sar, however I'd like the sar to calculate heiken ashi ohlc, and not the normal type

Can you tell me how I can do this, my mtf indicator calls to the sar indicator to calculate sar formula, I think it is calling to the internal indicator in mt4 that can not edit

you can skype or email if you can assist and like to talk about it

skype sty671

email sty671@gmail.com

I can also supply the original file that I'm trying to use heiken ashi ohlc for