TFEX-H1 EA

เริ่มโดย admin, กันยายน 13, 2017, 05:17:41 AM

« หน้าที่แล้ว - ต่อไป »

admin

//int Expert_ID =Period();//  copy from forex up and down and sideway
extern double Lot = 1.0;// deposit 1000 usd lot1.0 protit 1411 usd trade 18 times currency EURUSD M30  time 2015-11-01 to 2015-12-16 (46 days)//extern double MAperiod = 10; // for Exness M30 EURUSD
//extern double K = 20;
//extern double D =4;
//extern double Slow = 4;
//extern int Movingback200 = 200; // old 320
//extern int Movingback100 = 100;
//extern int BBback = 180;
//extern int Movingbackvaryopen = 100;
//extern int Movingbackvaryclose = 100;
//extern int         TP =180;
//extern int         SL = 60;
 

//double  Lot=NormalizeDouble (( AccountEquity()/5)/(150 *2),2);  //for currency only  leverager 1:888

double TrailingStop =00;
double Shiftbackopenorder=26;



//  close all code //

//**************************************************************************

//bool  Openbuyandsell = true;    // for open oreder and false for no oopen order//

//**************************************************************************

int    ProfitTarget     =10000;             // closes all orders once Float hits this $ amount 800 usd lot 1.0 deposit 1000 usd protit 1411 usd time 2015-11-01 to 2015-12-16 (46 days)
int    LossTarget     = -10000;               // must be -400 only stop loss USD

//////////////////////////////////////////////

int  Openbuyandsell = 1;    //   default = 1 for  1= true openorder    , 0= false for no open order

//////////////////////////////////////////



int  CloseAllorder      = 0;  //  default =0 No closeallorder =0= false     ,  closeallorder =1= true 


///////////////////////////////////////////


bool   CloseProfitableTradesOnly = false; // closes only profitable trades

double ProftableTradeAmount      = 1000*Lot/5;     // Only trades above this amount close out

double Loss      = -1000*Lot/5 ; // loss value for stop loss

  int Expert_ID =Period();
 
// bool Openorder;

////////////////////////////////////////////

//extern bool   ClosePendingOnly = false;          // closes pending orders only
//extern bool   UseAlerts        = false;

void CloseAll()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType() == OP_BUY)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
        if ( OrderType() == OP_SELL)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
        if ( OrderType()== OP_BUYSTOP)  result = OrderDelete( OrderTicket() );
        if ( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
      //  if (UseAlerts) PlaySound("alert.wav");
}
  return;
}


//+------------------------------------------------------------------------+
//| cancels all orders that are in profit
//+------------------------------------------------------------------------+
void CloseAllinProfit()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
   bool result = false;
       if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
       if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       
        //   if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()<Loss)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
     //  if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()<Loss)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
     
     
   
   
       // if (UseAlerts) PlaySound("alert.wav");
}
  return;
}

//+------------------------------------------------------------------------+
//| cancels all pending orders
//+------------------------------------------------------------------------+
void ClosePendingOrdersOnly()
{
  for(int i=OrdersTotal()-1;i>=0;i--)
{
    OrderSelect(i, SELECT_BY_POS);
    bool result = false;
        if ( OrderType()== OP_BUYSTOP)   result = OrderDelete( OrderTicket() );
        if ( OrderType()== OP_SELLSTOP)  result = OrderDelete( OrderTicket() );
  }
  return;
  }
// close all code //

int start()

