candle stick pattern (http://line.me/ti/p/~boysiamavs)
http://www.onlinetradingconcepts.com/TechnicalAnalysis/Candlesticks/PiercingPattern.html
:)
การดู trend forex และ หุ้น
extern int Expert_ID = 789;// 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;
extern double TrailingStop =0;// for time frame M1
extern double Shiftbackopenorder=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 = 15000; // Only trades above this amount close out
extern double Loss = -5000.0; // loss value for stop loss
//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;
// 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()==16 ) CloseAll();
// 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();
///// 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 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);
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 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 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,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);
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)
{
//---- 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)
{
//---- 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(
(
( (POpen3 > PClose3 && ( (POpen3- POpen2 > 6 && PClose2 < PClose3 ) )&& ( POpen1-POpen2 >6 && POpen1 > PClose2) && POpen1 < PClose1 ) && MACD_1 >0 )//morning star rev1
|| ( POpen2 > PClose2 && POpen1 - PClose2 >5 && POpen1<PClose1 && MACD_1 >0 ) // harami open buy rev1
|| ( PClose2 < POpen2 && ( PClose2-POpen1) >5 && PClose1 > POpen1 && PClose1 > POpen2 && MACD_1 >0 ) //bullish engulfing rev1
|| ( POpen2 < PClose2 && (POpen1 - PClose2) >5 && POpen1 < PClose1 && MACD_1 >0 ) // windows Gap open buy rev1
)
&& Hour() < 16
// && ( BuyProfit+SellProfit >= 0) && OrdersTotal() < 7
)
// if ( ( (PHigh15 >= PHighest && PClose0 >PHighest ) || ( PLow15 <= PLowest && PClose0 > PLowest) ) && ( (Hour()>=12 && Hour()<=20) ) )
{
// double slb=Ask-SL*Point;
// double tpb=Ask+TP*Point;
double stoploss=Ask*0.97; // SL percentage
double takeprofit=Ask*1.06; // 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,sl , tp , "forex candle",
Expert_ID, 0, Green ) < 0 )
{
_GetLastError = GetLastError();
// Alert( "Error OrderSend # ", _GetLastError );
return(-1);
}
return(0);
}
////////////////---- open a SELL position///////////////////
if (
(
( PClose3 > POpen3 && ( (POpen2 - PClose3) > 5 &&( POpen2 - POpen3) > 5 )&& POpen1 > PClose1 && MACD_1 <0 ) // evening star rev1
|| ( POpen2 < PClose2 && (POpen2 - POpen1) > 5 && PClose1 < POpen1 && MACD_1 <0 ) // Harami opn sell rev1
||( POpen2 < PClose2 && (POpen1- PClose2) > 5 && POpen1 > PClose1 && PClose1 < POpen2 && MACD_1 <0 ) //bearish engulfing open sell rev 1
||( POpen2 > PClose2 && (PClose2 - POpen1)>5 && POpen1 > PClose1 && MACD_1 <0 )// windows gap open sell rev1
)
&& Hour()< 16
// && (BuyProfit+SellProfit) >= 0 && OrdersTotal() <7
)
// if ( ((PLow15 <= PLowest && PClose0 < PLowest) || ( PHigh15 >= PHighest && PClose0 < PHighest ) ) && (Hour()>=12 && Hour()<=20) )
{
// double sls=Bid+SL*Point;
// double tps=Bid-TP*Point;
double stop=Bid*1.03;
double take=Bid*0.94;
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,s ,t, "forex candle",
Expert_ID, 0, Red ) < 0 )
{
_GetLastError = GetLastError();
// Alert( "Error OrderSend # ", _GetLastError );
return(-1);
}
return(0);
}
return(0);
}
:)
color color1 = Red;
color color2 = White;
color color3 = Red;
color color4 = White;
#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);
tweezer
:)