Re: รูปแบบราคาหุ้น Price pattern เทคนิคคอล

เริ่มโดย admin, ตุลาคม 22, 2016, 09:23:20 AM

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

admin

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

    

admin

extern int Expert_ID = 777;//
extern double Lot = 1; // 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;
extern double Gap = 0.02 ; // gap up and down 2%
extern double TrailingStop =0;// for time frame M1
extern double Shiftbackopenorder=26;
extern double shiftbackbar=120;


//  close all code //


extern int    ProfitTarget     =100000;             // 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)
//extern int    LossTarget     = -1000;               // must be -400 only stop loss USD
extern bool   CloseAllNow      = false;          // closes all orders now//
//extern bool   CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount      = 1;     // Only trades above this amount close out
//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 (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;
   
//  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");









//+------------------------------------------------------------------+
//  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();
   
   
   
   
   
    //closed all time 13.00-20.00
   
  //  if( Hour()==20 && Minute()==40 && DayOfWeek()==5 ) CloseAll();
   
    Print ( "Close all = every friday 20:40 ");
   
//  if(  Hour()>20 || ( Hour() >=0 && Hour() < 6  ) || ( Hour() >9 && Hour()<12 ) ) CloseAll();
   
 
   
   // if(CloseProfitableTradesOnly) CloseAllinProfit();
   
  if(BuyProfit+SellProfit >= ProfitTarget  ) CloseAll();
   
//  if(BuyProfit+SellProfit <=  LossTarget  ) CloseAll();
   
   // if(ClosePendingOnly) ClosePendingOrdersOnly();
   
   
 
   
//   Print ( "ProfitTarget =  ",ProfitTarget);
   
    //Print ( "LossTarget =  ",LossTarget);
   
   // Print ( "Ordertotal =  ",OrdersTotal());
   
// Print ( "Minute =  ",Minute());
   
   
   
   
   
   //  if ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 , 0 , "Exness", 2, 0, Green );}   
  //  if ((BuyProfit+SellProfit) >= Profit2 && OrdersTotal() ==2  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 3, 0, Green );}
   // if ((BuyProfit+SellProfit) >= Profit3 && OrdersTotal() ==3  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 4, 0, Green );}
     // if ((BuyProfit+SellProfit) >= Profit4 && OrdersTotal() ==4  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 5, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit5 && OrdersTotal() ==5  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness",6, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit6 && OrdersTotal() ==6  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 7, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit7 && OrdersTotal() ==7  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 8, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit8 && OrdersTotal() ==8  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 9, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit9 && OrdersTotal() ==9  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 10, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit10 && OrdersTotal() ==10  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 11, 0, Green );}
     
   
     //   if((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 )  { OrderSend (Symbol(), OP_SELL, Lot, Bid, 5,0 , 0 , "Exness", 2, 0, Green );} 
      //  if( (BuyProfit+SellProfit) >= Profit2 && OrdersTotal() == 2 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 3, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit3 && OrdersTotal() == 3 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 4, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit4 && OrdersTotal() == 4 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 5, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit5 && OrdersTotal() == 5 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 6, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit6 && OrdersTotal() == 6 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 7, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit7 && OrdersTotal() == 7 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 8, 0, Green );}
    //   if( (BuyProfit+SellProfit) >= Profit8 && OrdersTotal() == 8 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 9, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit9 && OrdersTotal() == 9 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 10, 0, Green );}
    //   if( (BuyProfit+SellProfit) >= Profit10 && OrdersTotal() == 10 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 11, 0, Green );}
       
       
/////  close all code///   





    //---- 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 MACD_1 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1 );
    double MACD_2 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 2 );
  double   Mamain=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0);
double     Masignal=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);



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   Ma200=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,0);
  double   Ma201=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,1);
  double   Ma202=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,2);
  double   Ma203=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,3);

  double  Stomain=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,0);
  double  Stomain1=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,1);
  double  Stomain2=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,2);
   double  Stomain3=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,3);
   
 
  double Bolingermain = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0);
  double Bolingerlower = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
  double Bolingerupper  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
 
  double Bolingermain90 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,BBback);
  double Bolingerlower90 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,BBback);
  double Bolingerupper90  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,BBback);
 
 
 
   double Bolingermain1 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,1);
  double Bolingerlower1 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
  double Bolingerupper1  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
 
  //  Print("Bolingermain=",Bolingermain);
  //  Print("Bolingerlower=",Bolingerlower);
   //   Print("Bolingerupper=",Bolingerupper);
   Print("DayOfWeek()=",DayOfWeek()  );
   
     
     
 
   
       double   Ma1=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,0);
//  double   Maback200=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingback200);
// double   Maback100=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingback100);
 
  double   Mabackopen=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingbackvaryopen);
     double   Mabackclose=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingbackvaryclose);
     
double    Stosignal=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,0);
double    Stosignal1=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,1);
double    Stosignal2=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,2);

double   Macd=iMACD(NULL,0,12,26,3,PRICE_CLOSE,MODE_MAIN,0);
double   Macdsi=iMACD(NULL,0,12,26,3,PRICE_CLOSE,MODE_SIGNAL,0);

*/

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



  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  POpen1=iOpen(NULL,0,1);
double  POpen2=iOpen(NULL,0,2);
  double  POpen3=iOpen(NULL,0,3);

double PLow1= iLow(NULL,0,1);
double PLow2= iLow(NULL,0,2);
  double PLow3= iLow(NULL,0,3);

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



// Print("PClose1=",PClose1);
//Print("PLow1=",PLow1);
  //Print("PHigh1=",PHigh1);


 
