Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course > Questions
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 02-25-2008, 04:38 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Search for a formation over many bars

Hello,

I was hoping for some guidance on coding that I can't seem to figure out. Simply put, I see the problem of being able to do addition but not being able translate that into multiplication.

Here's the problem:
I need to look for a specific pattern on the Force indicator over 3 different periods in one timeframe. Now the problem is that this pattern can occur anytime in the past 30 bars for anyone period.

I have done simple crosses before by looking at the previous 2 bars to make a decision, but not anything where the condition can be met anytime within the past x bars. I think I've seen an indicator that did something like this and might have used an array function, but don't remember exactly.

So the indicator must remember that it has recognized the pattern and watch out for the same pattern in the subsequent periods. So the counter would start once the first pattern is recognized and then would reset after 30 bars have passed and the other periods don't create the necessary pattern.

I've attached a screen shot showing an example which has the Force Indicator withthe periods, 2, 13, and 26. I'm looking for upside down "v" formations over specific levels for a short trade. In this case the critical "v" formation on the 2 period is 350, 200 on the 13 period and between 50 and 100 on the 26 period.

Thanks for anyone's help out there!
Mike
Attached Images
File Type: gif triple force example.gif (17.5 KB, 131 views)
__________________
--------------------------------------------------
"Treat people as if they were what they ought to be and help them become what they are capable of being." Goethe

Last edited by mikep; 02-25-2008 at 04:42 PM.
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 02-25-2008, 11:45 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Hello, anyone....Bueller?

__________________
--------------------------------------------------
"Treat people as if they were what they ought to be and help them become what they are capable of being." Goethe
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 03-03-2008, 03:12 AM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Well I was able to get a response from someone in the mql4 forum but the indicator doesn't paint arrows on the chart - and they haven't been available to provide anymore help.

Can someone take a look at the - I think this type of event tracking indicator can be very useful for others and that it could be adapted to your favorite.

Newdigital - not sure if this thread should stay here or be moved to the 'indicator' posts.

Thanks,
Mike

Code:
//+------------------------------------------------------------------+
//|                                           Multiple Force Cross   |
//+------------------------------------------------------------------+
 
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Red
 
double CrossUp[];
double CrossDown[];
extern int BarsToProcess = 20;
 
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,3);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
  
   //int BarsToProcess = 1000;
   bool PForce2Buy = false, PForce13Buy = false, PForce26Buy = false;
   bool PForce2Sell = false, PForce13Sell = false, PForce26Sell = false;
   double PForce_2[];
   double PForce_13[];
   double PForce_26[];
   
   ArrayResize(PForce_2, BarsToProcess+3);
   ArrayResize(PForce_13, BarsToProcess+3);
   ArrayResize(PForce_26, BarsToProcess+3);
 
   // get some values
   for(int i = BarsToProcess+2; i >= 0; i--){
   //for (int i = BarsToProcess+2; i >= 0; i++) {
   PForce_2[i]  = iForce(NULL, 0, 2, MODE_SMA,PRICE_CLOSE,i);
   PForce_13[i] = iForce(NULL, 0, 13,MODE_SMA,PRICE_CLOSE,i);
   PForce_26[i] = iForce(NULL, 0, 26,MODE_SMA,PRICE_CLOSE,i);
 
      
   
 
   // Check conditions
   for( i = BarsToProcess; i >= 0; i--){
   //for (i = BarsToProcess; i >= 0; i++) {
      CrossDown[i]=EMPTY_VALUE;
      CrossUp[i]=EMPTY_VALUE;
      
      if(  PForce_2[i+2]  < 350 && PForce_2[i+1] > 350 && PForce_2[i] < 350 ) PForce2Sell  = true;
 
      if(  PForce_13[i+2] < 200 && PForce_13[i+1] > 200 && PForce_13[i] < 200 ) PForce13Sell = true;
 
      if( (PForce_26[i+2] <= 100   &&  PForce_26[i+2] >= 50)   && (PForce_26[i+1] >  100 ) && (PForce_26[i]   <= 100   &&  PForce_26[i]   >= 50 )) PForce26Sell = true;
 
      if(  PForce_2[i+2]  > -350 && PForce_2[i+1] < -350 && PForce_2[i] > -350 ) PForce2Buy  = true;
 
      if(  PForce_13[i+2] > -200 && PForce_13[i+1] < -200 && PForce_13[i] > -200 ) PForce13Buy = true;
 
      if( (PForce_26[i+2] >= -100   &&  PForce_26[i+2] <= -50)   && (PForce_26[i+1] <  -100 ) && (PForce_26[i]   >= -100   &&  PForce_26[i]   <= -50 )) PForce26Buy = true;
   
 
   // if all conditions met
   if( PForce2Buy == true && PForce13Buy == true && PForce26Buy == true)  CrossUp[i] = Low[i] - 25*Point;
      
    if( PForce2Sell == true && PForce13Sell == true && PForce26Sell == true) CrossDown[i] = High[i] + 25*Point;
      
   
   }
   }
 
   return(0);
}
Attached Files
File Type: mq4 Multiple Force Cross.mq4 (3.3 KB, 17 views)
__________________
--------------------------------------------------
"Treat people as if they were what they ought to be and help them become what they are capable of being." Goethe
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
  #4 (permalink)  
Old 03-03-2008, 07:03 AM
Senior Member
 
Join Date: Mar 2006
Posts: 310
vladv is on a distinguished road
thanks for sharing it.
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
  #5 (permalink)  
