Close and Reverse orders - page 4

To add comments, please log in or register
GeoffGreaves
28
GeoffGreaves  

Buy and Sell with 5 digit brokers

The basic buy and sell scripts have a problem with five digit brokers because the MQL4 variable 'Points' seems to be ticks rather than pips and so the SL and TP are only a tenth of what's expected. Okay if inelegant to put 400 for 40 etc. if you only use five digits but JPY and other charts that I use don't although I'm happy to use the same SL and TP so I've added checking for five digits to the originals with automatic adjustment.

GoodBoyFX
41
GoodBoyFX  
GeoffGreaves:

Buy and Sell with 5 digit brokers

The basic buy and sell scripts have a problem with five digit brokers because the MQL4 variable 'Points' seems to be ticks rather than pips and so the SL and TP are only a tenth of what's expected. Okay if inelegant to put 400 for 40 etc. if you only use five digits but JPY and other charts that I use don't although I'm happy to use the same SL and TP so I've added checking for five digits to the originals with automatic adjustment.


guys have requested hedging script that opens opposite positions(same size) without closing current open orders. Ideal for trade mgmt (chaos time or news coming in hedge lock your positions profit/loss) enjoy this attachment.. note: hedge script is to be attached the pair which is being traded needing hedge
ADLANE RAMDANE
54
ADLANE RAMDANE  
GoodBoyFX:

guys have requested hedging script that opens opposite positions(same size) without closing current open orders. Ideal for trade mgmt (chaos time or news coming in hedge lock your positions profit/loss) enjoy this attachment.. note: hedge script is to be attached the pair which is being traded needing hedge

Thank you for doing great  Hedge_Script

Can you add it to this accretion For this EA

extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=50;
extern double TakeProfit=50;
extern int TrailingStop=50;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;
     if((iFractals(NULL,0,MODE_LOWER,0)<iBullsPower(NULL,0,13,PRICE_HIGH,0))&&(iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0)>iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0))) // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
     if((iFractals(NULL,0,MODE_LOWER,0)<iBearsPower(NULL,0,13,PRICE_LOW,0))&&(iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0)<iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,0))) // Here is your open Sell rule
     {
        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
}

int TotalOrdersCount()
{
  int result=0;
  for(int i=0;i<OrdersTotal();i++)
  {
     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
     if (OrderMagicNumber()==MagicNumber) result++;

   }
  return (result);
}



11128532
29
11128532  
eli:

Sometimes there is a need to reverse the trade that u open. The attached script will close all open orders that already running and will open a new orders with equal lots size. The scrip will close and reverse only the orders that the symbol() is equal to the one that the script is attached to.

Thanks for your great job. 

Please would you do a script that will close and reverse all the open trades in different pairs in my platform.

I lost mine when my system crashed? 

Eraldi-al
25
Eraldi-al  
Can please someone to help and tell how this scripts work,, they work only with hot keys?,, and i had never suxcidet  to run any ea on my mt4,,, they show me only the sad face on the chart, haw can i do to work them.Thanks.
To add comments, please log in or register