int BarHighest = iHighest(NULL,0,MODE_HIGH,Shiftbackopenorder,0);
  int BariLowest = iLowest(NULL,0,MODE_LOW,Shiftbackopenorder,0); 
   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);

  int BarHighestdays = iHighest(NULL,0,MODE_HIGH,shiftbackbar,0);
  int BarLowestdays = iLowest(NULL,0,MODE_LOW,shiftbackbar,0); 
   double  PLowestdays=iLow(NULL,0,BarLowestdays);
double  PHighestdays=iHigh(NULL,0,BarHighestdays);

/*

  double  PLow2=iLow(NULL,0,2);
  double  PHigh2=iHigh(NULL,0,2);

double  PLow1=iLow(NULL,0,1);
  double  PHigh1=iHigh(NULL,0,1);
 
  double  PLow0=iLow(NULL,0,0);
  double  PHigh0=iHigh(NULL,0,0);
 
    double  PLow15=iLow(NULL,0,15);
  double  PHigh15=iHigh(NULL,0,15);
 
    double  PLow60=iLow(NULL,0,60);
  double  PHigh60=iHigh(NULL,0,60);

*/

// Print("PHighest=",PHighest);
// Print("PLowest=",PLowest);
 
   
 
// double roundhihg = MathRound(PHigh   );
 
// Print("roundhihg=",roundhihg);

//  Print("Hour=",Hour());
 
//  Print ( "Minute =  ",Minute());
 
//  Print("Trading Hour= 13.00-19.00");

 
 
 






