Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
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.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-15-2008, 01:59 PM
cutzpr's Avatar
Member
 
Join Date: Jan 2008
Posts: 62
cutzpr is on a distinguished road
Question Need help with Pivot Point EA

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.


PHP Code:
//+------------------------------------------------------------------+
//|                                                 PrevDay EAt.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//---- input parameters
extern double Risk_Percent=10;
extern bool Allow_Risk=false;
extern bool TimeFilter=false;
extern double FromHourTrade=0;
extern double ToHourTrade=23;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
int totalticket;
double PrevPivotLots;
bool CanopenCancloseBlockTrade;
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.00001Poin 0.0001//6 digits
        
else if (Point == 0.001Poin 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.

total=OrdersTotal();   

  if(
total<&& BlockTrade==false )
     
Canopen=true;
     
  else if(
total>|| BlockTrade==true)
     
Canopen=false;
     
     
//*****Trade Order Functions

   
if(Canopen==true)
        {
      if (
iClose(NULL,0,1)>PrevPivot && iOpen(NULL,0,0)>PrevPivot)
                    {
            
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"PrevPivot",12345,0,Green);
            
                   if(
ticket>0)
                   {
                      if(
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                     Print(
"BUY order opened : ",OrderOpenPrice());
                   }
                 else Print (
"Error opening BUY order : ",GetLastError());
            return (
0);
                    }
            
      else if (
iClose(NULL,0,1)<PrevPivot && iOpen(NULL,0,0)<PrevPivot)
                {
            
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"PrePivot",12345,0,Red);
 
                if (
ticket>0)
                   {
                      if(
OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                         Print (
"Sell order opened : ",OrderOpenPrice());
                   }
                else Print(
"Error opening SELL Order : ",GetLastError());
            return (
0);
               }
    }
    
//*****Close Order Functions.   
   
   
if(total>0)
        {
        
OrderSelect(ticketSELECT_BY_POSMODE_TRADES);
            
            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);
                                }
                        }
                                    
            return (
0);
        }    
 

Attached Files
File Type: mq4 PrevDayAndFloatingPivot.mq4 (3.7 KB, 55 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 08-10-2008, 12:32 PM
Junior Member
 
Join Date: Apr 2008
Posts: 3
Zenith63 is on a distinguished road
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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 08-10-2008, 03:20 PM
Linuxser's Avatar
User Root
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 4,412
Blog Entries: 56
Linuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond repute
Quote:
Originally Posted by cutzpr View Post
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.
Hello,

The EA comes from this thread: The Only Pivot.

Maybe inside that you could find what you need.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
pivot point ea, Pivot point


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Point Indicator Money Duck Indicators - Metatrader 4 1 12-18-2008 06:05 AM
Pivot Point Moving Average jeepr94 Indicators - Metatrader 4 7 04-18-2008 09:36 PM
What is pivot point and how to use it on Forex? KOHHOB General Discussion 16 06-13-2007 01:35 AM
Pivot Point System jebigabre Suggestions for Trading Systems 2 08-27-2006 07:28 AM
pivot point trading peterz Setup Questions 0 06-28-2006 01:53 PM


All times are GMT. The time now is 09:30 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.