Old 03-03-2008, 01:36 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Quote:
Originally Posted by vladv View Post
thanks for sharing it.
No problem, but the code still needs work to make it viable...
__________________
--------------------------------------------------
"Treat people as if they were what they ought to be and help them become what they are capable of being." Goethe
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
  #6 (permalink)  
Old 03-03-2008, 01:45 PM
Linuxser's Avatar
User Root
 
Join Date: May 2006
Location: Helliconia (Winter)
Posts: 4,410
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
Hi.

A couple of things.

By using fixed numbers this indicator will work only in some time frame and in some pair.

And by looking the conditions. Seem to be too hard to be accomplished.

if( PForce_2[i+2] < 350 && PForce_2[i+1] > 350 && PForce_2[i] < 350 ) PForce2Sell = true;

With this condition PForce two bars ago should be < 350 and PForce one bars ago should be > 350 and PForce current bars should be < 350.

And this is just to start because you´re requesting 9 consecutive conditions to assign a value.
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
  #7 (permalink)  
Old 03-03-2008, 02:50 PM
mikkom's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 285
mikkom is on a distinguished road
Quote:
Originally Posted by mikep View Post
I have done simple crosses before by looking at the previous 2 bars to make a decision, but not anything where the condition can be met anytime within the past x bars. I think I've seen an indicator that did something like this and might have used an array function, but don't remember exactly.
It's not really that hard, just use the same code that you use for the 2 bar verification and just loop back 30 days and verify the condition for every of those X days.

this sounds quite an interesting indicator so I might take a look at coding it later, the most important things are the exact values on how high the peak should be on each indicator.
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
  #8 (permalink)  
Old 03-03-2008, 05:47 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Quote:
Originally Posted by Linuxser View Post
Hi.

A couple of things.

By using fixed numbers this indicator will work only in some time frame and in some pair.

And by looking the conditions. Seem to be too hard to be accomplished.

if( PForce_2[i+2] < 350 && PForce_2[i+1] > 350 && PForce_2[i] < 350 ) PForce2Sell = true;

With this condition PForce two bars ago should be < 350 and PForce one bars ago should be > 350 and PForce current bars should be < 350.

And this is just to start because you´re requesting 9 consecutive conditions to assign a value.
Yes - you are correct - I was specifically looking at this combo of critical lines for the GBPJPY on the hour charts.

I found that when looking back at the charts, the most significant moves came they was a tight "v" pattern across a critical line. This I found helped me to stay out of sideway markets.
__________________
--------------------------------------------------
"Treat people as if they were what they ought to be and help them become what they are capable of being." Goethe
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
  #9 (permalink)  
Old 03-03-2008, 05:52 PM
mikep's Avatar
Member
 
Join Date: Jun 2006
Posts: 86
mikep is on a distinguished road
Quote:
Originally Posted by mikkom View Post
It's not really that hard, just use the same code that you use for the 2 bar verification and just loop back 30 days and verify the condition for every of those X days.

this sounds quite an interesting indicator so I might take a look at coding it later, the most important things are the exact values on how high the peak should be on each indicator.
Hi mikkom,
You're right, I could create 30 pair of 'or' statements per indicator period, but I was hoping the coding could be done cleaner so that I could begin running tests looking for optimized levels and the amount of time to review.
That's why I alluded to this being a problem similar to expressing it in additional form vs. multiplication.
__________________
--------------------------------------------------
"Treat people as if they were what they ought to be and help them become what they are capable of being." Goethe
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
  #10 (permalink)  
Old 03-03-2008, 07:26 PM
mikkom's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 285
mikkom is on a distinguished road
Quote:
Originally Posted by mikep View Post
Hi mikkom,
You're right, I could create 30 pair of 'or' statements per indicator period, but I was hoping the coding could be done cleaner so that I could begin running tests looking for optimized levels and the amount of time to review.
That's why I alluded to this being a problem similar to expressing it in additional form vs. multiplication.
I didn't mean 30 ors at all, more like (pseudocode follows..)

Code:
/** 1st indicator / timeframe **/
found = false;
for(int i=0; i<30; i++) {
     // Check for current time +i
     if(pattern found) {
        found=true;
        break;
     }
}

/** 2nd indicator **/
found2 = false;
for(int i=0; i<30; i++) {
     // Check for current time +i
     if(pattern found at current time +i) {
        found2=true;
        break;
     }
}

/** 3rd indicator **/
found3 = false;
for(int i=0; i<30; i++) {
     // Check for current time +i
     if(pattern found) {
        found3=true;
        break;
     }
}

bool allPatternsFound = found && found2 && found3;
Something like that.. (by using arrays as cache it will be faster but the idea is the same)

(ps. just running annoyingly long optimization to find some more good probabilities for my little EA, 4 more hours to go... booring)

Last edited by mikkom; 03-03-2008 at 07:31 PM.
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


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
Programmer Search FulkrumFX Lessons 5 07-18-2007 02:08 PM
Script for search history maje Metatrader 4 2 05-23-2007 09:40 PM
Search an indicator Yves81 Expert Advisors - Metatrader 4 1 04-16-2007 06:23 PM
High % Formation Need Help Coding Indicator doragio Metatrader 4 1 09-22-2006 02:10 AM
Array search helper functions for your use... cubesteak Metatrader 4 3 09-04-2006 05:55 AM


All times are GMT. The time now is 11:32 PM.



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