// double atr=iATR(Symbol(),1,30,0);
   

    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(Ma12 < Ma26)
             
           //  if(PClose0 <= PLowestdays)
           
       //  if  ( Pricehigh1 >= Bolingerupper1 && PClose0 <= Bolingerupper )
           
       //  if  ( PHigh0 >= PHighest)
         
       //  if  ( PClose0 >= Bolingerupper)
           
           //if ( Ma1 > PClose0 && Ma1  > PClose1 && Stomain1 > 80  /*&& Ma1 < Mabackopen   && (Hour()>=11 && Hour()<=17)*/ )
           
          //  if (  Ask==0 /*(Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackclose  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Mabackclose   )*/ )
           
           // if ( Stomain1 > 81 && Stomain < 80 )
           
         //  if ( (Stomain1 > 80 && Stomain < 79 && Ma1 < Maback200 && Maback100 < Maback200  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Maback200 && Maback100 < Maback200  ))
            {
                //---- 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(Ma12 > Ma26)
             
            //   if(PClose0 >= PHighestdays)
           
    //  if (Pricelow1 <= Bolingerlower1 && PClose0 >= Bolingerlower  ) 
         
//if (PLow0 <= PLowest  )
     
   //  if (PClose0 <= Bolingerlower  )
           
           
         //  if  ( PClose0 > Ma1 && PClose1 > Ma1 && Stomain1 < 20 /*&& Ma1 > Mabackopen     && (Hour()>=11 && Hour()<=17)*/ )
           
        //    if   (   Ask==0 /*(Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackclose  )|| (Stomain1 < 80 && Stomain > 81 && Ma1 > Mabackclose  )*/ )
           
          //  if (  Stomain1 < 19 && Stomain > 20  )
         
        //   if   ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Maback200 && Maback100 > Maback200 ) || (Stomain1 < 80 && Stomain > 81 && Ma1 > Maback200 && Maback100 > Maback200  ))
            {
                //---- 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  ( ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Maback200 && Maback100 > Maback200 ) || (Stomain1 < 80 && Stomain > 81 && Ma1 > Maback200 && Maback100 > Maback200  )) && (  (Hour()>=12 && Hour()<=16)  || (Hour()>=6 && Hour()<=10)  ) && OrdersTotal() == 0 )
 
  // if  ( PClose0 > Ma1 && PClose1 > Ma1 && Stomain1 < 20/*&& Ma1 > Mabackopen     && (Hour()>=11 && Hour()<=17)*/ )
 
// if  ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen  )  || ( Stomain1 < 80 && Stomain > 81 && Ma1 > Mabackopen  ) 
   
//    || ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0  && Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen )
   
  // || ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 2 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0  && Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen ) )
   
  // if (   PLow2 <= Bolingerlower1 && PLow1 >= Bolingerlower1 && PLow0 >= Bolingerlower1  && Bolingerlower >= Bolingerlower90 )
 
 
//  if ( (Pricelow1 <= Bolingerlower1 && PClose0 >= Bolingerlower )  || (PClose1 <= Bolingermain1 && PClose0 >= Bolingermain) )

     //if( ( PLow2 <= PLowest && PLow15 > PLowest && PLow0 > PLowest) || (PClose0 >= PHighest))
     
    // if (  PClose0 >= PHighest  /*&& ( (Hour()>=13 && Hour()<20) )*/ )
     
     // if(    PClose0 >= PHighest &&  Ma12 > Ma26 && (BuyProfit+SellProfit) >= 0)
     
      if( PClose3 < Ma26 && POpen3 > PClose3 && (PClose3- POpen2 )> POpen3*Gap && POpen2 < POpen3 && POpen2 > PClose2 && (POpen1 - POpen2)> POpen2*Gap && POpen1 < PClose2)
     
    //   if  (        (  (PHigh15 >= PHighest && PClose0 >PHighest ) ||  ( PLow15 <= PLowest && PClose0 > PLowest)  )    && ( (Hour()>=12 && Hour()<=20) )  )
   
    {
    //  double slb=Ask-SL*Point;
   
   //   double tpb=Ask+TP*Point;
     
      double sl=Ask-(PHighest-PLowest);
     double tp=Ask+(PHighest-PLowest)  ;
     
        //---- open a BUY positiont
        if ( OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,0 , 0 , "XM",
              Expert_ID, 0, Green ) < 0 )
        {
            _GetLastError = GetLastError();
           // Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
    //---- open a SELL position
   
   // if (( (Stomain1 > 80 && Stomain < 79 && Ma1 < Maback200 && Maback100 < Maback200  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Maback200 && Maback100 < Maback200  )) && (  (Hour()>=12 && Hour()<=16)  || (Hour()>=6 && Hour()<=10)  ) && OrdersTotal() == 0   )
   
//   if ( Ma1 > PClose0 && Ma1  > PClose1 && Stomain1 > 80 /*&& Ma1 < Mabackopen  && (Hour()>=11 && Hour()<=17)*/ )
   
 
//  if ( ( Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen )  || ( Stomain1 > 20 && Stomain < 19 && Ma1 < Mabackopen ) 
   
  // ||((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_SELL  && OrderSymbol() == Symbol() && SellProfit > 0  && Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen )
   
  // ||((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 2 && OrderType() == OP_SELL  && OrderSymbol() == Symbol() && SellProfit > 0  && Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen ) )
   
// if  (    PHigh2 >= Bolingerupper1  && PHigh1 <= Bolingerupper1 && PHigh0 <= Bolingerupper1  && Bolingerupper <= Bolingerupper90 )
   
// if  ( ( Pricehigh1 >= Bolingerupper1 && PClose0 <= Bolingerupper )     || (PClose1 >= Bolingermain1 && PClose0 <= Bolingermain) )
 
 
// if (( PHigh2 >= PHighest && PHigh15 < PHighest && PHigh0 < PHighest )|| (PClose0 <= PLowest))

//  if (PClose0 <= PLowest /*&& ( (Hour()>=13 && Hour()<20) ) */)
   
   //if(  PClose0 <= PLowest   &&  Ma12 < Ma26 && (BuyProfit+SellProfit) >= 0)
   
   if ( PClose3 > Ma26 && PClose3 > POpen3 && POpen2 > PClose3 && POpen2 <PClose2 && (PClose2-POpen1)>PClose2*Gap && POpen1< PClose1 && (POpen2-PClose3)> PClose3*Gap)
   
  //  if (  ((PLow15 <= PLowest  && PClose0 < PLowest)  || ( PHigh15 >= PHighest  && PClose0 < PHighest ) )   && (Hour()>=12 && Hour()<=20) )
   
    {
   
   // double sls=Bid+SL*Point;
    //  double tps=Bid-TP*Point;
     
       double s=Bid+(PHighest-PLowest);
      double t=Bid-(PHighest-PLowest);
     
        //---- open a SELL position
        if ( OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,0 , 0, "XM",
              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

    

admin

extern int Expert_ID = 69;//
extern double Lot = 0.01; // 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;
extern double TrailingStop =0;// for time frame M1
extern double Shiftbackopenorder=26;// for daily
extern double shiftbackbar=26;


//  close all code //


extern int    ProfitTarget     =100000;             // 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)
//extern int    LossTarget     = -1000;               // must be -400 only stop loss USD
extern bool   CloseAllNow      = false;          // closes all orders now//
//extern bool   CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount      = 1;     // Only trades above this amount close out
//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 (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;
   
//  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");









//+------------------------------------------------------------------+
//  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 && OrdersTotal() >3 ) CloseAll();
   
   
   
   
   
    //closed all time 13.00-20.00
   
  //  if( Hour()==20 && Minute()==40 && DayOfWeek()==5 ) CloseAll();
   
    Print ( "Close all = every friday 20:40 ");
   
//  if(  Hour()>20 || ( Hour() >=0 && Hour() < 6  ) || ( Hour() >9 && Hour()<12 ) ) CloseAll();
   
 
   
   // if(CloseProfitableTradesOnly) CloseAllinProfit();
   
  if(BuyProfit+SellProfit >= ProfitTarget  ) CloseAll();
   
//  if(BuyProfit+SellProfit <=  LossTarget  ) CloseAll();
   
   // if(ClosePendingOnly) ClosePendingOrdersOnly();
   
   
 
   
//   Print ( "ProfitTarget =  ",ProfitTarget);
   
    //Print ( "LossTarget =  ",LossTarget);
   
   // Print ( "Ordertotal =  ",OrdersTotal());
   
// Print ( "Minute =  ",Minute());
   
   
   
   
   
   //  if ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 , 0 , "Exness", 2, 0, Green );}   
  //  if ((BuyProfit+SellProfit) >= Profit2 && OrdersTotal() ==2  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 3, 0, Green );}
   // if ((BuyProfit+SellProfit) >= Profit3 && OrdersTotal() ==3  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 4, 0, Green );}
     // if ((BuyProfit+SellProfit) >= Profit4 && OrdersTotal() ==4  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 5, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit5 && OrdersTotal() ==5  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness",6, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit6 && OrdersTotal() ==6  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 7, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit7 && OrdersTotal() ==7  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 8, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit8 && OrdersTotal() ==8  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 9, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit9 && OrdersTotal() ==9  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 10, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit10 && OrdersTotal() ==10  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 11, 0, Green );}
     
   
     //   if((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 )  { OrderSend (Symbol(), OP_SELL, Lot, Bid, 5,0 , 0 , "Exness", 2, 0, Green );} 
      //  if( (BuyProfit+SellProfit) >= Profit2 && OrdersTotal() == 2 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 3, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit3 && OrdersTotal() == 3 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 4, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit4 && OrdersTotal() == 4 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 5, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit5 && OrdersTotal() == 5 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 6, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit6 && OrdersTotal() == 6 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 7, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit7 && OrdersTotal() == 7 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 8, 0, Green );}
    //   if( (BuyProfit+SellProfit) >= Profit8 && OrdersTotal() == 8 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 9, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit9 && OrdersTotal() == 9 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 10, 0, Green );}
    //   if( (BuyProfit+SellProfit) >= Profit10 && OrdersTotal() == 10 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 11, 0, Green );}
       
       
/////  close all code///   





    //---- 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 MACD_1 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1 );
    double MACD_2 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 2 );
  double   Mamain=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0);
double     Masignal=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);

/*
double   Ma200=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,0);
  double   Ma201=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,1);
  double   Ma202=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,2);
  double   Ma203=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,3);

  double  Stomain=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,0);
  double  Stomain1=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,1);
  double  Stomain2=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,2);
   double  Stomain3=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,3);
   
 
  double Bolingermain = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0);
  double Bolingerlower = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
  double Bolingerupper  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
 
  double Bolingermain90 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,BBback);
  double Bolingerlower90 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,BBback);
  double Bolingerupper90  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,BBback);
 
 
 
   double Bolingermain1 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,1);
  double Bolingerlower1 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
  double Bolingerupper1  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
 
  //  Print("Bolingermain=",Bolingermain);
  //  Print("Bolingerlower=",Bolingerlower);
   //   Print("Bolingerupper=",Bolingerupper);
   Print("DayOfWeek()=",DayOfWeek()  );
   
     
     
 
   
       double   Ma1=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,0);
//  double   Maback200=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingback200);
// double   Maback100=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingback100);
 
  double   Mabackopen=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingbackvaryopen);
     double   Mabackclose=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingbackvaryclose);
     
double    Stosignal=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,0);
double    Stosignal1=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,1);
double    Stosignal2=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,2);

double   Macd=iMACD(NULL,0,12,26,3,PRICE_CLOSE,MODE_MAIN,0);
double   Macdsi=iMACD(NULL,0,12,26,3,PRICE_CLOSE,MODE_SIGNAL,0);

*/

// hihest lowest data
 
    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 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  POpen1=iOpen(NULL,0,1);
double  POpen2=iOpen(NULL,0,2);
  double  POpen3=iOpen(NULL,0,3);

double PLow1= iLow(NULL,0,1);
double PLow2= iLow(NULL,0,2);
  double PLow3= iLow(NULL,0,3);

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

double hard =2*(POpen1-PClose1);

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

//fibonanci
double fibo0 =PLowest;
double fibo23= PHighest- (PHighest-PLowest)*23.6/100;
double fibo38=PHighest-(PHighest-PLowest)*38.2/100;
double fibo50=PHighest-(PHighest-PLowest)*50/100;
double fibo61=PHighest-(PHighest-PLowest)*61.8/100;
double fibo76=PHighest-(PHighest-PLowest)*76.4/100;
double fibo100=PHighest;
  double fibo123=PHighest-(PHighest-PLowest)*123.6/100;
  double fibo200=PHighest-(PHighest-PLowest)*200/100;
 
 
   double fibo20=PHighest+(PHighest-PLowest)*200/100;
   double fibo15=PHighest+(PHighest-PLowest)*150/100;
   double fibo168=PHighest+(PHighest-PLowest)*168/100;
 
 
//  Print("fibo0=",fibo0);
//  Print("fibo50=",fibo50);
  //  Print("fibo100=",fibo100);
  // Print("fibo123=",fibo123);
  // Print("fibo200=",fibo200);



  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);

  int BarHighestdays = iHighest(NULL,0,MODE_HIGH,shiftbackbar,0);
  int BarLowestdays = iLowest(NULL,0,MODE_LOW,shiftbackbar,0); 
   double  PLowestdays=iLow(NULL,0,BarLowestdays);
double  PHighestdays=iHigh(NULL,0,BarHighestdays);




 
// double roundhihg = MathRound(PHigh   );
 
// Print("roundhihg=",roundhihg);

//  Print("Hour=",Hour());
 
//  Print ( "Minute =  ",Minute());
 
//  Print("Trading Hour= 13.00-19.00");

 
 
 






// double atr=iATR(Symbol(),1,30,0);
   

    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  ( Pricehigh1 >= Bolingerupper1 && PClose0 <= Bolingerupper )
           
       //  if  ( PHigh0 >= PHighest)
         
       //  if  ( PClose0 >= Bolingerupper)
           
           //if ( Ma1 > PClose0 && Ma1  > PClose1 && Stomain1 > 80  /*&& Ma1 < Mabackopen   && (Hour()>=11 && Hour()<=17)*/ )
           
          //  if (  Ask==0 /*(Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackclose  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Mabackclose   )*/ )
           
           // if ( Stomain1 > 81 && Stomain < 80 )
           
         //  if ( (Stomain1 > 80 && Stomain < 79 && Ma1 < Maback200 && Maback100 < Maback200  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Maback200 && Maback100 < Maback200  ))
            {
                //---- 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 (Pricelow1 <= Bolingerlower1 && PClose0 >= Bolingerlower  ) 
         
//if (PLow0 <= PLowest  )
     
   //  if (PClose0 <= Bolingerlower  )
           
           
         //  if  ( PClose0 > Ma1 && PClose1 > Ma1 && Stomain1 < 20 /*&& Ma1 > Mabackopen     && (Hour()>=11 && Hour()<=17)*/ )
           
        //    if   (   Ask==0 /*(Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackclose  )|| (Stomain1 < 80 && Stomain > 81 && Ma1 > Mabackclose  )*/ )
           
          //  if (  Stomain1 < 19 && Stomain > 20  )
         
        //   if   ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Maback200 && Maback100 > Maback200 ) || (Stomain1 < 80 && Stomain > 81 && Ma1 > Maback200 && Maback100 > Maback200  ))
            {
                //---- 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  ( ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Maback200 && Maback100 > Maback200 ) || (Stomain1 < 80 && Stomain > 81 && Ma1 > Maback200 && Maback100 > Maback200  )) && (  (Hour()>=12 && Hour()<=16)  || (Hour()>=6 && Hour()<=10)  ) && OrdersTotal() == 0 )
 
  // if  ( PClose0 > Ma1 && PClose1 > Ma1 && Stomain1 < 20/*&& Ma1 > Mabackopen     && (Hour()>=11 && Hour()<=17)*/ )
 
// if  ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen  )  || ( Stomain1 < 80 && Stomain > 81 && Ma1 > Mabackopen  ) 
   
//    || ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0  && Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen )
   
  // || ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 2 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0  && Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen ) )
   
  // if (   PLow2 <= Bolingerlower1 && PLow1 >= Bolingerlower1 && PLow0 >= Bolingerlower1  && Bolingerlower >= Bolingerlower90 )
 
//  if ( (Pricelow1 <= Bolingerlower1 && PClose0 >= Bolingerlower )  || (PClose1 <= Bolingermain1 && PClose0 >= Bolingermain) )

     //if( ( PLow2 <= PLowest && PLow15 > PLowest && PLow0 > PLowest) || (PClose0 >= PHighest))
     
     
 
     
    if ( ( POpen2 < PClose2 && POpen1 > PClose2*1.02 && POpen1 < PClose1 )    && (BuyProfit+SellProfit) >= 0  ) // gap buy
   
     
    //   if  (        (  (PHigh15 >= PHighest && PClose0 >PHighest ) ||  ( PLow15 <= PLowest && PClose0 > PLowest)  )    && ( (Hour()>=12 && Hour()<=20) )  )
   
    {
    //  double slb=Ask-SL*Point;
   
   //   double tpb=Ask+TP*Point;
     
      double sl=Ask-(PHighest-PLowest)/3;
     double tp=Ask+(PHighest-PLowest)  ;
     
        //---- open a BUY positiont
        if ( OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,sl ,tp , "xm",
              Expert_ID, 0, Green ) < 0 )
        {
            _GetLastError = GetLastError();
           // Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
    //---- open a SELL position
   
   // if (( (Stomain1 > 80 && Stomain < 79 && Ma1 < Maback200 && Maback100 < Maback200  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Maback200 && Maback100 < Maback200  )) && (  (Hour()>=12 && Hour()<=16)  || (Hour()>=6 && Hour()<=10)  ) && OrdersTotal() == 0   )
   
//   if ( Ma1 > PClose0 && Ma1  > PClose1 && Stomain1 > 80 /*&& Ma1 < Mabackopen  && (Hour()>=11 && Hour()<=17)*/ )
   
 
//  if ( ( Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen )  || ( Stomain1 > 20 && Stomain < 19 && Ma1 < Mabackopen ) 
   
  // ||((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_SELL  && OrderSymbol() == Symbol() && SellProfit > 0  && Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen )
   
  // ||((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 2 && OrderType() == OP_SELL  && OrderSymbol() == Symbol() && SellProfit > 0  && Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen ) )
   
// if  (    PHigh2 >= Bolingerupper1  && PHigh1 <= Bolingerupper1 && PHigh0 <= Bolingerupper1  && Bolingerupper <= Bolingerupper90 )
   
// if  ( ( Pricehigh1 >= Bolingerupper1 && PClose0 <= Bolingerupper )     || (PClose1 >= Bolingermain1 && PClose0 <= Bolingermain) )
 
 
// if (( PHigh2 >= PHighest && PHigh15 < PHighest && PHigh0 < PHighest )|| (PClose0 <= PLowest))

 
   if ( ( POpen2 > PClose2 && POpen1 < PClose2*0.98  && POpen1 > PClose1 )   && (BuyProfit+SellProfit) >= 0  ) // gaps sell
   
  //  if (  ((PLow15 <= PLowest  && PClose0 < PLowest)  || ( PHigh15 >= PHighest  && PClose0 < PHighest ) )   && (Hour()>=12 && Hour()<=20) )
   
    {
   
   // double sls=Bid+SL*Point;
    //  double tps=Bid-TP*Point;
     
       double s=Bid+(PHighest-PLowest)/3;
      double t=Bid-(PHighest-PLowest);
     
        //---- open a SELL position
        if ( OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,s , t, "xm",
              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

    

admin

extern int Expert_ID = 777;//
extern double Lot = 0.01; // 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;
extern double Gap = 0.02 ; // gap up and down 2%
extern double TrailingStop =0;// for time frame M1
extern double Shiftbackopenorder=26;
extern double shiftbackbar=26;


//  close all code //


extern int    ProfitTarget     =100000;             // 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)
//extern int    LossTarget     = -1000;               // must be -400 only stop loss USD
extern bool   CloseAllNow      = false;          // closes all orders now//
//extern bool   CloseProfitableTradesOnly = false; // closes only profitable trades
extern double ProftableTradeAmount      = 1;     // Only trades above this amount close out
//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 (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;
   
//  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");









//+------------------------------------------------------------------+
//  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();
   
   
   
   
   
    //closed all time 13.00-20.00
   
  //  if( Hour()==20 && Minute()==40 && DayOfWeek()==5 ) CloseAll();
   
//   Print ( "Close all = every friday 20:40 ");
   
//  if(  Hour()>20 || ( Hour() >=0 && Hour() < 6  ) || ( Hour() >9 && Hour()<12 ) ) CloseAll();
   
 
   
   // if(CloseProfitableTradesOnly) CloseAllinProfit();
   
  if(BuyProfit+SellProfit >= ProfitTarget  ) CloseAll();
   
//  if(BuyProfit+SellProfit <=  LossTarget  ) CloseAll();
   
   // if(ClosePendingOnly) ClosePendingOrdersOnly();
   
   
 
   
//   Print ( "ProfitTarget =  ",ProfitTarget);
   
    //Print ( "LossTarget =  ",LossTarget);
   
   // Print ( "Ordertotal =  ",OrdersTotal());
   
// Print ( "Minute =  ",Minute());
   
   
   
   
   
   //  if ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 , 0 , "Exness", 2, 0, Green );}   
  //  if ((BuyProfit+SellProfit) >= Profit2 && OrdersTotal() ==2  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 3, 0, Green );}
   // if ((BuyProfit+SellProfit) >= Profit3 && OrdersTotal() ==3  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 4, 0, Green );}
     // if ((BuyProfit+SellProfit) >= Profit4 && OrdersTotal() ==4  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 5, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit5 && OrdersTotal() ==5  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness",6, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit6 && OrdersTotal() ==6  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 7, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit7 && OrdersTotal() ==7  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 8, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit8 && OrdersTotal() ==8  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 9, 0, Green );}
    //  if ((BuyProfit+SellProfit) >= Profit9 && OrdersTotal() ==9  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 10, 0, Green );}
   //   if ((BuyProfit+SellProfit) >= Profit10 && OrdersTotal() ==10  && OrderType() == OP_BUY  && OrderSymbol() == Symbol()&& BuyProfit > 0 )  { OrderSend (Symbol(), OP_BUY, Lot, Ask, 5, 0 ,0 , "Exness", 11, 0, Green );}
     
   
     //   if((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 )  { OrderSend (Symbol(), OP_SELL, Lot, Bid, 5,0 , 0 , "Exness", 2, 0, Green );} 
      //  if( (BuyProfit+SellProfit) >= Profit2 && OrdersTotal() == 2 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 3, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit3 && OrdersTotal() == 3 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 4, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit4 && OrdersTotal() == 4 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 5, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit5 && OrdersTotal() == 5 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 6, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit6 && OrdersTotal() == 6 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 7, 0, Green );}
      //  if( (BuyProfit+SellProfit) >= Profit7 && OrdersTotal() == 7 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 8, 0, Green );}
    //   if( (BuyProfit+SellProfit) >= Profit8 && OrdersTotal() == 8 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 9, 0, Green );}
     //  if( (BuyProfit+SellProfit) >= Profit9 && OrdersTotal() == 9 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 10, 0, Green );}
    //   if( (BuyProfit+SellProfit) >= Profit10 && OrdersTotal() == 10 && OrderType() == OP_SELL  && OrderSymbol() == Symbol()&& SellProfit > 0 ){ OrderSend (Symbol(), OP_SELL, Lot, Bid, 5, 0 , 0 , "Exness", 11, 0, Green );}
       
       
/////  close all code///   





    //---- 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 MACD_1 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1 );
    double MACD_2 = iMACD( Symbol(), 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 2 );
  double   Mamain=iMA(NULL,0,10,0,MODE_SMA,PRICE_CLOSE,0);
double     Masignal=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);



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   Ma200=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,0);
  double   Ma201=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,1);
  double   Ma202=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,2);
  double   Ma203=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,3);

  double  Stomain=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,0);
  double  Stomain1=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,1);
  double  Stomain2=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,2);
   double  Stomain3=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_MAIN,3);
   
 
  double Bolingermain = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,0);
  double Bolingerlower = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
  double Bolingerupper  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
 
  double Bolingermain90 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,BBback);
  double Bolingerlower90 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,BBback);
  double Bolingerupper90  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,BBback);
 
 
 
   double Bolingermain1 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_MAIN,1);
  double Bolingerlower1 = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
  double Bolingerupper1  = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
 
  //  Print("Bolingermain=",Bolingermain);
  //  Print("Bolingerlower=",Bolingerlower);
   //   Print("Bolingerupper=",Bolingerupper);
   Print("DayOfWeek()=",DayOfWeek()  );
   
     
     
 
   
       double   Ma1=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,0);
