pivot and poc for 1 hour timeframe
ea calculate pivot weakly
poc = ( 20 candle high - 20 candle low )/2
//+------------------------------------------------------------------+
//| pivot-poc.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
extern int MagicNumber=10002;
extern double Lots =0.01;
extern int TrailingStop=1;
extern int Slippage=3;
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
int start()
{
string signal="";
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double speared = DoubleToStr(Ask-Bid,Digits);
datetime ctime = Time[0];
datetime lastclose = 0;
double sellstoploss = DoubleToStr(High[1]+(High[1]-Low[1]),Digits);
double selltp = DoubleToStr(Low[1]-2*(High[1]-Low[1]),Digits);
double buystoploss = DoubleToStr(Low[1]-(High[1]-Low[1]),Digits);
double buytp = DoubleToStr(High[1]+2*(High[1]-Low[1]),Digits);
//double rsi = iRSI(NULL,0,14,PRICE_CLOSE,0);
int c = OrdersHistoryTotal();
int a = OrdersHistoryTotal() - 10;
int b = OrdersHistoryTotal();
for (c = a;c < b ;c++)
{
if (OrderSelect(c,SELECT_BY_POS, MODE_HISTORY) == true && OrderMagicNumber()== MagicNumber)
{
// Alert("orders found"+ OrderTicket() + " " + OrderCloseTime());
lastclose = OrderCloseTime();
}
}
int LowestCandle = iLowest(_Symbol,_Period,MODE_LOW,20,0);
int HighestCandle = iHighest(_Symbol,_Period,MODE_HIGH,20,0);
double poc = Low[LowestCandle]+(High[HighestCandle]-Low[LowestCandle])/2;
double MH = iHigh(_Symbol,PERIOD_W1,1); //iHigh(_Symbol,PERIOD_MN1,1);
double ML = iLow(_Symbol,PERIOD_W1,1); //iLow(_Symbol,PERIOD_MN1,1);
double MC = iClose(_Symbol,PERIOD_W1,1); //iClose(_Symbol,PERIOD_MN1,1);
double pivot = (MH+ML+MC)/3;
if ((Open[1] < Close[1]) && (Close[0] > High[1]) && (Close[1] > pivot) && (Close[1] > poc))
{
//set the signal variable to buy
signal="buy";
}
//if the moving average above the current price
if ((Open[1] > Close[1]) && (Close[0] < Low[1]) && (Close[1] < pivot) && (Close[1] < poc))
{
//set the signal variable to sell
signal="sell";
}
Comment("ASK ",Ask, " BID ",Bid, " SPEARD ", speared , "\n CURRENT TIME ",ctime, " LAST ORDER CLOSED TIME ",lastclose,
"\n PIVOT POINT ",pivot , " POC POINT ",poc ,"\n The current signal is : ",signal , "",PERIOD_CURRENT );
if( TotalOrdersCount()==0)
{
int result=0;
if ((signal == "buy" && TotalOrdersCount() ==0))//Here is your open Buy rule
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,buystoploss,0,"Pivot-POC EA https://forexwithcandlestick.blogspot.com",MagicNumber,0,Green);
if(result>0)
{
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(buystoploss,Digits),0,0,Green);
}
return(0);
}
//if the fast SMA is now above
if ((signal == "sell" && TotalOrdersCount() ==0)) //Here is your open Sell rule
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,sellstoploss,0,"Pivot-POC EA https://forexwithcandlestick.blogspot.com ",MagicNumber,0,Red);
if(result>0)
{
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(sellstoploss,Digits),0,0,Red);
}
return(0);
}
}
ObjectDelete("tpl");
ObjectCreate(0,"tpl",OBJ_HLINE,0,Time[20],
OrderTakeProfit(),Time[1],OrderTakeProfit());
ObjectSetInteger(0,"tpl",OBJPROP_COLOR,Blue);
ObjectSetInteger(0,"tpl",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"tpl",OBJPROP_WIDTH,1);
//object pivot
ObjectDelete("PIVOTL");
ObjectCreate(0,"PIVOTL",OBJ_HLINE ,0,Time[20],
pivot,Time[1],pivot);
ObjectSetInteger(0,"PIVOTL",OBJPROP_COLOR,Yellow);
ObjectSetInteger(0,"PIVOTL",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"PIVOTL",OBJPROP_WIDTH,3);
ObjectDelete("POC");
ObjectCreate(0,"POC",OBJ_HLINE,0,Time[20],
poc,Time[1],poc);
ObjectSetInteger(0,"POC",OBJPROP_COLOR,White);
ObjectSetInteger(0,"POC",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"POC",OBJPROP_WIDTH,3);
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if((OrderProfit() > 0 && Low[1]>Bid)) //here is your close buy rule
{ Alert("close buy",Bid);
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Blue);
}
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop && OrderStopLoss()<Bid-buystoploss)
{
OrderModify(OrderTicket(),OrderOpenPrice(),buystoploss,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if((OrderProfit() > 0 && High[1]<Ask)) // here is your close sell rule
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Yellow);
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop && OrderStopLoss()> sellstoploss)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),sellstoploss,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);
if (OrderMagicNumber()==MagicNumber) result++;
}
return (result);
}
No comments:
Post a Comment