{
// close all code //
int      OrdersBUY;
   int      OrdersSELL;
   double   BuyLots, SellLots, BuyProfit, SellProfit;
   

   
if( CloseAllorder == 1) bool CloseAllNow      = true;
if( CloseAllorder == 1) bool  Openorder = false;

if( CloseAllorder == 0)  CloseAllNow      = false;
if( CloseAllorder == 0)   Openorder = true;
   
 
   
//  double Profit1 =ProfitTarget*0.02;
//double Profit3 =ProfitTarget*0.06;

//Print("Symbol  ",Symbol());

//Print("Order Symbol",OrderSymbol());

//Print("OrderMagicNumber = ",OrderMagicNumber());

//if(OrderMagicNumber()==22222) Print("buy now");


  //Print(" ProftableTradeAmount      =", ProftableTradeAmount  );
  // Print(" Loss      =", Loss );
   
//Print(" OrderMagic    =", OrderMagicNumber() );


//Print("Ordersymbol =",OrderSymbol());
/*

Print("Loss =  ",Loss);

Print("ProftableTradeAmount =  ",ProftableTradeAmount);
*/

//Print("Lot =",Lot);
//Print("OrdersTotal() =",OrdersTotal());


//+------------------------------------------------------------------+
//  Determine last order price                                       |
//-------------------------------------------------------------------+
      for(int i=0;i<OrdersTotal();i++)
      {
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
           if(OrderType()==OP_BUY)  OrdersBUY++;
           if(OrderType()==OP_SELL) OrdersSELL++;
           if(OrderType()==OP_BUY)  BuyLots += OrderLots();
           if(OrderType()==OP_SELL) SellLots += OrderLots();
           if(OrderType() == OP_BUY)  BuyProfit += OrderProfit() + OrderCommission() + OrderSwap();
           if(OrderType() == OP_SELL)  SellProfit += OrderProfit() + OrderCommission() + OrderSwap();
           
           
           
           
      }               
   
    if(CloseAllNow  ) CloseAll();
   
   
/* 
    if(CloseAllNow  )
{ Openorder = false;}
else
{Openorder = true;}

*/

//if( BuyProfit+SellProfit > ProftableTradeAmount) CloseAllNow = true;
//if (OrdersTotal() >0 )
{
//if( Bid >= OrderOpenPrice()+100*Point   || Ask <= OrderOpenPrice()-100*Point  ) CloseAllNow = true;
}
//if (OrdersTotal()==0 )CloseAllNow = false;
   
Print("BuyProfit+SellProfit  =",BuyProfit+SellProfit );
/*
    if(CloseAllNow)

{Print ( "CloseAllNow = true "); }
else
{Print ( "CloseAllNow = false "); }

 


/*

if(Openorder)

{Print ( "Openorder = true "); }
else
{Print ( "Openorder = false "); }

/*


Print("OrdersTotal =",OrdersTotal());

Print("OrderOpenPrice()-100*Point =",OrderOpenPrice()-100*Point);
Print("OrderOpenPrice()+100*Pointt =",OrderOpenPrice()+100*Point);

Print("OrderOpenPrice()-50*Point =",OrderOpenPrice()-50*Point);
Print("OrderOpenPrice()+50*Pointt =",OrderOpenPrice()+50*Point);
Print("OrderOpenPrice() =",OrderOpenPrice());
/*

Print("Period =",Period());


Print("Period =",Period());
 
Print("Symboll()=",Symbol());

if(Openbuyandsell)

{Print ( "Openbuyandsell = true "); }
else
{Print ( "Openbuyandsell = false "); }   
   
    */

 
  if(Openbuyandsell==1)

{Print ( "Openbuyandsell = 1"); }
else
{Print ( "Openbuyandsell = 0 "); }


   
////////////////////////////////////////////////////////   //closed all @ time
   
//if( Hour()==23 /* && DayOfWeek()==5*/ ) CloseAll();
 
// if( Symbol()=="EURUSD" && Bid==1.05324) CloseAll();
 
///////////////////////////////////////////////////////////////////////////////
   
//  Print ( "Close all = every friday 16:00 ");
   
//  if(   ( Hour() >0 && Hour() < 6  ) || ( Hour() >9 && Hour()<12 ) ) CloseAll();
   
 
   
    if(CloseProfitableTradesOnly) CloseAllinProfit();
   

   
   // if(ClosePendingOnly) ClosePendingOrdersOnly();
   
   
 
   

/////  close all code///   

int Vol_1=  iVolume(NULL,0,1);
int Vol_2=  iVolume(NULL,0,2);
int Vol_3=  iVolume(NULL,0,3);


int VMA;
int VMA200;

  for(int v=1;v<=201;v++)
{
 
        if ( i<=200 )
        {
       
          VMA +=  iVolume(NULL,0,v);
       // Print(" i =", v);
       //Print(" VMA =", VMA);
          }
  }     
   
     VMA200 = VMA/200;
//    Print(" VMA200 =", VMA200); 
   // Sleep(60000);


    //---- Remember the indicator's values for further analysis
    //---- Note that we use the 1st and the 2nd bar. This allows a 1-bar delay
    //---- (i.e., the signal will appear later), but protects against repeated opening and closing
   
   
   
    //---- positions within a bar
   
   
   double ATR= iATR(NULL,0,1,1);
   
  //  Print(" ATR =", ATR); 
   
    double MACD_1 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1 );
    double MACD_S = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 1 );