//  double   Maback200=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingback200);
// double   Maback100=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingback100);
 
  double   Mabackopen=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingbackvaryopen);
     double   Mabackclose=iMA(NULL,0,MAperiod,0,MODE_SMA,PRICE_CLOSE,Movingbackvaryclose);
     
double    Stosignal=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,0);
double    Stosignal1=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,1);
double    Stosignal2=iStochastic(NULL,0,K,D,Slow,MODE_EMA,0,MODE_SIGNAL,2);

double   Macd=iMACD(NULL,0,12,26,3,PRICE_CLOSE,MODE_MAIN,0);
double   Macdsi=iMACD(NULL,0,12,26,3,PRICE_CLOSE,MODE_SIGNAL,0);

*/

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



  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  POpen1=iOpen(NULL,0,1);
double  POpen2=iOpen(NULL,0,2);
  double  POpen3=iOpen(NULL,0,3);

double PLow1= iLow(NULL,0,1);
double PLow2= iLow(NULL,0,2);
  double PLow3= iLow(NULL,0,3);

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

double hard =2*(POpen1-PClose1);

// Print(" (PHigh1 -POpen1)=", (PHigh1 -POpen1));

//Print(" (POpen1-PClose1)*2=", hard);

// double tt =2*(POpen1-PClose1);

