Im trying to build a EA that calculate the High and Low, Im using standard devtion to determ when the market isnt moving then setting high and low values and want
to buy or sell if the price is crossing under the low or above the high
Im getting wrong values in high and low, someone know why?
Thanks for your help
#property link ""
#include <stderror.mqh>
#include <stdlib.mqh>
#define IDLE 0
#define SIGNAL_BUY 1
#define SIGNAL_SELL 2bool trade=false;
int tickets=0;
int ticketb=0;
int Order = IDLE;
bool update=true;
bool flagbuy = true;
bool flagsell = true;
double MA9, BigMA, BigMAShort, stand;
double Short_MA9;
externdouble lotSize=0.1;
externint TP=100;
externint SL=100;
externint Short_TP=100;
externint Short_SL=100;
externstring a= "Standard Deviation setting";
externint gapInPips=10;
externint Stand_PER= 10; /// set the number of bars back externint MODE_MA= 0;
externint stand_app= 0;
externdouble DEV_POINT= 0.0005;
externstring b= "setting for ";
externint MagicNumber=7272;
double low, hi, hiPt, lowPt;
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
//----if (OrdersTotal()==0)
{
trade=false;
Order = IDLE;
}
if (OrdersTotal()!=0)
{
for (int i=1; i<=OrdersTotal(); i++) //Cycle for all orders..
{ //displayed in the terminalif(OrderSelect(i-1,SELECT_BY_POS)==true)//If there is the next one
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
{
trade=true;
update=true;
break;
}
else {trade=false;}
}
}
}
//////////////////// INDICATORS
stand=iStdDev(NULL,0,Stand_PER,0,MODE_EMA,PRICE_CLOSE,0);
double gap= gapInPips; ///
hilow();///find the high and low priceif(DEV_POINT>stand && update==true) /// just if the Standart devtion is < than the open point than get high and low
{
hi=hiPt;
low= lowPt;
update=false; ///stop getting high and low and wait until the price will cross it
}
//////////////////CHECK FOR BUY
if (trade==false && Order==IDLE && flagbuy== false && update==false)
{
if( Ask >hi)
{
Order=SIGNAL_BUY;
flagbuy=true;
}
}
//////////////////CHECK FOR SELLif (trade==false && Order==IDLE && flagsell==false && update==false)
{
if(Bid <low)
{
Order=SIGNAL_SELL;
flagsell=true;
}
}
Comment("DEV = ", stand, " devpoint ", DEV_POINT, " hi ", hiPt, " low ", lowPt, " hi_dev= ", hi, " low_vev ", low);// "\n buy_pt " ,Ask+ (gap*Point), " sell_pt ",Bid- (gap*Point) );
/////////////////////////BUY_ orderif (trade==false)
{
if (Order == SIGNAL_BUY )
{
ticketb=OrderSend(Symbol(),OP_BUY,lotSize,Ask,3, 0, 0,"",MagicNumber ,0 ,Green); //open buyif(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
OrderModify(ticketb,OrderOpenPrice(),Ask- SL*Point,Ask+ (TP * Point) ,0,Green);
if(OrderSelect( ticketb, SELECT_BY_TICKET )==true)
{
Alert("LONG ORDER OPENED IN Stand DEV"," Symbol= ",Symbol()," Period=",Period(), " Ticket= ",ticketb, " HiPt= ",hi, " lowPt= ",low);
trade= true;
}
else
{
Print("OrderSelect returned the error of ",GetLastError());
Alert("EROR LONG ORDER IN Stand DEV"," Symbol= ",Symbol()," Period=",Period()," EROR= ",GetLastError());
Order= IDLE;
}
}
}
/////////////////////////sellif (trade==false)
{
if (Order == SIGNAL_SELL )
{
tickets=OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,"",MagicNumber,0,Green); // open sellif(OrderSelect( tickets, SELECT_BY_TICKET )==true)
OrderModify(tickets,OrderOpenPrice(),Bid+ (Short_SL*Point),Bid-(Short_TP*Point),0,Blue);
if(OrderSelect( tickets, SELECT_BY_TICKET )==true)
{
Alert("SHORT ORDER OPENED IN Stand DEV"," Symbol= ",Symbol()," Period=",Period(), " Ticket= ",ticketb);
trade= true;
}
else
{
Print("OrderSelect returned the error of ",GetLastError());
Alert("ERROR SHORT ORDER IN Stand DEV "," Symbol= ",Symbol()," Period=",Period()," EROR= ",GetLastError());
Order= IDLE;
}
}
}
/////////////////////////////////// END/////////////////check order status buyif (stand>DEV_POINT){
flagbuy=false;
flagsell=false;}
//////////////////////////////////////////////////////////////return(0);
}
//+------------------------------------------------------------------+void hilow()
{
for(int size=Stand_PER; size>0; size--) /// sort to find the high and low
{
if(iHigh(NULL,0,size)>iHigh(NULL,0,size-1)) //// find high point
{
hiPt=iHigh(NULL,0,size);
}
if(iHigh(NULL,0,size)<iHigh(NULL,0,size-1))
{
hiPt=iHigh(NULL,0,size-1);
}
////////////////////////////////////////if(iLow(NULL,0,size)<iLow(NULL,0,size-1)) /// find low point
{
lowPt=iLow(NULL,0,size);
}
if(iLow(NULL,0,size)>iLow(NULL,0,size-1))
{
lowPt=iLow(NULL,0,size-1);
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi guys,
Im trying to build a EA that calculate the High and Low, Im using standard devtion to determ when the market isnt moving then setting high and low values and want
to buy or sell if the price is crossing under the low or above the high
Im getting wrong values in high and low, someone know why?
Thanks for your help