Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
I am still new to programming and I just can not get a handle of what is going on with this EA. I still need to add some filters, but the EA currently does not put orders in correctly.
Simply, I would like to place an order if the close of the previous bar and the open of the current bar is above the PrevPivot. And Visa-versa for a sell order.
Now the EA seems to only trade when the Value of the PrePivot changes day to day. But not during the day. Now I checked the Data window and the PrePivot buffer shows the value throughout the day. But for some reason it just doesnt work for me. Can someone please take a look at this for me.
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int total, ticket;
double PrevPivot, Lots;
bool Canopen, Canclose, BlockTrade;
double Poin; // This variable was included to solve the problem where some brokers use 6 digit quotes instead of 5
static datetime timeprev; // Portion of coded was added to alloy only one trader per bar.
//This portion of code was added to only allow one trader per bar.
if(timeprev==Time[0])
{
return(0); //only execute on new bar
}
else if (timeprev==0)
{
timeprev=Time[0]; // do nothing if freshly added to chart
return(0);
}
else
{
timeprev=Time[0];
}
//*****Following code was added to control the Risk per trade.
if (Allow_Risk==true)
Lots=MathCeil(AccountFreeMargin() * Risk_Percent / 10000) / 10;
else Lots=1.0;
//The following code was also included to solve the 6 digit broker quoting
if (Point == 0.00001) Poin = 0.0001; //6 digits
else if (Point == 0.001) Poin = 0.01; //3 digits (for Yen based pairs)
else Poin = Point; //Normal
//End Point Code
// if(Bars<100) //Minium amount of bars the indicators will need to work
// {
// Print("bars less than 100, Expert will not execute");
// return(0);
// }
//*******Start of function iCustom************
PrevPivot=iCustom(NULL,0,"PrevDayAndFloatingPivot",0,0);
//****If TimeFilter is true, then trades will be limited to only certain hours of the day.
if (TimeFilter==true)
{
if (!(Hour() >= FromHourTrade && Hour() <= ToHourTrade && Minute() <=3))
BlockTrade=true;
else BlockTrade=false;
}
//Booleans used to control when order will be open and closed. Only
//one order will be open at any given time. The EA will always be in the market.
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
if(OrderType()==OP_BUY) //Long position is opened
{ //should the long position be closed?
if (iClose(NULL,0,1)<PrevPivot && iOpen(NULL,0,0)<PrevPivot)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // Long position closed.
return(0);
}
}
else if(OrderType()==OP_SELL) //Short position is opened.
{ //Should the short position be closed?
if (iClose(NULL,0,1)>PrevPivot && iOpen(NULL,0,0)>PrevPivot)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // Short position closed.
return(0);
}
}
Can you give an example of when it's not working? I'm running it here and it looks like it's doing what you're after, but I don't really understand your description of the problem.
The best way to check something like this is to add a print statement of the values then run a back test in slowed visualisation mode, open the journal page and just watch what is happening compared to the values from the Print statement. For instance I added
Print("PrevPivot=" + PrevPivot + ",PrevClose=" + iClose(NULL,0,1) + ",CurrOpen=" + iOpen(NULL,0,0));
Just under //*****Trade Order Functions, and of course turn off the printing of "shit" in your indicator as these make reading the journal very difficult.
Anyway if you can post a screenshot of a backtest when your EA didn't trade but should of I'll see what I can do...
I am still new to programming and I just can not get a handle of what is going on with this EA. I still need to add some filters, but the EA currently does not put orders in correctly.
Simply, I would like to place an order if the close of the previous bar and the open of the current bar is above the PrevPivot. And Visa-versa for a sell order.
Now the EA seems to only trade when the Value of the PrePivot changes day to day. But not during the day. Now I checked the Data window and the PrePivot buffer shows the value throughout the day. But for some reason it just doesnt work for me. Can someone please take a look at this for me.