//Print("POpen3*0.98=",POpen3*0.98);
// Print("POpen2=",POpen2);

 
//  (PClose3- POpen2 )> POpen3*Gap
// (PHigh1 -POpen1)> 2*(POpen1-PClose1)


 
int BarHighest = iHighest(NULL,0,MODE_HIGH,Shiftbackopenorder,0);
  int BariLowest = iLowest(NULL,0,MODE_LOW,Shiftbackopenorder,0); 
   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);

  int BarHighestdays = iHighest(NULL,0,MODE_HIGH,shiftbackbar,0);
  int BarLowestdays = iLowest(NULL,0,MODE_LOW,shiftbackbar,0); 
   double  PLowestdays=iLow(NULL,0,BarLowestdays);
double  PHighestdays=iHigh(NULL,0,BarHighestdays);

/*

  double  PLow2=iLow(NULL,0,2);
  double  PHigh2=iHigh(NULL,0,2);

double  PLow1=iLow(NULL,0,1);
  double  PHigh1=iHigh(NULL,0,1);
 
  double  PLow0=iLow(NULL,0,0);
  double  PHigh0=iHigh(NULL,0,0);
 
    double  PLow15=iLow(NULL,0,15);
  double  PHigh15=iHigh(NULL,0,15);
 
    double  PLow60=iLow(NULL,0,60);
  double  PHigh60=iHigh(NULL,0,60);

*/