double   Ma1201=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,1);
double   Ma1226=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,26);
double   Ma1252=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,52);

double   Ma12=iMA(NULL,0,12,0,MODE_SMA,PRICE_CLOSE,0);
double     Ma26=iMA(NULL,0,26,0,MODE_SMA,PRICE_CLOSE,0);

double     EMA5_0=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);
double     EMA10_0=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,0);
double     EMA20_0=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,0);

double     EMA5_2=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,2);
double     EMA10_2=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,2);
double     EMA20_2=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,2);


double     EMA5=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA10=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA20=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA25=iMA(NULL,0,25,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA75=iMA(NULL,0,75,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA50=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA100=iMA(NULL,0,100,0,MODE_EMA,PRICE_CLOSE,1);
double     EMA200=iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,1);


double      Sto = iStochastic(NULL,0,12,3,3,MODE_SMA,0,MODE_MAIN,  1);// 1st bar
 
     int BarHighest60 = iHighest(NULL,0,MODE_HIGH,60,30);
  double  PHighest60=iHigh(NULL,0,BarHighest60);   
  int BarLowest60 = iLowest(NULL,0,MODE_LOW,60,30);   
   double  PLowest60=iLow(NULL,0,BarLowest60);
     
      int BarHighest26 = iHighest(NULL,0,MODE_HIGH,26,0);
  double  PHighest26=iHigh(NULL,0,BarHighest26);   
  int BarLowest26 = iLowest(NULL,0,MODE_LOW,26,0);   
   double  PLowest26=iLow(NULL,0,BarLowest26);
   
   int BarHighest30 = iHighest(NULL,0,MODE_HIGH,30,0);
  double  PHighest30=iHigh(NULL,0,BarHighest30);   
  int BarLowest30 = iLowest(NULL,0,MODE_LOW,30,0);   
   double  PLowest30=iLow(NULL,0,BarLowest30);
   
   //RSI highest
  double RSIHi60=iRSI(NULL,0,12,PRICE_CLOSE,BarHighest60);
  double RSIHi30=iRSI(NULL,0,12,PRICE_CLOSE,BarHighest30);
   
    //RSI LOwest
  double RSILow60=iRSI(NULL,0,12,PRICE_CLOSE, BarLowest60);   
  double RSILow30=iRSI(NULL,0,12,PRICE_CLOSE,BarLowest30);



  double  PClose15=iClose(NULL,0,15);
double  PClose30=iClose(NULL,0,30);
double  PClose60=iClose(NULL,0,60);

     double  PClose0=iClose(NULL,0,0);
double  PClose1=iClose(NULL,0,1);
double  PClose2=iClose(NULL,0,2);
double  PClose3=iClose(NULL,0,3);


double  POpen0=iOpen(NULL,0,0);
double  POpen1=iOpen(NULL,0,1);
double  POpen2=iOpen(NULL,0,2);
  double  POpen3=iOpen(NULL,0,3);
 
  double PLow0= iLow(NULL,0,0);
double PLow1= iLow(NULL,0,1);
double PLow2= iLow(NULL,0,2);
  double PLow3= iLow(NULL,0,3);

  double PHigh0= iHigh(NULL,0,0);
double PHigh1= iHigh(NULL,0,1);
  double PHigh2= iHigh(NULL,0,2);
  double PHigh3= iHigh(NULL,0,3);
 




///////////////////////////////////////////////////////////////////////
   
 


/*
  double HA_Close_2= (POpen2+PHigh2+PLow2+PClose2)/4;
    double HA_Open_2 = (POpen3+PClose3 )/2;
   

  double HA_Close= (POpen1+PHigh1+PLow1+PClose1)/4;
  double HA_Open = (HA_Close_2+HA_Open_2)/2;




  Print(" HA_Close =", HA_Close);
Print(" HA_Open =",HA_Open);
Print(" OrderType() =",OrderType());

*/

int BarHighest_c25 = iHighest(NULL,0,MODE_CLOSE,25,5);
  int BariLowest_c25 = iLowest(NULL,0,MODE_CLOSE,25,5); 
   double  PLowest_c25=iLow(NULL,0,BariLowest_c25);
double  PHighest_c25=iHigh(NULL,0,BarHighest_c25);



int BarHighest_c150 = iHighest(NULL,0,MODE_CLOSE,150,4);
  int BariLowest_c150 = iLowest(NULL,0,MODE_CLOSE,150,4); 
   double  PLowest_c150=iLow(NULL,0,BariLowest_c150);
double  PHighest_c150=iHigh(NULL,0,BarHighest_c150);

int BarHighest_c100 = iHighest(NULL,0,MODE_CLOSE,100,4);
  int BariLowest_c100 = iLowest(NULL,0,MODE_CLOSE,100,4); 
   double  PLowest_c100=iLow(NULL,0,BariLowest_c100);
double  PHighest_c100=iHigh(NULL,0,BarHighest_c100);

int BarHighest_c50 = iHighest(NULL,0,MODE_CLOSE,50,4);
  int BariLowest_c50 = iLowest(NULL,0,MODE_CLOSE,50,4); 
   double  PLowest_c50=iLow(NULL,0,BariLowest_c50);
double  PHighest_c50=iHigh(NULL,0,BarHighest_c50);



 
int BarHighest = iHighest(NULL,0,MODE_HIGH,Shiftbackopenorder,12);
  int BariLowest = iLowest(NULL,0,MODE_LOW,Shiftbackopenorder,12); 
   double  PLowest=iLow(NULL,0,BariLowest);
double  PHighest=iHigh(NULL,0,BarHighest);


  int BarHighest240 = iHighest(NULL,0,MODE_HIGH,240,0);
  int BarLowest240 = iLowest(NULL,0,MODE_LOW,240,0); 
   double  PLowest240=iLow(NULL,0,BarLowest240);
double  PHighest240=iHigh(NULL,0,BarHighest240);

color color1 = Red;
color color2 = Green;
color color3 = Red;
color color4 = Green;
#define HAHIGH      0
#define HALOW       1
#define HAOPEN      2
#define HACLOSE     3
//double HAHigh = iCustom(NULL,0,"Heiken Ashi", color1,color2,color3,color4, HAHIGH, 0);
double HACLOSE_1 = iCustom(NULL,0,"Heiken Ashi", color1,color2,color3,color4, HACLOSE, 1);
double HAOPEN_1 = iCustom(NULL,0,"Heiken Ashi", color1,color2,color3,color4,HAOPEN, 1);

Print("  HACLOSE_1 =", HACLOSE_1);
Print("  HAOPEN_1 =", HAOPEN_1);

 
////////////////// /// Hedging zone recovery /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
      if (OrderType() == OP_BUY && Openbuyandsell != 0 )
     
     {
       if (OrdersTotal()==1  && Openorder && Bid < OrderOpenPrice()-ATR*0.618 )
      {
       OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,0 ,0, "XM",  9, 0, Red );
      Openbuyandsell = 0;
      }
      }
     
   if ( OrderType() == OP_SELL &&   Openbuyandsell != 0)
      {
      if (OrdersTotal()==1   && Openorder && Ask > OrderOpenPrice()+ATR*0.618  )
     
      {
      OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,0 ,0 , "XM", 9, 0, Green ) ;
     Openbuyandsell = 0;
      }
      }
     
    ///////////////////////////////////////////////////////////////////////////////////////////// 
   
     
     //  if ( OrderType() == OP_BUY && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
      // if ( OrderType() == OP_SELL && OrderProfit()+OrderSwap()>ProftableTradeAmount)  result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
   
      for(int j=0;j<OrdersTotal();j++)
      {

     OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
 
     if(OrderType() == OP_BUY && OrderMagicNumber()==9)
      {
         
      if ( HA_Close < HA_Open && Renko_HU_1 < Renko_HU_2 )
      {
      OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
      }
     
      }
     
      if(OrderType() == OP_SELL && OrderMagicNumber()==9)
      {
     
       if (HA_Close > HA_Open && Renko_HU_2 < Renko_HU_1  )
       {
       OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
       }
           
       }   
           
      }     
   
    */
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


   
     int _GetLastError = 0, _OrdersTotal = OrdersTotal();
    //---- search in all open positions
    for ( int z = _OrdersTotal - 1; z >= 0; z -- )
    {
        //---- if an error occurs when searching for a position, go to the next one
        if ( !OrderSelect( z, SELECT_BY_POS ) )
        {
            _GetLastError = GetLastError();
            Print( "OrderSelect( ", z, ", SELECT_BY_POS ) - Error #", _GetLastError );
            continue;
        }

        //---- if a position is closed not for the current symbol, skip it
       
       
       
        if ( OrderSymbol() != Symbol() ) continue;

        //---- if the MagicNumber is not equal to the Expert_ID, skip this position
        if ( OrderMagicNumber() != Expert_ID ) continue;

        //---- if a BUY position is opened,
       
       
       if ( OrderType() == OP_BUY )
        {
       
         if(TrailingStop>0) 
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
       
       
           //---- close buy position
           
// if(Ask==0)
   
  // if ( (HA_Close < HA_Open && Renko_HU_1 <= Renko_HU_2  ) )
   
   
//  if  ( POpen1 < POpen2 &&  PClose1 < PClose2 && PLow1 < PLow2 && PHigh1 < PHigh2)
   
   
  //  if ( (  PClose1 +POpen1 + PHigh1 + PLow1 )/4 < ( PClose2 + POpen2 + PHigh2 + PLow2  )/4   ) // close buy
   
  // if (    /* MACD_1 < MACD_S && */ Openorder && Openbuyandsell==1  && Hour() >=0 && Hour() < 23  && POpen1 < POpen2 &&  PClose1 < PClose2 && PLow1 < PLow2 && PHigh1 < PHigh2) // Heiken ahi
   
    if (/* MACD_1 < MACD_S && */ HAOPEN_1 > HACLOSE_1) // Heiken ahi
       
  //if ( ( EMA10 <  EMA50 && MACD_1 <0 ) )
     
// if ( MACD_1 < MACD_S)

  //  if ( EMA5_0 <  EMA5_2 && MACD_1 < 0 && PClose1 < POpen1 && Vol_1 > Vol_2 && Vol_1 > Vol_3 )
 
// if (   Vol_1 >= VMA200*2 && MACD_1 <  0 &&  PClose1 < POpen1 )
       
   
     
     
   
            {
                //---- close the position
               
                if ( !OrderClose( OrderTicket(), OrderLots(), Bid, 5, Green ) )
                {
                    _GetLastError = GetLastError();
                  //  Alert( "Error OrderClose # ", _GetLastError );
                    return(-1);
                }                                   
                             
             
               
               
               
            }
            //---- if the alert has not changed, exit: it is too early to open a new position
            else
            { return(0); } 
           
           
       
           
        }
        //---- if a SELL position is opened,
        if ( OrderType() == OP_SELL )
        {
         if(TrailingStop>0) 
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
       
       
       
       
            //---- close sell position
             
   //  if(Ask==0)
     
     
//  if  (  HA_Close > HA_Open && Renko_HU_2 <= Renko_HU_1    )
   
   
     
    //  if  ( POpen1 > POpen2 && PClose1 > PClose2 && PLow1 > PLow2 && PHigh1 > PHigh2 )
   
   
   //  if ( (  PClose1 +POpen1 + PHigh1 + PLow1 )/4 > ( PClose2 + POpen2 + PHigh2 + PLow2  )/4   ) // close sell 
   
   
     
  //   if   ( /* MACD_1 > MACD_S && */ Openorder && Openbuyandsell==1 && Hour() >=0 && Hour() < 23 && POpen1 > POpen2 && PClose1 > PClose2 && PLow1 > PLow2 && PHigh1 > PHigh2  )// // Heiken ahi   
     
       if   ( /* MACD_1 > MACD_S && */ HACLOSE_1 > HAOPEN_1 )// // Heiken ahi open close
       
    //    if  ( PClose1 > EMA50 )
           
     //  if  ( (   EMA10 >  EMA50 && MACD_1 >0 )   )
     
           
           // if  ( MACD_1 > MACD_S )
           
            //if  ( EMA5_0 > EMA5_2 && MACD_1 >0 && PClose1 > POpen1 && Vol_1 > Vol_2 && Vol_1 > Vol_3 )
           
     //        if  (Vol_1 >= VMA200*2 && MACD_1 >0 && PClose1 > POpen1  )
           
         
           
           
     
            {
                //---- close the position
                if ( !OrderClose( OrderTicket(), OrderLots(), Ask, 5, Red ) )
                {
                    _GetLastError = GetLastError();
                   // Alert( "Error OrderClose № ", _GetLastError );
                    return(-1);
                }
            }
            //---- if the alert has not changed, exit: it is too early to open a new position
            else return(0);
        }
       
       
   
             
    }



  ///////////   //---- open a BUY positiont/////////////
 
