| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
|||
|
Somebody might actually help you if you posted the code.
![]() Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV ![]() ForexArea.com Users of Gap Trader from 'Forex-Assistant' MUST Read This |
|
|||
|
proper use of Time[]
I'm a fair programmer but new to mql4. I'm working on a box trade (aka breakout trade) expert adviser. Essentially it should find the highest and lowest values for a specific time frame, and when a candle closes outside of that box I place a trade.
Essentially there are three states, I can start my EA in 1) after the close of the previous day, and before the box start time. 2) after the start of the box but before the end of the box. 3) after the end of the box. What I find confusing is the Time[] array because the index keeps changing. Assume I enter at state 2. In the init function I was going to set a global variable giving the position of the start of the box. As quotes come in my start function is constantly called, and once the end of the box time was reached I would have the start and end positions. Of course that is not the case as the index on the Time array keeps rolling forward. At best I can keep incrementing the position of the box start index, but that doesn't seem a very clean way to do things. If you have a suggestion on how I should change my thinking away traditional c/c++ to mql4 I'd love to hear it. Also when I'm done I would obviously benefit greatly from a code review by a more senior programmer. Would anyone like to volunteer for that? Thanks for your time, Markus |
|
|||
|
Quote:
You can get the exact time of any bar and timeframe using iTime() as well. There's quite a few ways to go about it... |
|
|||
|
open two orders on the same time (problem...)
Hi, i don't know why in some Opportunities the script open two orders on the same time.
someone can help me with this, please if(UseStopLoss) ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,EAName, MagicNo, 0,Green); else ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+ TakeProfit*Point,EAName, MagicNo, 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()); thank's |
|
|||
|
Help for code
Hi all,
I would like to code an indicator for compute the close value wich create a reversal of an indicator like HMA. For that i need to create a function for compute one value of HMA with a close values tab where i modify the current value in an dichotomy loop to find the value wich create the reversal. Somebody can help me with my ComputeHull function ? Here my code, without dichotomy reseach it is just a simple HMA indicator with computeHull function, the indicator is displayed but it is shifted down Regards //#property indicator_separate_window #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Blue //---- input parameters extern int HullAntPeriod=12; //---- buffers double TempBuf1[]; double TempBuf2[]; double HullAntBuf[]; //Variable int HalfHullAntPeriod; int SqrtHullAntPeriod; //+------------------------------------------------------------------+ //| Specific functions | //+------------------------------------------------------------------+ double ComputeHull(int ActualBar) { double CloseTemp[]; double Temp[]; double Temp1, Temp2; double result = -1; int i; //Copy Close Values to CloseTemp ArrayResize(CloseTemp, HullAntPeriod+SqrtHullAntPeriod); ArrayCopy(CloseTemp, Close, 0, ActualBar, HullAntPeriod+SqrtHullAntPeriod); ArraySetAsSeries(CloseTemp, true); ArrayResize(Temp, SqrtHullAntPeriod); //HMA value computation for(i=0; i<SqrtHullAntPeriod; i++) { Temp1 = iMAOnArray(CloseTemp, 0, HalfHullAntPeriod, 0, MODE_LWMA, i); Temp2 = iMAOnArray(CloseTemp, 0, HullAntPeriod, 0, MODE_LWMA, i); Temp[i] = 2*Temp1-Temp2; } ArraySetAsSeries(Temp, true); result = iMAOnArray(Temp, 0, SqrtHullAntPeriod, 0, MODE_LWMA, 0); //---- done return(result); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 1 additional buffers are used for temporary data. IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_NONE); //---- 2 indicator buffers mapping SetIndexBuffer(0,HullAntBuf); SetIndexBuffer(1,TempBuf1); SetIndexBuffer(2,TempBuf2); //---- name for DataWindow and indicator subwindow label IndicatorShortName("HULL ANTICIP("+HullAntPeriod+")"); SetIndexLabel(0,"HULL ANTICIPATION"); SetIndexLabel(1,NULL); SetIndexLabel(2,NULL); //---- Specific indicator initialization HalfHullAntPeriod = MathFloor(HullAntPeriod/2); SqrtHullAntPeriod = MathFloor(MathSqrt(HullAntPeriod)); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int bar, limit, i; int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(i=0; i<limit; i++) HullAntBuf[i]=ComputeHull(i); //---- return(0); } //+------------------------------------------------------------------+ |
|
|||
|
HOW to Open an order at the beginning of a bar only ??
Hi,
I'm implementing an EA in which I want to open an order only if a cross of some level by an indicator has occured between the second previous bar and the previous one. For example, on the daily chart, If there is a cross between the 18th of January and the 19th of January, I want to open an order on the 20th of January. I did something like this: When I open an order, I record the order open time. Then I do the following test: Is (CurrentTime() - LastOrderOpenTime) < Period() ?? If yes, it means that the current bar is not finished, yet, and I shouldn't open a new order. And also, when this condition becomes false, I should be on the next bar of the chart, and the cross happened before the last bar and no order should be opened until the next signal. The problem is that when attaching it to a chart, it keeps on creating new orders until the bar is finished. Anybody can tell me what I did wrong? |
![]() |
| Bookmarks |
| Tags |
| candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
|
||||
| Posted By | For | Type | Date | |
| Need an experienced programmer? - Page 2 | Post #0 | Refback | 09-24-2008 07:24 AM | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to code this? | iscuba11 | Metatrader 4 mql 4 - Development course | 1 | 08-03-2007 05:22 PM |