// Print("PHighest=",PHighest);
// Print("PLowest=",PLowest);
 
   
 
// double roundhihg = MathRound(PHigh   );
 
// Print("roundhihg=",roundhihg);

//  Print("Hour=",Hour());
 
//  Print ( "Minute =  ",Minute());
 
//  Print("Trading Hour= 13.00-19.00");

 
 
 






// double atr=iATR(Symbol(),1,30,0);
   

    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(Ma12 < Ma26)
             
           //  if(PClose0 <= PLowestdays)
           
       //  if  ( Pricehigh1 >= Bolingerupper1 && PClose0 <= Bolingerupper )
           
       //  if  ( PHigh0 >= PHighest)
         
       //  if  ( PClose0 >= Bolingerupper)
           
           //if ( Ma1 > PClose0 && Ma1  > PClose1 && Stomain1 > 80  /*&& Ma1 < Mabackopen   && (Hour()>=11 && Hour()<=17)*/ )
           
          //  if (  Ask==0 /*(Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackclose  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Mabackclose   )*/ )
           
           // if ( Stomain1 > 81 && Stomain < 80 )
           
         //  if ( (Stomain1 > 80 && Stomain < 79 && Ma1 < Maback200 && Maback100 < Maback200  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Maback200 && Maback100 < Maback200  ))
            {
                //---- 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(Ma12 > Ma26)
             
            //   if(PClose0 >= PHighestdays)
           
    //  if (Pricelow1 <= Bolingerlower1 && PClose0 >= Bolingerlower  ) 
         
//if (PLow0 <= PLowest  )
     
   //  if (PClose0 <= Bolingerlower  )
           
           
         //  if  ( PClose0 > Ma1 && PClose1 > Ma1 && Stomain1 < 20 /*&& Ma1 > Mabackopen     && (Hour()>=11 && Hour()<=17)*/ )
           
        //    if   (   Ask==0 /*(Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackclose  )|| (Stomain1 < 80 && Stomain > 81 && Ma1 > Mabackclose  )*/ )
           
          //  if (  Stomain1 < 19 && Stomain > 20  )
         
        //   if   ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Maback200 && Maback100 > Maback200 ) || (Stomain1 < 80 && Stomain > 81 && Ma1 > Maback200 && Maback100 > Maback200  ))
            {
                //---- 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  ( ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Maback200 && Maback100 > Maback200 ) || (Stomain1 < 80 && Stomain > 81 && Ma1 > Maback200 && Maback100 > Maback200  )) && (  (Hour()>=12 && Hour()<=16)  || (Hour()>=6 && Hour()<=10)  ) && OrdersTotal() == 0 )
 
  // if  ( PClose0 > Ma1 && PClose1 > Ma1 && Stomain1 < 20/*&& Ma1 > Mabackopen     && (Hour()>=11 && Hour()<=17)*/ )
 
// if  ( (Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen  )  || ( Stomain1 < 80 && Stomain > 81 && Ma1 > Mabackopen  ) 
   
//    || ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0  && Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen )
   
  // || ((BuyProfit+SellProfit) >= Profit1 && OrdersTotal() == 2 && OrderType() == OP_BUY  && OrderSymbol() == Symbol() && BuyProfit > 0  && Stomain1 < 20 && Stomain > 21 && Ma1 > Mabackopen ) )
   
  // if (   PLow2 <= Bolingerlower1 && PLow1 >= Bolingerlower1 && PLow0 >= Bolingerlower1  && Bolingerlower >= Bolingerlower90 )
 
 
//  if ( (Pricelow1 <= Bolingerlower1 && PClose0 >= Bolingerlower )  || (PClose1 <= Bolingermain1 && PClose0 >= Bolingermain) )

     //if( ( PLow2 <= PLowest && PLow15 > PLowest && PLow0 > PLowest) || (PClose0 >= PHighest))
     
    // if (  PClose0 >= PHighest  /*&& ( (Hour()>=13 && Hour()<20) )*/ )
     
     // if(    PClose0 >= PHighest &&  Ma12 > Ma26 && (BuyProfit+SellProfit) >= 0)
     
      if(   
     
     (   
      (PClose3 < Ma26 && POpen3 > PClose3 &&  POpen2 < POpen3*0.98 && POpen2 < POpen3 && POpen2 > PClose2 && POpen1> POpen2*1.02 && POpen1 < PClose2)//morning star
     
      || (PClose2 < Ma26 && (POpen1-PLow1) > 2*(PClose1-POpen1) && POpen1< PClose1)//hammer
     
       ||  ( PClose2 < Ma26 && PClose2 < POpen2 && PClose2*.98 > POpen1 && PClose1 > POpen2  ) //bullish engulfing
       
       ||  ( PClose2 <Ma26 && POpen2 > PClose2 && POpen1 > PClose2*1.02 && POpen1<PClose1 ) // harami open buy
       
      ||  ( POpen2 < PClose2 && POpen1 > PClose2*1.02 && POpen1 < PClose1 ) // windows Gap open buy
      )
     
        && (BuyProfit+SellProfit) >= 0
     
      )
     
     
    //   if  (        (  (PHigh15 >= PHighest && PClose0 >PHighest ) ||  ( PLow15 <= PLowest && PClose0 > PLowest)  )    && ( (Hour()>=12 && Hour()<=20) )  )
   
    {
    //  double slb=Ask-SL*Point;
   
   //   double tpb=Ask+TP*Point;
     
      double sl=Ask-(PHighest-PLowest)/3;
     double tp=Ask+(PHighest-PLowest)  ;
     
        //---- open a BUY positiont
        if ( OrderSend( Symbol(), OP_BUY, Lot, Ask, 5,sl , PHighest , "XM",
              Expert_ID, 0, Green ) < 0 )
        {
            _GetLastError = GetLastError();
           // Alert( "Error OrderSend # ", _GetLastError );
            return(-1);
        }
        return(0);
    }
    //---- open a SELL position
   
   // if (( (Stomain1 > 80 && Stomain < 79 && Ma1 < Maback200 && Maback100 < Maback200  ) || (Stomain1 > 20 && Stomain < 19 && Ma1 < Maback200 && Maback100 < Maback200  )) && (  (Hour()>=12 && Hour()<=16)  || (Hour()>=6 && Hour()<=10)  ) && OrdersTotal() == 0   )
   
//   if ( Ma1 > PClose0 && Ma1  > PClose1 && Stomain1 > 80 /*&& Ma1 < Mabackopen  && (Hour()>=11 && Hour()<=17)*/ )
   
 
//  if ( ( Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen )  || ( Stomain1 > 20 && Stomain < 19 && Ma1 < Mabackopen ) 
   
  // ||((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 1 && OrderType() == OP_SELL  && OrderSymbol() == Symbol() && SellProfit > 0  && Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen )
   
  // ||((BuyProfit+SellProfit)  >= Profit1 && OrdersTotal() == 2 && OrderType() == OP_SELL  && OrderSymbol() == Symbol() && SellProfit > 0  && Stomain1 > 80 && Stomain < 79 && Ma1 < Mabackopen ) )
   
// if  (    PHigh2 >= Bolingerupper1  && PHigh1 <= Bolingerupper1 && PHigh0 <= Bolingerupper1  && Bolingerupper <= Bolingerupper90 )
   
// if  ( ( Pricehigh1 >= Bolingerupper1 && PClose0 <= Bolingerupper )     || (PClose1 >= Bolingermain1 && PClose0 <= Bolingermain) )
 
 
// if (( PHigh2 >= PHighest && PHigh15 < PHighest && PHigh0 < PHighest )|| (PClose0 <= PLowest))

//  if (PClose0 <= PLowest /*&& ( (Hour()>=13 && Hour()<20) ) */)
   
   //if(  PClose0 <= PLowest   &&  Ma12 < Ma26 && (BuyProfit+SellProfit) >= 0)
   
   if ( 
   (
   
      ( PClose3 > Ma26 && PClose3 > POpen3 && POpen2 > PClose3 && POpen2 <PClose2 && POpen1  < PClose2*0.98 && POpen1< PClose1 && POpen2 > PClose3*1.02 ) // evening star
   
   || (PClose2 > Ma26 && POpen1 > PClose1 && (PHigh1 -POpen1)> 2*(POpen1-PClose1))//shooting star
   
     || ( PClose2 > Ma26 && POpen2 < PClose2 && POpen1> POpen2*1.02 && POpen1 < PClose1 && PClose1 < POpen2    ) //bearish engulfing
       
     || ( PClose2 > Ma26 && POpen2 < PClose2 && POpen1 < PClose2*0.98 && POpen1 < PClose2    ) // Harami opn sell
     
      || ( POpen2 > PClose2 && POpen1 < PClose2*0.98  && POpen1 > PClose1 ) // windows gap open sell
     
   )
   &&  (BuyProfit+SellProfit) >= 0   
   
   )
   
  //  if (  ((PLow15 <= PLowest  && PClose0 < PLowest)  || ( PHigh15 >= PHighest  && PClose0 < PHighest ) )   && (Hour()>=12 && Hour()<=20) )
   
    {
   
   // double sls=Bid+SL*Point;
    //  double tps=Bid-TP*Point;
     
       double s=Bid+(PHighest-PLowest)/3;
      double t=Bid-(PHighest-PLowest);
     
        //---- open a SELL position
        if ( OrderSend( Symbol(), OP_SELL, Lot, Bid, 5,s ,PLowest, "XM",
              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