//  if(OrdersTotal()==0) Openbuyandsell = 1;
 
// if(PClose1 > EMA20 )
  {

// Print("PClose1 > EMA20= BUY");

  //    if(PClose1 <= PLowest_c)
       
   //if(PClose1 <= PLowest_c150 ||PClose1 <= PLowest_c100 ||PClose1 <= PLowest_c50  )
     
  //   if  ( EMA5 > EMA10 && MACD_1 >0  && EMA5 > EMA75  && Hour() >=0 && Hour() < 23 && Openorder && Openbuyandsell && PClose1 > EMA50 &&   Period()== PERIOD_H1  )
     
    //  if  ( EMA5_0 > EMA5_2 && MACD_1 >0 && PClose1 > EMA200    && Hour() >=0 && Hour() < 23 && Openorder && Openbuyandsell && PClose1 > POpen1 && Vol_1 > Vol_2 && Vol_1 > Vol_3 &&  Vol_1 > VMA200 )// for uptrend down trend
   
   
//  if   ( (  MACD_1 > 0 && Openorder && Openbuyandsell )&& Hour() >=0 && Hour() < 23  &&  ( (PClose1 <= EMA20) || (PClose1 <= EMA10) || (PClose1 <= EMA5)) )// ORiginal condition
   
   
   // if   (/*  MACD_1 > MACD_S && */ Openorder && Openbuyandsell==1 && Hour() >=0 && Hour() < 23 && POpen1 > POpen2 && PClose1 > PClose2 && PLow1 > PLow2 && PHigh1 > PHigh2  )// // Heiken ahi
   
      if   (  MACD_1 > MACD_S &&  HACLOSE_1 > HAOPEN_1 )// // Heiken ahi open close
   
   
  // if   ( (  Openorder && Openbuyandsell )&& PClose1 > POpen1 &&  Vol_1 > VMA200 && Hour() >=0 && Hour() < 23 &&  ( (PClose2 <= EMA200) || (PClose2 <= EMA50)|| (PClose2 <= EMA10) ) )  // price and volume analysis

    {
    //  double slb=Ask-SL*Point;
   
   //   double tpb=Ask+TP*Point;
   
   double ATRstoploss=Ask-ATR;//atr
    double ATRtakeprofit=Ask+ATR; // TP percentage
   
   double stoploss=Ask*0.99800;   // SL percentage   
        double takeprofit=Ask*1.01200; // TP percentage
     
      double sl=Ask-(PHighest-PLowest)/2;
     double tp=Ask+(PHighest-PLowest)*1.236  ;
     
        //---- open a BUY positiont
        if ( OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,0 ,0 , "H1 Tfex",
              Expert_ID, 0, Green ) < 0 )
        {
            _GetLastError = GetLastError();
           // Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
   
   
   
   }
 
   // if( PClose1 < EMA20  && Period()==1440   ) int S=1;
   
    /////////////////// open a SELL position///////////////////
   
//  if( PClose1 < EMA20)
{
// Print("PClose1 < EMA20 = SELL");
   // if(PClose1 >= PHighest_c)
   
  //    if(PClose1 >= PHighest_c150||PClose1 >= PHighest_c100||PClose1 >= PHighest_c50 )
 
   
// if ( EMA5<  EMA10 && MACD_1 <0 && EMA5 < EMA75  && Hour() >=0 && Hour()< 23 && Openorder && Openbuyandsell  && PClose1 < EMA50 &&   Period()== PERIOD_H1 )
 
//  if ( EMA5_0 <  EMA5_2 && MACD_1 < 0   && PClose1 < EMA200 && Hour() >=0 && Hour()< 23 && Openorder && Openbuyandsell && PClose1 < POpen1 && Vol_1 > Vol_2 && Vol_1 > Vol_3 &&  Vol_1 > VMA200 )// for uptrend down trend

 
  // if ( (     MACD_1 < 0 && Openorder && Openbuyandsell ) && Hour() >=0 && Hour() < 23  &&   (( PClose1 >= EMA20 ) ||  ( PClose1 >= EMA10 ) ||  ( PClose1 >= EMA5 )) ) // Origianl condition
   
   
   // if ( /*    MACD_1 < MACD_S && */ Openorder && Openbuyandsell==1  && Hour() >=0 && Hour() < 23  && POpen1 < POpen2 &&  PClose1 < PClose2 && PLow1 < PLow2 && PHigh1 < PHigh2) // Heiken ahi
   
       if ( MACD_1 < MACD_S &&  HAOPEN_1 > HACLOSE_1) // Heiken ahi
   
   
   
//   if ( ( Openorder && Openbuyandsell )&& PClose1 < POpen1 && Vol_1 > VMA200 && Hour() >=0 && Hour() < 23 &&  (( PClose2 >= EMA200 ) ||  ( PClose2 >= EMA10 )||  ( PClose2 >= EMA50 )) ) // price and volume condition
   
    {
   
   // double sls=Bid+SL*Point;
    //  double tps=Bid-TP*Point;
   
     double ATRstop=Bid+ATR;
      double ATRtake=Bid-ATR;
   
     double stop=Bid*1.00200;
     double take=Bid*0.98800;
     
       double s=Bid+(PHighest-PLowest)/2;
      double t=Bid-(PHighest-PLowest)*1.236;
     
        //---- open a SELL position
        if ( OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,0 ,0, "H1 Tfex",
              Expert_ID, 0, Red ) < 0 )
        {
            _GetLastError = GetLastError();
          //  Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
   
    }

    return(0);
}

บจก.สยามเอวีเอส
63 Moo 2 แพรกษาใหม่ เมือง สมุทรปราการ
นำเข้า-จำหน่าย เครื่องจักร cnc มือสองญี่ปุ่น
ติดต่อ คุณ ธนเดช  084-387-2401
EMAIL kiattub@gmail.com
คลิกลิ้งแอดไลน์ได้เลย Line id : boysiamavs
http://line.me/ti/p/~boysiamavs